10 Replies Latest reply on Apr 30, 2015 1:32 PM by AdamMiltonBarker

    how to create opencv app with iotdk-ide-win for galileo board?

    AdamMiltonBarker

      I just downloaded iot-devkit-201409031152-mmcblkp0.direct.bz2 and iotdk-ide-win.7z. I'd like to create a opencv app for my galileo board with this SDK. I'm not familiar with eclipse. how should I create a project file for this case? I could not a doc talking about it.

        • 1. Re: how to create opencv app with iotdk-ide-win for galileo board?
          ForumMigrationAdmin

          Hi Stephen

          For creating a new project, you can copy one of the samples included with it, right clicking for instance project 2_cpp_helloworld and selecting copy, then paste. It will open a dialog that will ask you the name of a new project, and copy the all the settings. It's the easiest way to start.

          To use other libraries already included in the image like openCV, you will need to include the appropriate libraries and links to compile your code. If you use Eclipse, you would need:

          1) add the library path to include

          Right click your Project name, select Properties, then select Settings -> C/C++ Build -> Settings -> Tool Settings -> Cross G++ LinkerCompiler-> Includes, and then add:

          ${DEVKIT_HOME}/devkit-x86/sysroots/i586-poky-linux/usr/include/opencv2

          2) add the linker information:

          Right click your Project name, select Properties, then select Settings -> C/C++ Build -> Settings -> Tool Settings -> Cross G++ Linker -> Miscelaneous

          in the Linker Flags, add at the end of the line -lopencv2

           

          We are working on creating more documentation for this and other subjects.

          Regards, Sulamita.

          • 2. Re: how to create opencv app with iotdk-ide-win for galileo board?
            ForumMigrationAdmin

            Sulamita,

            It helps!  however, there is a typo and libraries for linking need to change to what I use (there are many libs for opencv). below is what works for me.

             

            1) add the library path to include

            Right click your Project name, select Properties, then select Settings -> C/C++ Build -> Settings -> Tool Settings -> Cross G++ Compiler -> Includes, and then add:

            ${DEVKIT_HOME}/devkit-x86/sysroots/i586-poky-linux/usr/include/opencv2

            2) add the linker information:

            Right click your Project name, select Properties, then select Settings -> C/C++ Build -> Settings -> Tool Settings -> Cross G++ Linker -> Miscelaneous

            in the Linker Flags, add at the end of the line -lopencv_highgui  -lopencv_imgproc -lopencv_core

             

            the soruce code for my est:

            #include <opencv2/opencv.hpp>
            #include <stdio.h>
            using namespace cv;
            //using namespace std;

            int main( int argc, char** argv )
            {
            char* imageName = argv[1];
            Mat image; image = imread( imageName, 1 );

            if( argc != 2 || !image.data ) { printf( " No image data \n " ); return -1; }

            Mat gray_image;
            cvtColor( image, gray_image, CV_BGR2GRAY );
            imwrite( "reslut.jpg", gray_image );
            return 0;
            }

            reagrds,

            stephen

            • 3. Re: how to create opencv app with iotdk-ide-win for galileo board?
              ForumMigrationAdmin

              Hi Stephen

              Great! And thanks for adding the details, I fixed the typo for future reference, but I'm sure more people will find your info helpful.

              Regards, Sulamita.

              • 4. Re: how to create opencv app with iotdk-ide-win for galileo board?
                ForumMigrationAdmin

                Stephen, can you also let the forum know what camera you are using to capture images? and any that you tried that didn't work.(8-)..

                • 5. Re: how to create opencv app with iotdk-ide-win for galileo board?
                  ForumMigrationAdmin

                  the PS4 camera definitely works fine. Haven't tried other cameras yet

                  • 6. Re: how to create opencv app with iotdk-ide-win for galileo board?
                    ForumMigrationAdmin

                    I tried 2 cameras:

                    1- a very old camera from Logitech - Pro 9000

                    2- a new camera from KINYO - EZCam PCM-512

                    both behave the same -I could take picture,  but it'll show several warning like " VIDIOC_QUERYMENU:Invalid argument". However, the code  did output a image file.

                    The bad new is that it alwasy failed when I tried to take video (see below code). the code compiles OK, but when I ran it,  video.isOpened()) always returns false.

                    //===================================

                    #include <iostream>

                    // Include standard OpenCV headers
                    // #include "cv.h"
                    // #include "highgui.h"
                    #include "opencv2/opencv.hpp"

                    using namespace std;

                    // All the new API is put into "cv" namespace
                    using namespace cv;

                    int main (int argc, char *argv[])
                    {
                        // Open the default camera
                        VideoCapture capture(0);

                        // Check if the camera was opened
                        if(!capture.isOpened())
                        {
                            cerr << "Could not create capture";
                            return -1;
                        }

                        // Get the properties from the camera
                        double width = capture.get(CV_CAP_PROP_FRAME_WIDTH);
                        double height = capture.get(CV_CAP_PROP_FRAME_HEIGHT);

                        cout << "Camera properties\n";
                        cout << "width = " << width << endl <<"height = "<< height << endl;

                        // Create a matrix to keep the retrieved frame
                        Mat frame;

                        // Create a window to show the image
                        //namedWindow ("Capture", CV_WINDOW_AUTOSIZE);

                        // Create the video writer
                        VideoWriter video("capture.avi",CV_FOURCC('M', 'J', 'P', 'G'), 10, cvSize((int)width,(int)height) );
                      
                       
                        // Check if the video was opened
                        if(!video.isOpened())
                        {
                            cerr << "Could not create video.";
                            return -1;
                        }

                        cout << "Press Esc to stop recording." << endl;

                        // Get the next frame until the user presses the escape key
                        while(true)
                        {
                            // Get frame from capture
                            capture >> frame;

                            // Check if the frame was retrieved
                            if(!frame.data)
                            {
                                cerr << "Could not retrieve frame.";
                                return -1;
                            }

                            // Save frame to video
                            video << frame;

                            // Show image
                            //imshow("Capture", frame);

                            // Exit with escape key
                            if(waitKey(1) == 27)
                                break;
                        }

                    //==================================

                    regards,

                    stephen

                    • 7. Re: how to create opencv app with iotdk-ide-win for galileo board?
                      ForumMigrationAdmin

                      Stephen, i tried to use your source code for test but it shows the following

                      terminate called after throwing an instance of 'std::logic_error'
                        what():  basic_string::_S_construct null not valid
                      Aborted

                      can you please give me some direction in this regard [im a beginner].

                      Thanks in advance.

                      • 8. Re: how to create opencv app with iotdk-ide-win for galileo board?
                        ForumMigrationAdmin
                        1. you probably would have some more info like where this problem occurred.
                        2. you might want to step through with a debugger
                        • 9. Re: how to create opencv app with iotdk-ide-win for galileo board?
                          AdamMiltonBarker

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

                          Failing at videowriter


                          #include <opencv2/opencv.hpp>

                          #include <iostream>

                          #include <ctime>

                          using namespace cv;

                          using namespace std;

                          int main()

                          {

                          VideoCapture cap(-1);

                          if(!cap.isOpened()){

                          cout << "Webcam could not be opened successfully" << endl;

                          exit(-1);

                          } else {

                          cout << "Webcam opened successfully" << endl;

                          }

                            double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH);

                            double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT);

                            cout << "Frame Size = " << dWidth << "x" << dHeight << endl;

                            Size frameSize(static_cast<int>(dWidth), static_cast<int>(dHeight));

                            VideoWriter oVideoWriter ("video.mpeg" ,CV_FOURCC('M','J','P','G'), 1 ,frameSize, 0);

                            if ( !oVideoWriter.isOpened() ){

                          cout << "ERROR: Failed to write the video" << endl;

                          return -1;

                            }

                          for(;;){

                           

                          Mat frame;

                          bool bSuccess = cap.read(frame);

                           

                          if (!bSuccess){

                          cout << "ERROR: Cannot read a frame from video file" << endl;

                          break;

                          }

                           

                          oVideoWriter.write(frame);

                           

                          if (waitKey(10) == 27){

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

                          break;

                          }

                            }

                           

                          cap.release();

                          return 0;

                          }

                          • 10. Re: how to create opencv app with iotdk-ide-win for galileo board?
                            AdamMiltonBarker

                            Using a Logitech HD720p  and the exact method and code from stephen h I get the same as Barath L.

                            chmod 755 /tmp/TASS;/tmp/TASS ;exit
                            terminate called after throwing an instance of 'std::logic_error'
                              what():  basic_string::_S_construct null not valid
                            Aborted
                            logout

                            Any ideas on this ?

                             

                            www.plus.google.com/+AdamMiltonBarker