首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hikvision python OpenCV

Hikvision python OpenCV
EN

Stack Overflow用户
提问于 2019-03-01 00:00:36
回答 1查看 2.9K关注 0票数 0
代码语言:javascript
复制
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()

我有这段代码,它可以很好地连接和显示,但它真的很慢,还有其他方法可以做到吗?并且有更少的延迟?我想用我的HikVision IP摄像头进行人脸识别

EN

回答 1

Stack Overflow用户

发布于 2019-05-27 15:42:51

尝试用Python直接加载蒸汽不会有任何结果。

只有使用HikVision提供的SDK中的.dll.so文件,并使用ctypes调用内部函数,才能获得极低的延迟。

下面是我之前创建的一个访问NET_DVR_PTZControl_Other的简单示例。如果你想用他们的SDK开发你自己的应用程序,那会有很多工作要做。我建议您从您的供应商处请求一个示例python应用程序。

例如,

代码语言:javascript
复制
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示例

代码语言:javascript
复制
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")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54929701

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档