大佬教程收集整理的这篇文章主要介绍了linux – 让BeagleBone使用OpenCV捕获静态帧,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
所以我插入了我的USB网络摄像头,并检查/ dev以确保它显示出来.
它确实如同视频0(右下).我知道这是正确的,因为它在我拔掉相机后就消失了.
所以现在我启动Python并运行以下命令:
root@beaglebone:/dev# python Python 2.7.2 (default,Sep 11 2012,16:15:43) [GCC 4.5.4 20120305 (prereleasE)] on linux2 Type "Help","copyright","credits" or "license" for more information. >>> import cv >>> capture=cv.CaptureFromCAM(-1) >>> img=cv.QueryFrame(capturE) >>> type(capturE) <type 'cv2.Capture'> >>> type(img) <type '@L_801_4@'>
如您所见,我能够充分创建捕获对象,但我无法从中拉出帧.我也用相机ID(上面代码中的-1)的不同(或没有)整数参数尝试了这个,但无济于事.
作为参考,在IPython上我的笔记本电脑上运行相同的代码如下所示:
In [1]: import cv In [2]: capture=cv.CaptureFromCAM(-1) In [3]: img=cv.QueryFrame(capturE) In [4]: type(capturE) Out[4]: cv2.Capture In [5]: type(img) Out[5]: cv2.cv.iplimage
你可以看到我在这里正在拍摄一张图片.我不确定从这里到底要去哪里.
更新:
我在FFmpeg玩了一下,并且能够通过发出以下命令让相机响应(也就是说,它继续亮起):
root@beaglebone:/# ffmpeg -f video4linux2 -i /dev/video0
这很有趣,因为apparently CaptureFromCAM使用的是V4L界面……我不知道从哪里开始.
import cv capture = cv.CaptureFromCAM(-1) if not capture: print "Unable to open device #-1" sys.exit(1)
发送-1作为参数告诉OpenCV打开默认的摄像头设备.在某些系统上,这不起作用,您需要增加数量.尝试传递0,然后传递1和更高版本2.
您需要做的第二件事是确保QueryFrame()返回有效的内容:
img = cv.QueryFrame(capturE) if not img: print "Unable to retrieve frame from the device" sys.exit(1)
我见过OpenCV的Python API和C(甚至是C)API之间的奇怪行为.如果以上都没有帮助您解决问题,我建议您使用OpenCV编译C程序(具有最可靠的API)从相机检索数据.在某些情况下,OpenCV的C API工作和Python没有.
This C program从相机中检索帧并将其显示在窗口中:
#include <stdio.h> #include <highgui.h> #include <cv.h> int main() { CvCapture* capture = NULL; if ((capture = cvCaptureFromCAM(-1)) == NULL) { fprintf(stderr,"ERROR: capture is NULL \n"); return -1; } cvNamedWindow("mywindow",CV_WINDOW_AUTOSIZE); cvQueryFrame(capturE); // Sometimes needed to get correct data while (1) { IplImage* frame = cvQueryFrame(capturE); // check return { fprintf( stderr,"ERROR: cvQueryFrame Failed\n"); break; } // At this point you already have the frame! There's no need to // repeat the thing 10x with cvGrabFrame and cvRetrieveFrame. // You are probably sabotaging yourself doing this multiple times. cvShowImage("mywindow",framE); // Do not release the frame! int key = cvWaitKey(10); if (key == 0x1b) break; } cvReleaseCapture(&capturE); cvDestroyWindow("mywindow"); return 0; }
以上是大佬教程为你收集整理的linux – 让BeagleBone使用OpenCV捕获静态帧全部内容,希望文章能够帮你解决linux – 让BeagleBone使用OpenCV捕获静态帧所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。