Esempio n. 1
0
def image_put(q, name, pwd, ip, channel=1, camera_corp='hik'):
    # 大华的情况 :
    if camera_corp == 'dahua':
        full_vedio_url = "rtsp://%s:%s@%s/cam/realmonitor?channel=%d&subtype=0" % (name, pwd, ip, channel)
    # 网络摄像头是海康:
    elif camera_corp == 'hik':
        full_vedio_url = "rtsp://%s:%s@%s/Streaming/Channels/%d" % (name, pwd, ip, channel)
    full_vedio_url = i11process_frame.deal_specialchar_in_url(full_vedio_url)
    cap = cv2.VideoCapture(full_vedio_url)
    # if cap.isOpened():
    #     print('HIKVISION')
    # else:
    #     cap = cv2.VideoCapture("rtsp://%s:%s@%s/cam/realmonitor?channel=%d&subtype=0" % (name, pwd, ip, channel))
    #     print('DaHua')

    # 通过timeF控制多少帧数真正读取1帧到队列中
    timeF = 15
    count = 1 
    while True:
        res, frame = cap.read()
        if count % timeF == 0:
            # print('pick=', count)
            q.put(cap.read()[1])
            q.get() if q.qsize() > 1 else time.sleep(0.01)
        count += 1
Esempio n. 2
0
def image_put(q, queueid):
    name = queue_rtsp_dict.get(queueid, None)[0]
    pwd = queue_rtsp_dict.get(queueid, None)[1]
    ip = queue_rtsp_dict.get(queueid, None)[2]
    channel = queue_rtsp_dict.get(queueid, None)[3]
    camera_corp = queue_rtsp_dict.get(queueid, None)[4]

    full_vedio_url = None
    # 大华的情况 :
    if camera_corp == 'dahua':
        full_vedio_url = "rtsp://%s:%s@%s/cam/realmonitor?channel=%s&subtype=0" % (
            name, pwd, ip, channel)
    # 网络摄像头是海康:
    elif camera_corp == 'hik':
        full_vedio_url = "rtsp://%s:%s@%s/Streaming/Channels/%s" % (
            name, pwd, ip, channel)
    full_vedio_url = i11process_frame.deal_specialchar_in_url(full_vedio_url)
    try:
        cap = cv2.VideoCapture(full_vedio_url)
        # if cap.isOpened():
        #     print('HIKVISION')
        # else:
        #     cap = cv2.VideoCapture("rtsp://%s:%s@%s/cam/realmonitor?channel=%d&subtype=0" % (name, pwd, ip, channel))
        #     print('DaHua')

        # 通过timeF控制多少帧数真正读取1帧到队列中
        timeF = 15
        count = 1
        while True:
            if cap.isOpened():
                status, frame = cap.read()
                if status:
                    if count % timeF == 0:
                        # print('pick=', count)
                        q.put((cap.read()[1], queueid))
                        q.get() if q.qsize() > 1 else time.sleep(0.01)
                    count += 1
    except cv2.error as e:
        print('#' * 10, 'cv2 error:', e)
# 	rtsp_obj = row[1:]
#     print(rtsp_obj[4])
for i in camera_ip_list:
    print(rtsp_obj)
    rtsp_obj = i[1:]
    if rtsp_obj[4] == 'dahua':
        video_url = "rtsp://%s:%s@%s/cam/realmonitor?channel=%d&subtype=0" \
            % (rtsp_obj[0], rtsp_obj[1], rtsp_obj[2], rtsp_obj[3])
    # 网络摄像头是海康:
    elif rtsp_obj[4] == 'hik':
        video_url = "rtsp://%s:%s@%s/Streaming/Channels/%d" % (
            rtsp_obj[0], rtsp_obj[1], rtsp_obj[2], int(rtsp_obj[3]))

    video_flag = True
    rect = (0, 0, 0, 0)
    addr = deal_specialchar_in_url(video_url)
    cap = cv2.VideoCapture(addr)
    #cap = cv2.VideoCapture("test2.dav")
    #cap = cv2.VideoCapture(0)
    cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*"H264"))

    # cap.set(3, 1920)
    # cap.set(4, 1080)
    # cap.set(cv2.CAP_PROP_FPS,5)
    #cap = cv2.VideoCapture(0)
    waitTime = 50

    #Reading the first frame
    (grabbed, frame) = cap.read()
    if frame is None:
        print('\n### error ###', video_url)