Skip to content

Commit 32e6230

Browse files
committed
Using picture endpoint
1 parent 8937624 commit 32e6230

3 files changed

Lines changed: 79 additions & 75 deletions

File tree

hikvision_isapi_sk/snap.py

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
from urllib.parse import urlparse
22
import logging
3-
# Issue with opencv-python and homeassistant
4-
# try:
5-
# # Verify that the OpenCV python package is pre-installed
6-
# import cv2
7-
# CV2_IMPORTED = True
8-
# except ImportError:
9-
# CV2_IMPORTED = False
103

114
from hikvision_isapi_cli.client import Client
5+
from hikvision_isapi_cli.api.isapi import channels_1_picture
126

137
_LOGGER = logging.getLogger(__name__)
148

@@ -21,54 +15,22 @@ def __init__(self, client: Client, rtsp_port: int, path: str) -> None:
2115
:param rtsp_port: The RTSP port of the stream.
2216
:param path: The path of the stream.
2317
"""
24-
# if not CV2_IMPORTED:
25-
# _LOGGER.error(
26-
# "No OpenCV library found! Install or compile for your system "
27-
# "following instructions here: http://opencv.org/releases.html"
28-
# )
29-
# return
30-
18+
3119
self.client = client
3220
self.rtsp_port = rtsp_port
3321
self.path = path
3422
self.host = urlparse(client.base_url).hostname
3523
self.stream_url = (
3624
f"rtsp://{client.username}:{client.password}@{self.host}:{rtsp_port}/{path}"
3725
)
38-
# self.cap = cv2.VideoCapture(self.stream_url)
39-
# self.cap.set(cv2.CAP_PROP_BUFFERSIZE, 60)
40-
# self.cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*"H264"))
4126

42-
def get_snapshot(self) -> bytes:
27+
def get_snapshot(self, channel_id: int) -> bytes:
4328
"""
4429
Capture a snapshot from the RTSP stream and return the binary data of the image.
4530
4631
:return: The binary data of the image, or None if the frame cannot be read.
4732
"""
48-
# ret, frame = self.cap.read()
49-
# if ret:
50-
# # Encode the image as JPEG
51-
# _, img_encoded = cv2.imencode(".jpg", frame)
52-
# # Return the binary data
53-
# return img_encoded.tobytes()
54-
# else:
55-
# # Return None if the frame cannot be read
56-
# return None
57-
raise NotImplementedError()
58-
59-
def release(self):
60-
"""
61-
Release the RTSP stream.
62-
"""
63-
#self.cap.release()
64-
raise NotImplementedError()
65-
66-
def open(self):
67-
"""
68-
Open the RTSP stream.
69-
"""
70-
#self.cap.open(self.stream_url)
71-
raise NotImplementedError()
33+
return channels_1_picture.sync_detailed(channel_id=channel_id,client=self.client).content
7234

7335
def stream_source(self) -> str:
7436
"""

poetry.lock

Lines changed: 74 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "hikvision-isapi-cli"
3-
version = "1.0.23"
3+
version = "1.1.0"
44
description = "A client library for accessing Hikvision ISAPI and more"
55

66
authors = ["mmascia"]
@@ -29,9 +29,6 @@ pytest-unordered = "==0.5.2"
2929
pytest-picked = "==0.4.6"
3030
pytest-xdist = "==3.2.1"
3131
pytest = "==7.3.1"
32-
#opencv-python = "==4.6.0.66"
33-
#opencv-python-headless = "==4.6.0.66"
34-
#numpy = ">=1.24.1"
3532

3633
[build-system]
3734
requires = ["poetry-core>=1.0.0"]

0 commit comments

Comments
 (0)