0

I am trying to capture a video from a file on BeagleBoard-xm with ubuntu-12.04 with Kernel version 3.6.8-x4, but when run the program which is exactly same & working fine onto my host machine (pc) which is also ubuntu-12.04 in code i am trying to catch orange colour (spark is taking place in a machine & trying to capture it in a frame). Code is given Below:

#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();

            }

and compiled on BeagleBone with

gcc track.cpp -o track 'pkgconfig opencv cvblob --libs --cflags'

its returning an Executable as track. Whenever we execute this one its not giving any error instead its Display this [avi @ 0x13cb940] non-interleaved AVI & getting hanged for Long time (No response till we cancelled ).

Ayush joshi
  • 305
  • 1
  • 5
  • 14
  • How long did you wait before canceling it? What was the CPU load? You're doing time consuming operations (especially the median filter) which depending on the optimizations in the OpenCV library can be orderes of magnitude slower on ARM than on x86. – Gyorgy Szekely Nov 21 '13 at 10:57
  • for almost more than 15-20 minutes.One more thing i want to say you that it works fine when trying to capture simple video or capture an image......but when I am trying to deal with blob Detection its creating problem as explain above – Ayush joshi Nov 21 '13 at 11:03

0 Answers0