local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local CAMERA_HEIGHT = 24
local HEIGHT_OFFSET = 2
local function updateCamera()
local character = player.Character
if character then
local root = character:FindFirstChild("HumanoidRootPart")
if root then
local rootPosition = root.Position + Vector3.new(0, HEIGHT_OFFSET, 0)
local cameraPosition = Vector3.new(rootPosition.X, rootPosition.Y + CAMERA_HEIGHT, rootPosition.Z)
camera.CFrame = CFrame.lookAt(cameraPosition, rootPosition)
end
end
end
RunService:BindToRenderStep("CustomCamera", Enum.RenderPriority.Camera.Value + 1, updateCamera)
HikVision Camera RTSP with Authentication rtsp://<username>:<password>@<IP address of device>:<RTSP port>/Streaming/channels/<channel number><stream number> NOTE: <stream number> represents main stream (01), or the sub stream (02) Example: rtsp://192.168.0.100:554/Streaming/channels/101 – get the main stream of the 1st channel rtsp://192.168.0.100:554/Streaming/channels/102 – get the sub stream of the 1st channel
# 카메라 Configure - Stream manager - Video Setting - Encoding Format 에서
# H265 로 설정하면 아래와 같은 에러 메세지가 발생한다.
# [hevc @ 0000024133eada80] PPS id out of range: 0
# H264 로 설정하면 괜찮다. 특정 카메라에서만 이런 현상이 나타날 수도 있다.
ifnot cap.isOpened():
print("Not opened")
exit()
while cv2.waitKey(1) <0:
ret, frame = cap.read()
ifnot ret:
print("False returned")
exit()
cv2.imshow("video", frame)
cap.release()
cv2.destroyAllWindows()
HikVision Camera RTSP Stream Setting
RTSP without Authentication (NVR/DVR/IPC/Encoder) rtsp://<IP address of device>:<RTSP port>/Streaming/channels/<channel number><stream number> RTSP with Authentication rtsp://<username>:<password>@<IP address of device>:<RTSP port>/Streaming/channels/<channel number><stream number> NOTE: <stream number> represents main stream (01), or the sub stream (02) Example: rtsp://192.168.0.100:554/Streaming/channels/101 – get the main stream of the 1st channel rtsp://192.168.0.100:554/Streaming/channels/102 – get the sub stream of the 1st channel
만약 Sub Stream(Stream0)이 아닌 Main Stream(Stream1)을 사용하면 영상은 큰 문제 없이 계속 출력되지만 아래와 같은 에러 메세지가 계속 나타난다. (Sub Stream에서도 종종 에러가 발생하기도 했다)
이런 에러 때문인지는 모르겠지만 OpenCV에서 rtsp를 이용해 출력한 영상은 카메라에서 자체 지원하는 웹뷰 등을 이용해 확인한 영상보다 노이즈가 심하다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import queue
import threading
import cv2
q=queue.Queue()
stop =False
def Receive():
print("start Reveiving")
cap = cv2.VideoCapture('rtsp://admin:123456@192.168.0.161:554/stream0')
ifnot cap.isOpened():
print("Not opened")
exit()
global stop
ret =True
while ret andnot stop:
ret, frame = cap.read()
lock.acquire()
ifnot ret:
print("False returned")
continue
q.put(frame)
lock.release()
cap.release()
cv2.destroyAllWindows()
def Display():
print("Start Displaying")
global stop
while cv2.waitKey(1) <0:
lock.acquire()
ifnot q.empty():
frame=q.get()
cv2.imshow("stream", frame)
lock.release()
stop =True
if __name__ =='__main__':
lock = threading.Lock()
t1 = threading.Thread(target = Receive)
t2 = threading.Thread(target = Display)
t1.start()
t2.start()
영상을 받아오는 부분과 출력하는 부분을 다른 스레드로 구분하고 각각의 스레드에서 영상에 접근할때 충돌을 방지하기 위해 Primitive Lock을 사용해 봤지만 별 효과는 없다.
오히려 Main Stream(Stream1)에서 Sub Stream(Stream0)으로 바꿔 영상의 크기를 줄이는게 에러 확률을 크게 낮추었다.