在此post中,考虑了OpenCV中的形状检测主题(来自图像)。为了扩展主题,如何通过实时视频流实时检测OpenCV的形状?
答案 0 :(得分:1)
是的,可以从视频流中使用OpenCV检测形状 - 正如Miki所提到的,VideoCapture
并将每个帧作为单个图像抓取将是这样做的方法。 C ++中的代码类似于:
//inside your method, make sure to bring in the libraries needed
VideoCapture capture(0); //opens the first webcam on your computer
Mat frame;
while (true) {
capture >> frame; //pulls the next frame in
if (frame.empty()) { //makes sure it's not empty
printf("No frame!");
break;}
//do whatever you want with that frame here
imshow("framename", frame); //displays the frame to the user
waitKey(1); //longer gives you a longer delay between frames
}
实时操作会有点困难 - 取决于相机的帧速率和计算机处理程序的强大程度,您可以将更新速率降低到几分之一秒。如果它仍然不够快,通过opencv cuda
或opencv gpu
库可能会让您获得更快的速度。