1 2 3 Previous Next 35 Replies Latest reply on Oct 1, 2015 10:59 AM by AdamMiltonBarker

    OpenCV and Galileo Gen1

    AdamMiltonBarker

       

      I have read many questions over the last few months but I cannot find a tutorial for what I need and I am pretty lost to be honest. Can anyone help out in guiding me to complete my goal for one of my systems.

      I have a system built on an Intel Galileo Gen 1 and I want to be able to provide a feature that from the GUI I have built for the system, users can view a stream from the webcam attached to the board to see realtime what is going on in the location surrounding the unit. I have searched and searched, seen all of the videos on google and still can't find a kind of step by step from installing opencv to getting it running so I can connect to the webcam that is attached to the board.

      If anyone can help will be appreciated.

       

        • 1. Re: OpenCV and Galileo Gen1
          samontab

           

          I wrote a very detailed tutorial for installing OpenCV for Ubuntu 14.04. You may be able to use it as a reference to install it on Galileo:

          http://www.samontab.com/web/2014/06/installing-opencv-2-4-9-in-ubuntu-14...

           

          • 2. Re: OpenCV and Galileo Gen1
            AdamMiltonBarker

             

            Hi thanks for the reply am I wrong in thinking that it is already part of the IoT dev kit image ? Do you have any info for getting the dev kit installation working and running a script that will allow me to stream the video to the GUI ?

             

            • 3. Re: OpenCV and Galileo Gen1
              mhahn

              No, you are right: if you use the Intel(R) IoT devkit SD card image (eglibc based) OpenCV will be part of. And you should find quite a number of examples online - e.g. http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_an....

              I'd suggest starting with

              • capture a frame and write to a file - if that works you know you can access the camera fine
              • 4. Re: OpenCV and Galileo Gen1
                AdamMiltonBarker

                 

                Hi thanks for the post I have been going for months trying to find anything that works. The closest I have got is:#

                01#include "opencv2/highgui/highgui.hpp"

                 

                02#include <iostream>

                 

                03

                 

                04using namespace cv;

                 

                05using namespace std;

                 

                06

                 

                07int main(int argc, char* argv[])

                 

                08{

                 

                09    VideoCapture cap(0); // open the video camera no. 0

                 

                10

                 

                11    if (!cap.isOpened())  // if not success, exit program

                 

                12    {

                 

                13        cout << "Cannot open the video cam" << endl;

                 

                14        return -1;

                 

                15    } else {

                 

                16        cout << "OPened Cam" << endl;

                 

                17    }

                 

                18

                 

                19   double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video

                 

                20   double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video

                 

                21

                 

                22    cout << "Frame size : " << dWidth << " x " << dHeight << endl;

                 

                23

                 

                24    namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

                 

                25    //VideoWriter video("capture.avi",CV_FOURCC('M', 'J', 'P', 'G'), 10, cvSize((int)dWidth,(int)dHeight) );

                 

                26

                 

                27    cout << "GOT HERE" << endl;

                 

                28    while (1)

                 

                29    {

                 

                30        Mat frame;

                 

                31

                 

                32        bool bSuccess = cap.read(frame); // read a new frame from video

                 

                33

                 

                34         if (!bSuccess) //if not success, break loop

                 

                35        {

                 

                36             cout << "Cannot read a frame from video stream" << endl;

                 

                37             break;

                 

                38        }

                 

                39

                 

                40        imshow("MyVideo", frame); //show the frame in "MyVideo" window

                 

                41

                 

                42        if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop

                 

                43       {

                 

                44            cout << "esc key is pressed by user" << endl;

                 

                45            break;

                 

                46       }

                 

                47    }

                 

                48    return 0;

                 

                49

                 

                50}

                 

                Which returns:

                root@quark00a8ee:~# chmod 755 /tmp/TASS;/tmp/TASS ;exit

                VIDIOC_QUERYMENU: Invalid argument

                VIDIOC_QUERYMENU: Invalid argument

                VIDIOC_QUERYMENU: Invalid argument

                VIDIOC_QUERYMENU: Invalid argument

                VIDIOC_QUERYMENU: Invalid argument

                VIDIOC_QUERYMENU: Invalid argument

                VIDIOC_QUERYMENU: Invalid argument

                OPened Cam

                Frame size : 640 x 480

                (MyVideo:353): Gtk-WARNING **: cannot open display:

                logout

                 

                I am using Intel Gen 1, IoT dev kit and Logitech HD720p using Eclipse IoT IDE

                • 5. Re: OpenCV and Galileo Gen1
                  mhahn

                   

                  some hints:

                  • find out (e.g. debugger) where "VIDIOC_QUERYMENU: Invalid argument" is print out if this message is relevant
                  • apparently your camera got openened fine (I suppose 640x480 resolution is fine? possibly you'd have to change the resolution via V4L to allow higher fps on Galileo)
                  • I'd recommend to start writing frames to files rather than to use imshow

                  Once you get correct frames start checking your X setup for your attached display. You would at least need to run something like X11 or Wayland - possibly also a display manager. Apparently it's not yet correctly set ("cannot open display").

                   

                  • 6. Re: OpenCV and Galileo Gen1
                    mhahn

                     

                    just saw you tried VideoWriter - did that work?

                     

                    • 7. Re: OpenCV and Galileo Gen1
                      AdamMiltonBarker

                       

                      Sorry you totally lost me with most of what you said above. I mentioned I have been banging my head with this for a while and I cannot get my head around what is going wrong.

                      VideoWriter gives

                      VIDIOC_DQBUF: No such device

                      (MyVideo:380): Gtk-WARNING **: cannot open display:

                      So I guess not, how come there is no tutorial for this yet, pretty much every topic I have found on it no one ever provides an answer and its always the same errors. Totally stumped on how to get it working.

                      Debug just says:

                      root@quark00a8ee:~# chmod 755 /tmp/TASS;gdbserver :2345 /tmp/TASS;exit
                      Process /tmp/TASS created; pid = 397
                      Listening on port 2345
                      Remote debugging from host PC IP

                       

                      • 8. Re: OpenCV and Galileo Gen1
                        AdamMiltonBarker
                        • 9. Re: OpenCV and Galileo Gen1
                          AdamMiltonBarker

                           

                          So I have managed to write an image but it is blank :S

                          The camera light is coming on until script ends so making progress, any ideas to push this one forward anyone ?

                           

                          01#include "opencv2/opencv.hpp"

                           

                           

                          02#include "opencv2/highgui/highgui.hpp"

                           

                           

                          03#include <iostream>

                           

                           

                          04

                           

                           

                          05using namespace cv;

                           

                           

                          06using namespace std;

                           

                           

                          07

                           

                           

                          08int main(int, char**)

                           

                           

                          09{

                           

                           

                          10    VideoCapture cap(-1);

                           

                           

                          11    if (!cap.isOpened())  // if not success, exit program

                           

                           

                          12    {

                           

                           

                          13        cout << "Cannot open the video cam" << endl;

                           

                           

                          14        return -1;

                           

                           

                          15    } else {

                           

                           

                          16        cout << "Opened Cam" << endl;

                           

                           

                          17    }

                           

                           

                          18    Mat save_img; cap >> save_img;

                           

                           

                          19    if(save_img.empty())

                           

                           

                          20    {

                           

                           

                          21        cout << "Something is wrong with the webcam, could not get frame." << endl;

                           

                           

                          22    } else {

                           

                           

                          23        cout << "Writing Image." << endl;

                           

                           

                          24        imwrite("test.jpg", save_img); // A JPG FILE IS BEING SAVED

                           

                           

                          25        cout << "Written Image test.jpg" << endl;

                           

                           

                          26    }

                           

                           

                          27    return 0;

                           

                           

                          28}

                           

                          root@quark00a8ee:~# chmod 755 /tmp/TASS;/tmp/TASS ;exit
                          VIDIOC_QUERYMENU: Invalid argument
                          VIDIOC_QUERYMENU: Invalid argument
                          VIDIOC_QUERYMENU: Invalid argument
                          VIDIOC_QUERYMENU: Invalid argument
                          VIDIOC_QUERYMENU: Invalid argument
                          VIDIOC_QUERYMENU: Invalid argument
                          VIDIOC_QUERYMENU: Invalid argument
                          Opened Cam
                          select timeout
                          Writing Image.
                          Written Image test.jpg
                          logout

                          • 10. Re: OpenCV and Galileo Gen1
                            AdamMiltonBarker

                            OK last update need to sleep lol.

                            01#include "opencv2/opencv.hpp"

                             

                            02#include "opencv2/highgui/highgui.hpp"

                             

                            03#include <iostream>

                             

                            04

                             

                            05using namespace cv;

                             

                            06using namespace std;

                             

                            07

                             

                            08int main(int, char**){

                             

                            09    VideoCapture cap(-1);

                             

                            10    if (!cap.isOpened()){

                             

                            11        cout << "Cannot open the video cam" << endl;

                             

                            12        return -1;

                             

                            13    } else {

                             

                            14        cout << "Opened Cam" << endl;

                             

                            15    }

                             

                            16    Mat frame; cap >> frame;

                             

                            17    bool bSuccess = cap.read(frame);

                             

                            18    if (!bSuccess){

                             

                            19        cout << "Cannot read a frame from video stream" << endl;

                             

                            20        return -1;

                             

                            21    } else {

                             

                            22        cout << "Read a frame from video stream" << endl;

                             

                            23    }

                             

                            24    cout << "Writing Image" << endl;

                             

                            25    imwrite("bleh.png", frame);

                             

                            26    cout << "Image Written " << endl;

                             

                            27    return 0;

                             

                            28}

                            Gives me:

                            root@quark00a8ee:~# chmod 755 /tmp/TASS;/tmp/TASS ;exit
                            VIDIOC_QUERYMENU: Invalid argument
                            VIDIOC_QUERYMENU: Invalid argument
                            VIDIOC_QUERYMENU: Invalid argument
                            VIDIOC_QUERYMENU: Invalid argument
                            VIDIOC_QUERYMENU: Invalid argument
                            VIDIOC_QUERYMENU: Invalid argument
                            VIDIOC_QUERYMENU: Invalid argument
                            Opened Cam
                            select timeout
                            select timeout
                            Read a frame from video stream
                            Writing Image
                            Image Written
                            logout

                            And black image still

                            • 11. Re: OpenCV and Galileo Gen1
                              mhahn

                               

                              Quote:

                               

                              ForumMigrationAdmin wrote:

                               

                              OK last update need to sleep lol.

                              01 #include "opencv2/opencv.hpp"

                               

                              02 #include "opencv2/highgui/highgui.hpp"

                               

                              03 #include <iostream>

                               

                              04

                               

                              05 using namespace cv;

                               

                              06 using namespace std;

                               

                              07

                               

                              08 int main(int, char**){

                               

                              09     VideoCapture cap(-1);

                               

                              10     if (!cap.isOpened()){

                               

                              11         cout << "Cannot open the video cam" << endl;

                               

                              12         return -1;

                               

                              13     } else {

                               

                              14         cout << "Opened Cam" << endl;

                               

                              15     }

                               

                              16     Mat frame; cap >> frame;

                               

                              17     bool bSuccess = cap.read(frame);

                               

                              18     if (!bSuccess){

                               

                              19         cout << "Cannot read a frame from video stream" << endl;

                               

                              20         return -1;

                               

                              21     } else {

                               

                              22         cout << "Read a frame from video stream" << endl;

                               

                              23     }

                               

                              24     cout << "Writing Image" << endl;

                               

                              25     imwrite("bleh.png", frame);

                               

                              26     cout << "Image Written " << endl;

                               

                              27     return 0;

                               

                              28 }

                              Gives me:

                              root@quark00a8ee:~# chmod 755 /tmp/TASS;/tmp/TASS ;exit
                              VIDIOC_QUERYMENU: Invalid argument
                              VIDIOC_QUERYMENU: Invalid argument
                              VIDIOC_QUERYMENU: Invalid argument
                              VIDIOC_QUERYMENU: Invalid argument
                              VIDIOC_QUERYMENU: Invalid argument
                              VIDIOC_QUERYMENU: Invalid argument
                              VIDIOC_QUERYMENU: Invalid argument
                              Opened Cam
                              select timeout
                              select timeout
                              Read a frame from video stream
                              Writing Image
                              Image Written
                              logout

                              And black image still

                              code looks ok - maybe try specifying the camera in VideoCapture (e.g. set to '0' = default, or to '1', ..., '99'). Maybe you're on a "/dev/zero" kind of camera?

                              You could write a quick OpenCV program to scan through the cameras to get a list of existing ones

                              • 12. Re: OpenCV and Galileo Gen1
                                mhahn

                                 

                                at this stage you could also work on e.g. a Windows, or a Linux host (I am pretty sure OSX would work the same but I never tried OpenCV there). and compare results with what you get on Galileo

                                 

                                • 13. Re: OpenCV and Galileo Gen1
                                  @intel_stewart

                                   

                                  There's a great book published by Apress, and the ebook is free http://www.apress.com/9781430268390 and it has gen 1 and gen 2 OpenCV examples for both C++ and Python, even includes the different frame rates. Example code and a tutorial is difficult to beat.

                                  The Kindle version is free too. 

                                   

                                  • 14. Re: OpenCV and Galileo Gen1
                                    AdamMiltonBarker

                                     

                                    Hi thanks I have downloaded it will check it out, have you any idea why the image is black ?

                                     

                                    1 2 3 Previous Next