想在框架中存在脸时捕获所有框架
我正在尝试构建面部图像的数据集,我已经搜索并找到了一个与笔记本电脑的网络摄像头正常工作的代码,但是当我尝试使用IP摄像机捕获通常用于监视的IP相机时,而不是代码不起作用。
import cv2
import numpy as np
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_alt2.xml')
cap = cv2.VideoCapture(0)
count = 0
while True:
ret,frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:
cv2.imwrite("frame%d.jpg" % count, frame)
count = count + 1
if cv2.waitKey(2) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
我想提到的另一件事是我的笔记本电脑摄像头分辨率是640.0 480.0,IP摄像机具有2560.0 1440.0。请帮助我在脸上捕获所有框架。
I am trying to build a dataset of face images, I have searched and find a code that is working fine with my laptop's webcam but when I am trying to capture with IP Camera which is usually used for surveillance than code is not working.
import cv2
import numpy as np
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_alt2.xml')
cap = cv2.VideoCapture(0)
count = 0
while True:
ret,frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:
cv2.imwrite("frame%d.jpg" % count, frame)
count = count + 1
if cv2.waitKey(2) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
Another thing I want to mention my laptop Camera resolution is 640.0 480.0 and IP Cameras have 2560.0 1440.0. Please help me to capture all frames when face is present.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要从特定摄像机捕获图像,您需要在
cv2.VIDEOCAPTURE(参数)
中更改参数。例如:cv2.VIDEOCAPTURE(0)
:用于选择默认摄像机,通常是笔记本电脑内置摄像机。cv2.videocapture(n)
其中n> = 1
:它用于通过USB/其他端口选择其他外部摄像机连接到笔记本电脑cv2.videocapture('协议:// ip:port/1')
:它用于从网络摄像机(如您的情况下)获取协议
表示:http/rtsp等。表示托管地址:示例:192.168.18.37
port
在这种情况下访问IP地址的位置应为:
To capture images from specific camera you need to change arguments in
cv2.VideoCapture(argument)
. For example:cv2.VideoCapture(0)
: it's used to select the default camera, generally laptop inbuilt camera.cv2.VideoCapture(n)
where n>=1
: it's used to select the other external camera connect to laptop through usb/other portscv2.VideoCapture('protocol://IP:port/1')
: it's used to take input from network cameras(like in your case)protocol
means: HTTP/RTSP etc.IP
means hosting address: Example: 192.168.18.37port
where the IP address is accessedIn this case it should be:
在调整分辨率后,问题已经解决,我添加了框架调整的代码行
frair = cv2.Resize(frame,(1360,768))
比代码开始正常工作。此代码可能对任何人有帮助。
The issue has been resolved after adjusting the resolution, I have added the line of code for frame adjustment
frame = cv2.resize(frame, (1360, 768))
than code has started working properly.This code might be helpful for anyone.
在图像捕获之前更改分辨率更为最佳。无需调整后续帧大小。
Before the
while
loop set the width and height as follows:Changing the resolution before image capture is more optimal. There would be no need to resize every subsequent frame.
Before the
while
loop set the width and height as follows:Different flags used for video streaming