while True:
_, frame = video_capture.read()
small_frame = cv2.resize(frame, None , fx=0.25, fy=0.25)
rgb_small_frame = cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB)
我在调整窗口大小时遇到以下错误... 顺便说一句,别介意我的话,我仍然是一个 python 孩子,但我的项目需要它
错误:
[ERROR:[email protected]] global obsensor_uvc_stream_channel.cpp:159 cv::obsensor::getStreamChannelGroup Camera index out of range
Traceback (most recent call last):
File "C:\Users\123ab\PycharmProjects\FaceRecognition\program.py", line 35, in <module>
small_frame = cv2.resize(frame, None , fx=0.25, fy=0.25)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cv2.error: OpenCV(4.9.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\resize.cpp:4152: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
Process finished with exit code 1
我期待一个窗口显示我电脑网络摄像头的实时视频,但我收到了上述错误
顺便说一句,这是我的规格:
i5-12400f 16GB DDR4 内存 500GB SSD 关键 t500 pro 技嘉 h610 mk ddr4 v2 索泰 RTX 3050 8GB 生态 网络摄像头:是的
以下只是一个演示,说明如何使您向我们展示的小代码发挥作用。 我在 Windows 10 电脑上测试了这个。
import cv2 # install package opencv-python 4.10.0.84 if you haven't already
# Initialize the video capture object for the default camera (0 is usually the default)
video_capture = cv2.VideoCapture(0)
while True:
result, frame = video_capture.read()
if not result:
print("Failed to capture frame")
break
small_frame = cv2.resize(frame, None, fx=0.25, fy=0.25)
cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB)
cv2.imshow('Video', small_frame) # without this, nothing will be displayed
cv2.waitKey(1) # without this, the image won't refresh