![](/img/trans.png)
[英]Getting name is not defined error when trying to import a video to my cv2 face emotion recognition code
[英]Send cv2 video stream for face recognition
我正在努力解決將 cv2 視頻流(網絡攝像頭)發送到服務器(稍后將用於人臉識別)的問題。
我不斷收到服務器的以下錯誤:
Traceback (most recent call last):
File "server.py", line 67, in <module>
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
cv2.error: OpenCV(4.6.0) :-1: error: (-5:Bad argument) in function 'resize'
> Overload resolution failed:
> - src data type = 18 is not supported
> - Expected Ptr<cv::UMat> for argument 'src'
服務器看起來像這樣:
if client_socket:
while True:
packet = client_socket.recv(4 * 1024)
frame = np.array(packet)
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
rgb_small_frame = small_frame[:, :, ::-1]
這是客戶:
while True:
vid = cv2.VideoCapture(0)
while vid.isOpened():
time.sleep(0.5)
img, frame = vid.read()
frame = imutils.resize(frame, 4 * 1024)
a = pickle.dumps(frame)
message = struct.pack("Q", len(a)) + a
try:
client_socket.sendall(message)
except Exception as e:
print(e)
raise Exception(e)
有人知道嗎?
因為它是字節數據 stream,所以我嘗試包括例如睡眠 function 以允許更多處理。 還嘗試隔離客戶的圖片,但也出現錯誤。
您的代碼有幾個問題。 關於你的問題:你正在傳遞一個字節字符串來resize
:
import cv2
import numpy as np
cv2.resize(np.array(b"Hello"), (0, 0), fx=0.25, fy=0.25)
Output:
cv2.error: OpenCV(4.5.4) :-1: error: (-5:Bad argument) in function 'resize'
> Overload resolution failed:
> - src data type = 18 is not supported
> - Expected Ptr<cv::UMat> for argument 'src'
請考慮:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.