0
import numpy as np
import cv2
from hikvisionapi import Client


cap = cv2.VideoCapture()
#cap.open("rtsp://admin:DocoutBolivia@192.168.1.64:554/h264/ch0/sub")
cap.open("rtsp://admin:DocoutBolivia@192.168.1.64:554/Streaming/Channels/102/")
#cam = Client('http://192.168.1.64', 'admin', 'DocoutBolivia')

#rtsp://admin:password@192.168.1.64/h264/ch1/sub/

#response = cam.System.deviceInfo(method='get')
ret, frame = cap.read()
cv2.imwrite("holo.jpg", frame)

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Our operations on the frame come here

    # Display the resulting frame
    cv2.imshow('frame',frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

我有这段代码,它的连接和显示都很好,但是速度真的很慢还有另一种方法吗?并且延迟少一点?我想用我的海康威视网络摄像机进行人脸识别

4

1 回答 1

0

试图直接加载蒸汽Python不会让你到任何地方。

获得极低延迟的唯一方法是利用海康威视提供的SDK中的.dllor文件,调用内部函数。.soctypes

下面是我之前制作的一个简单示例,用于访问NET_DVR_PTZControl_Other. 如果您想使用他们的 SDK 开发自己的应用程序,工作量很大。我建议您向供应商索取示例 python 应用程序。

例如,

import os, ctypes
import cv2

def add_dll(path, dll_list):
    files = os.listdir(path)
    for file in files:
        if not os.path.isdir(path + file):
            if file.endswith(".dll"):
                dll_list.append(path + file)
        else:
            add_dll(path + file + "/", dll_list)


def callCpp(func_name, *args):
    for so_lib in so_list:
        try:
            lib = ctypes.cdll.LoadLibrary(so_lib)
            try:
                value = eval("lib.%s" % func_name)(*args)
                print("Success:" + str(value))
                return value
            except:
                continue
        except:
            print("Fail:" + so_lib)
            continue
    return False

def NET_DVR_PTZControl_Other(lUserID, lChannel, dwPTZCommand, dwStop):
    res = callCpp("NET_DVR_PTZControl_Other", lUserID, lChannel, dwPTZCommand, dwStop)
    if res:
        print("Control Success")
    else:
        print("Control Fail: " + str(callCpp("NET_DVR_GetLastError")))

获取 Steam 示例

class NET_DVR_JPEGPARA(ctypes.Structure):
    _fields_ = [
        ("wPicSize", ctypes.c_ushort), # WORD
        ("wPicQuality", ctypes.c_ushort)] # WORD

def NET_DVR_CaptureJPEGPicture():
    sJpegPicFileName = bytes("pytest.jpg", "ascii")
    lpJpegPara = NET_DVR_JPEGPARA()
    lpJpegPara.wPicSize = 2
    lpJpegPara.wPicQuality = 1
    res = callCpp("NET_DVR_CaptureJPEGPicture", lUserID, lChannel, ctypes.byref(lpJpegPara), sJpegPicFileName)
    if res == False:
        error_info = callCpp("NET_DVR_GetLastError")
        print("Success:" + str(error_info))
    else:
        print("Grab stream fail")
于 2019-05-27T07:42:50.950 回答