Software Archive
Read-only legacy content
17061 Discussions

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

stephen_h_
Beginner
2,312 Views

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.

0 Kudos
1 Solution
stephen_h_
Beginner
2,312 Views

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

View solution in original post

0 Kudos
10 Replies
Sulamita_G_Intel
Employee
2,312 Views

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++ Linker 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 -lopencv2

 

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

Regards, Sulamita.

 

0 Kudos
stephen_h_
Beginner
2,313 Views

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

0 Kudos
Sulamita_G_Intel
Employee
2,312 Views

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.

0 Kudos
Stewart_C_Intel
Employee
2,312 Views

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-)..

 

0 Kudos
Matthias_H_Intel
Employee
2,312 Views

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

0 Kudos
Stephen_Han
Employee
2,312 Views

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

0 Kudos
Barath_L_
Beginner
2,312 Views

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.

 

0 Kudos
Matthias_H_Intel
Employee
2,312 Views
  1. you probably would have some more info like where this problem occurred. 
  2. you might want to step through with a debugger 

 

0 Kudos
Anonymous
Not applicable
2,312 Views

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 ?

0 Kudos
Bryan_V_
Beginner
2,312 Views

Sulamita Garcia (Intel) wrote:

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++ Linker 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 -lopencv2

 

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

Regards, Sulamita.

 

 

 

Hi, i tried to start a new project from examples included on Eclipse Sdk for IoT as you said to start to work with openCV into eclipse but i can't find Cross G Compiler in  C/C++ Build -> Settings -> Tool Settings -> Cross G++ Compiler to add that libraries that i need. What i need do for start to work?

0 Kudos
Reply