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()

I have this code and it's connecting and showing well but it really slow there's another way for doing this? and have a bit less of delay? I want to make face recognition with my HikVision IP camera

Spangen
  • 4,420
  • 5
  • 37
  • 42
Reddy Tintaya
  • 141
  • 2
  • 8
  • One way you can speed up is go to camera settings and decrease the resolution, for example, try 640x480 or even smaller, but you will lose some quality of the image. – Bahramdun Adil Feb 28 '19 at 16:12
  • What's hardware do you have? CPU, GPU - write, plz, specifications – Nuzhny Feb 28 '19 at 17:09
  • I have a MacBook Pro with i5 6th, Intel Iris Graphics 550 1536 MB. if I use the software from Hikvision for seeing the camera there's no delay. – Reddy Tintaya Feb 28 '19 at 17:31
  • Standart answer: cap.open(address, cv2.CAP_PROP_FFMPEG) or cap.open(address, cv2.CAP_PROP_GSTREAMER). It need to use backend with hardware acceleration video decoding – Nuzhny Feb 28 '19 at 20:39

1 Answers1

0

Trying to load the steam directly with Python will not get you anywhere.

The only way to get extremely low lantency is to make use of the .dll or .so files from the SDK provided by HikVision, and use ctypes to call the internal functions.

Below is a simple example I made before to access the NET_DVR_PTZControl_Other. It is a lot of work if you want to develop your own application with their SDK. I'd suggest you to request a sample python application from your vendor.

For example,

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")))

Get Steam Example

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")
Rex Low
  • 2,069
  • 2
  • 18
  • 47