10 Replies Latest reply on Mar 9, 2016 11:09 AM by PabloM_Intel

    Intel Galileo OpenCv Project using Eclipse IDE



      I am a newbie at Intel Galileo and opencv but this is my senior project so I have to learn. Now I have just done all the things written here IoT - Getting Started with the Intel® Galileo Board on Windows* | Intel® Developer Zone then installed Eclipse IDE and connected it to Intel Galileo. I tried blink codes and it worked. Now I want to process images with OpenCv. First of all I wrote these basic codes to capture a video from the webcam and I was expecting a window to show up and that I can see the view of my webcam on my computer. But it says Gtk-WARNING **: cannot open display:

      So what can I do to solve this problem?


      By the way, at the end of this project it will be a tennis ball tracking robot so any ideas/methods will be appreciated.


      #include <opencv/cv.h>

      #include <opencv/highgui.h>

      #include <X11/keysym.h>



      int main(int argc, char **argv)


        /* Start the CV system and get the first v4l camera */

        cvInitSystem(argc, argv);

        CvCapture *cam = cvCreateCameraCapture(0);



        /* Create a window to use for displaying the images */

        cvNamedWindow("img", 0);

        cvMoveWindow("img", 200, 200);



        /* Display images until the user presses q */

        while (1) {


        IplImage *img = cvRetrieveFrame(cam);

        cvShowImage("img", img);

        if (cvWaitKey(10) == XK_q)

        return 0;




        • 1. Re: Intel Galileo OpenCv Project using Eclipse IDE

          Hi davulist,


          I would suggest you to check these threads for more information on image and video capture.

          Intel Galileo Gen2 - USB Camera

          OpenCV projects ?

          I was able to capture images and video on Edison using these set of instructions. Maybe you can implement some lines to your code from the discussions above.




          • 2. Re: Intel Galileo OpenCv Project using Eclipse IDE

            Hi davulist,


            Do you have updates on this?

            Are you able to see the /video0 device on /dev?

            Which webcam are you using?

            Also, you can’t use the function cvShowImage because the Galileo do not have a multimedia processor or screen that could allow you to show the image on it.




            1 of 1 people found this helpful
            • 3. Re: Intel Galileo OpenCv Project using Eclipse IDE

              Thanks to you both for your answers PabloM_Intel and CMata_Intel

              Yeah that was the problem. I was expecting from a system without a multimedia processor to show me the image on a window. I have a logitech C270 as a webcam. Now I have changed the codes. I used the code which is used in this tutorial Tutorial: Real-Time Object Tracking Using OpenCV - YouTube I used that source file in Visual Studio'10 and it worked great. Then I copied and pasted this code to the eclipse ide. I erased some parts of it including the imshow() parts. Then I ran it and there was no problem. I just didn't understand if the system track the ball or not. So I decided to add led blink code to the tracking part as follows. 


              void trackFilteredObject(int &x, int &y, Mat threshold, Mat &cameraFeed){

                Mat temp;



                //these two vectors needed for output of findContours

                vector< vector<Point> > contours;

                vector<Vec4i> hierarchy;


                //find contours of filtered image using openCV findContours function

                findContours(temp,contours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE );


                //use moments method to find our filtered object

                double refArea = 0;

                bool objectFound = false;


                if (hierarchy.size() > 0) {

                     int numObjects = hierarchy.size();



                               for (int index = 0; index >= 0; index = hierarchy[index][0]) {

                                         Moments moment = moments((cv::Mat)contours[index]);

                                         double area = moment.m00;



                                         //if the area is less than 20 px by 20px then it is probably just noise

                                         //if the area is the same as the 3/2 of the image size, probably just a bad filter

                                         //we only want the object with the largest area so we safe a reference area each

                                         //iteration and compare it to the area in the next iteration.

                                            if(area>MIN_OBJECT_AREA && area<MAX_OBJECT_AREA && area>refArea){

                                                        x = moment.m10/area;

                                                        y = moment.m01/area;

                                                        objectFound = true;

                                                        refArea = area;

                }else objectFound = false;




              //let user know you found an object

                if(objectFound ==true){


                mraa::Gpio* d_pin = NULL;

                d_pin = new mraa::Gpio(3, true, true);










              But the led doesn't blink. There is still no error in running and led of the webcam is on but the onboard led doesn't blink. Is it supposed to work same as it works in visual studio? What should I do?


              PS: The code I used in visual studio is here. https://raw.githubusercontent.com/kylehounslow/opencv-tuts/master/object-tracking-tut/objectTrackingTut.cpp

              • 4. Re: Intel Galileo OpenCv Project using Eclipse IDE

                Well, I could manage to make onboard led blink finally. To help the people who have the same problem, I advise you to check the current pixel format and resolution with this command v4l2-ctl --get-fmt-video My problem was that resolution of the webcam was 160/120 but in my codes I was using 640/480 resolution. And with this command v4l2-ctl --set-fmt-video width=640,height=480,pixelformat=1 I made it 640/480 in MJPG format. Now I made the led blink but still I got some problems. By using visual studio and trackbars I obtained the values H_MIN, H_MAX, S_MIN, S_MAX, V_MIN, V_MAX which makes the system track the ball but I think these values should change place to place because when I show the ball to the webcam, the led doesn't blink immediately. I think sometimes webcam doesn't recognise it in some positions. And it is important for me because I have to make distance calculation with the treshold area and if webcam recognise just half of the ball, my calculation error becomes huge.


                What are you suggestions about that problem?

                • 5. Re: Intel Galileo OpenCv Project using Eclipse IDE

                  Hi davulist,


                  Are you sure that the problem is not related to a possible delay at the moment of tracking and recognizing the ball? Did you make sure to give the program enough time to track the ball?

                  Also, make sure that the background is “object friendly”, by this I mean that there are no abrupt changes in it that may cause some erroneous behavior.




                  • 6. Re: Intel Galileo OpenCv Project using Eclipse IDE

                    Hi davulist,


                    I would like to know if you have been able to work on this. Have you tried to optimize the code you have?

                    The problem you have could be related in the amount of processes you are running on the board and the time that those processes need. As Pablo said, you need to check the time you are giving to the different tasks on your code.




                    • 7. Re: Intel Galileo OpenCv Project using Eclipse IDE

                      Hi PabloM_Intel and CMata_Intel


                      Thanks to you both for your answers. As PabloM_Intel mentioned above, the problem was I didn't have the object friendly background. Now I have a one-colour backgraound and it works better. Now I have two questions again.


                      1) I want to make a persistent sketch in my intel galileo. I mean, for example if webcam sees the ball, the onboard led is on if not, the led is off. I can do this by running the code on eclipse ide but I want my galileo do the same thing while it is not connected to eclipse ide. How can I do this?


                      2) I want to make a mobile robot. When I throw the ball, the robot will see it and when the ball stops moving, my robot will go to the ball. How can I do this by using opencv? Is there any command that understads if an object is stable or moving?



                      • 8. Re: Intel Galileo OpenCv Project using Eclipse IDE

                        Hi davulist,


                        Answering to your questions:

                        1. If you want to make your sketch persistent, I would suggest you to check the following links, https://software.intel.com/en-us/get-started-galileo-windows-step1, this first link is to produce a bootable micro SD card. And to create a service to run the sketch from boot check this one, https://communities.intel.com/message/358383#358383, the thread talks about doing it for Intel Edison, but it should be possible to apply it to the Galileo board.
                        2. There’s a lot of information on opencv.org about your question, you can start by reading the next document http://docs.opencv.org/3.0-beta/modules/video/doc/motion_analysis_and_object_tracking.html. You can also check the openCV forums as they may have some similar threads.




                        • 9. Re: Intel Galileo OpenCv Project using Eclipse IDE

                          Thanks for your answer PabloM_Intel I'll try to do that. And also if I want to change a persistent sketch, do I have to just make another one or do I have to delete the previous one first? And one more thing, if I copy my codes from eclipse ide and paste them to Arduino Ide (there will be opencv codes and dc motor drive codes), will it work or should I change some headers from the codes. Because I think there is no main part in arduino ide, it looks different for me.

                          • 10. Re: Intel Galileo OpenCv Project using Eclipse IDE

                            Hi davulist,


                            You’ll need to delete the previous one. But I believe you can just change the names of the sketches so you don’t have to make everything again, assign the original sketch name to the new one and change the name of the first sketch to identify it, you could use something like “oldsketch” or similar.

                            Regarding your second question, even if both IDEs use C++, you’ll probably need to make some changes to the code. If you’re using libraries that are not available in the Arduino IDE, you’ll need to import them. There are some other differences that you’ll need to take into account.