我正在尝试使用内核版本为3.6.8-x4的ubuntu-12.04从BeagleBoard-xm上的文件中捕获视频,但是在运行时完全相同的程序&工作正常我的主机(PC)也是ubuntu-12.04代码我试图捕捉橙色(火花发生在一台机器和试图捕获它在一个框架中)。 代码如下:
#include<cv.h>
#include<opencv2/highgui/highgui.hpp>
//Input-Output
#include<stdio.h>
#include<iostream>
//Blob Library Headers
#include<cvblob.h>
//Definitions
#define h 240
#define w 320
//NameSpaces
using namespace cv;
using namespace cvb;
using namespace std;
int main()
{
int count=1;
//Structure to get feed from CAM
char *buffer;
buffer=(char *) malloc(100);
//CvCapture* capture=cvCreateCameraCapture(0);
//CvCapture* capture = cvCaptureFromFile("/home/ubuntu/movie.avi"); //recording of spark
CvCapture* capture = cvCaptureFromFile("/home/ubuntu/20130521053652.avi"); //recording of spark
//capture image from video
//Mat fra, edges;
//capture >> fra;
//Structure to hold blobs
CvBlobs blobs;
//Windows
//Image Variables
IplImage *frame=cvCreateImage(cvSize(w,h),8,3); //Original Image
IplImage *hsvframe=cvCreateImage(cvSize(w,h),8,3);//Image in HSV color space
IplImage *labelImg=cvCreateImage(cvSize(w,h),IPL_DEPTH_LABEL,1);//Image Variable for blobs
IplImage *threshy=cvCreateImage(cvSize(w,h),8,1); //Threshold image of yellow color
IplImage* fra = NULL;
//Getting the screen information
//int screenx = GetSystemMetrics(SM_CXSCREEN);
//int screeny = GetSystemMetrics(SM_CYSCREEN);
fra = cvQueryFrame(capture);
//imwrite("test.jpg", fra);
cvSaveImage("test.png", frame);
//system("ffmpeg -ss 19 -i 20130521053652.avi -vframes 1 -f image2 tst.jpg");
while(1)
{
//Getting the current frame
IplImage *fram=cvQueryFrame(capture);
//If failed to get break the loop
if(!fram)
break;
//Resizing the capture
cvResize(fram,frame,CV_INTER_LINEAR );
//Flipping the frame
cvFlip(frame,frame,1);
//Changing the color space
cvCvtColor(frame,hsvframe,CV_BGR2HSV);
cvInRangeS(hsvframe,cvScalar(0,41,133),cvScalar(22,150,255),threshy);
cvSmooth(threshy,threshy,CV_MEDIAN,7,7);
//Finding the blobs
unsigned int result=cvLabel(threshy,labelImg,blobs);
if(result > 0)
{
printf("\n/*==Sparks==*/");
}
//Rendering the blobs
cvRenderBlobs(labelImg,blobs,frame,frame);
//Filtering the blobs
cvFilterByArea(blobs,60,500);
for (CvBlobs::const_iterator it=blobs.begin(); it!=blobs.end(); ++it)
{
double moment10 = it->second->m10;
double moment01 = it->second->m01;
double area = it->second->area;
//Variable for holding position
int x1;
int y1;
//Calculating the current position
x1 = moment10/area;
y1 = moment01/area;
if(result > 0)
{
//count++;
//fra = NULL;
fra = cvQueryFrame(capture);
sprintf(buffer,"spark_image-%d.png",count) ;
//imwrite("tet.jpg", fra);
cvSaveImage(buffer, frame);
count++;
}
//Mapping to the screen coordinates
//int x=(int)(x1*screenx/w);
//int y=(int)(y1*screeny/h);
//Printing the position information
//cout<<"X: "<<x<<" Y: "<<y<<endl;
}
//Showing the images
//system("ffmpeg -ss 19 -i 20130521053652.avi -vframes 1 -f image2 t?st.jpg");
//img = imread("MyPic.JPG", CV_LOAD_IMAGE_UNCHANGED); //read the image data in the file "MyPic.JPG" and store it in 'img'
//frame >> save_img;
/*==> show images*/
//cvShowImage("Live",frame);
char c=cvWaitKey(33);
if(c==27)
break;
}
//Cleanup
//free the memory
free(buffer);
cvReleaseCapture(&capture);
cvDestroyAllWindows();
}
并使用
在BeagleBone上编译 gcc track.cpp -o track 'pkgconfig opencv cvblob --libs --cflags'
将可执行文件作为track
返回。每当我们执行这个时它不会给出任何错误,而是显示它
[avi @ 0x13cb940] non-interleaved AVI
&amp;被长期绞死(在我们取消之前没有回复)。