2

I am using OpenCV on an embedded target board (FriendlyARM mini6410, processor arm 1176 running linux kernel 2.6.38). I compiled OpenCV 2.4.4 library using toolchain provided for the board, found in the ftp (pls see the website of FriendlyARM). I disabled GTK, ffmpeg and enable v4l. The library is compiled successfully.

Then I write code:

#include <opencv.hpp>
#include <highgui/highgui.hpp>
#include <imgproc/imgproc.hpp>
#include <iostream>
#include <stdio.h>

using namespace cv;
using namespace std;

int main()
{
    int i;
    cout << "initialise" << endl;
    IplImage* img=0;
    cout << "capturing ..." << endl;
    CvCapture* capture = cvCaptureFromCAM(2);
    cout << "get here" << endl;
    if(!capture){
        cout << "not capture" << endl;
        return -1;
    }
    cout << "captured" << endl;
    img=cvQueryFrame(capture);

   IplImage* img1 = cvCreateImage(cvGetSize(img),8,3);
   // cvCvtColor(img,img1,CV_RGB2GRAY);
   cvCopy(img, img1);
   cvSaveImage("cam_snap.jpg",img1);
   cvReleaseImage( &img1 );
   cvReleaseImage( &img );
   cvReleaseCapture( &capture );
   cout << "exit" << endl;

   return 0;
}

The code is built successfully. I run the .elf executable in the target board, connected to camera (PS3 eye), but the resulting image looks like a broken television (noise-like):

noise like image

While in my host, the resulting image is as expected (scene in front of camera). Can you provide me suggestion as to what went wrong or where should I start on debugging?

bonchenko
  • 567
  • 1
  • 9
  • 21
  • Does simply v4l2-capture work good? Try to run a simple example from v4l2 package. And what does `v4l2-ctl` says? – Eddy_Em May 16 '13 at 07:02
  • hmm, I installed OpenCV as static libraries, and v4l package I suppose is not available as executable command in my target. I tried to run v4l2-ctl command, but target returns "bin/sh: v4l2-ctl: not found". No v4l related command is available. – bonchenko May 16 '13 at 08:24

2 Answers2

1

You should check your depth and channels. It is probably a matter of alignement, moreover be careful your image is probably in BGR and not in RGB. And you should use cv::Mat instead of IplImage in C++ and VideoCapture instead of CVCapture.

This sample of code should work. (Not tested on the same arch as your)

#include <opencv.hpp>
#include <highgui/highgui.hpp>
#include <imgproc/imgproc.hpp>
#include <iostream>
#include <stdio.h>

using namespace cv;
using namespace std;

int main()
{
    VideoCapture capture = cv::VideoCapture(0);
    cout << "get here" << endl;
    if(!capture.isOpened())  // check if we succeeded                                                                                                   
         return -1;

    cout << "captured" << endl;
    Mat img;
    capture >> img;
    imwrite("./test.png", img);
    capture.release();
    cout << "exit" << endl;
    return 0;
}

Hope it helped.

Poko
  • 792
  • 2
  • 8
  • 24
  • Hey thanks for the code. But I tried it on the target, the result is still noisy. So far, I am guessing the fault is in the v4l library (statically linked to opencv library) or the USB interface (mini6410 runs on full speed USB while PS3 eye is strictly high speed USB - [this article] (http://codelaboratories.com/research/view/ps3eye-not-your-typical-webcam)). Second diagnosis seems to be logically understandable and easier to try, but haven't got any USB webcam right now :( will report if there is new findings! – bonchenko May 16 '13 at 10:32
0

Okay, confirmed. mini 6410 runs USB 1.0, and ps3 eye needs USB 2.0. I tried the program using standard webcam (chinese product, itech pc camera), works wonderfully. Saved image is showing scene in front of camera

bonchenko
  • 567
  • 1
  • 9
  • 21