How to Build and debug Open cv project in Eclipse? - opencv

I have configure all the libraries and path required for running open cv in c/c++ mode in eclipse, i have written the below code, but i don't know how to build and debug,
my code is
#include "cv.h"
#include "highgui.h"
//using namespace cv;
int main(int argc, char *argv[])
{
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
IplImage* img = cvLoadImage("prado.jpg",1);
cvShowImage("Example1", img );//*/
cvWaitKey(0);
return 0;
}

Related

readlink() error while reading /proc/self/exefile on QNX

I am working on QNX platform, in which I need to get the path of executable which is running.
I have wrote a small peice of code, which is returning always -1:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
extern int errno;
int main( int argc, char** argv )
{
char buf[512] = {0};
const char mypath[100] = "/proc/self/exefile";
errno = 0;
printf("The value readlink:: %d %s\n",readlink(mypath, buf, 512 ), strerror( errno ));
return( 0 );
}
When I ran above code then I get following output:
The value readlink:: -1 No such file or directory
Am I missing anything?
What needs to be done to get my current exe path in QNX?
In QNX /proc/self/exefile is not a symbolic link; It's a regular file.
Try:
#include <fstream>
#include <iostream>
#include <string>
int main(int argc, char **argv) {
std::ifstream file("/proc/self/exefile");
std::string path;
std::getline(file, path);
std::cout << path << "\n";
return 0;
}

HDR image reading and writing in opencv

I had written code for hdr image reading in opencv whenever i try to compile that i am getting ‘TonemapDurand’ was not declared in this scope
this type of error.
#include"opencv2/opencv.hpp"
#include "vector"
#include "bits/stdc++.h"
#include "fstream"
using namespace cv;
int main(int argc, char** argv )
{
vector<Mat>images;
Mat image;
image = imread( argv[1], 1 );
images.push_back(image);
Mat ldr;
Ptr<TonemapDurand> tonemap = createTonemapDurand(2.2f);
tonemap->process(images[0], ldr);
imwrite("ldr.png", ldr * 255);
waitKey(0);
return 0;
}
It looks like there is no HDR support in OpenCV 2.4.9, as you can see from here.
You have to install OpenCV 3 for doing your experiments on HDR.
There is a nice blog on using HDR in OpenCV here
It looks like you have missed some includes in your code :
#include <opencv2/photo.hpp>

c++ cvShowImage error

I want to load an image with opencv. Everything is working properly but it doesn't show me the image. Code what I usin is here:
#include
#include
#include
using namespace cv;
using namespace std;
int main( int argc, const char** argv )
{
IplImage *img = cvLoadImage("D:/C++/ MGC.JPG");
cvNamedWindow("MyWindow", 1); //create a window with the name "MyWindow"
cvMoveWindow("MyWindow", 100, 100);
cvShowImage("MyWindow", img);
cvWaitKey(0); //wait infinite time for a keypress
cvDestroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"
return 0;
}
Is there a specific reason you chose to use the C interface? If not, you should be using the C++ interface
int main( int argc, const char** argv )
{
cv::Mat image = cv::imread("D:/C++/ MGC.JPG");
cv::namedWindow("MyWindow", 256);
cv::imshow("MyWindow", image );
cv::waitKey();
return 0;
}

OpenCV Access Pixel Value Using Mouse

Can any one tell what wrong with the below code. I am getting segmentation fault while mouse moving last portion of the image. I am just printing R,G,B value according to the mouse position.
#include <iostream>
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
Mat image;
char window_name[20]="Pixel Value Demo";
static void onMouse( int event, int x, int y, int f, void* ){
Vec3b pix=image.at<Vec3b>(x,y);
int B=pix.val[0];
int G=pix.val[1];
int R=pix.val[2];
cout<<R<<endl<<G<<endl<<B<<endl;
}
int main( int argc, char** argv )
{
namedWindow( window_name, CV_WINDOW_AUTOSIZE );
image = imread( "src.jpg");
imshow( window_name, image );
setMouseCallback( window_name, onMouse, 0 );
waitKey(0);
return 0;
}
Thanks in advance......
Vec3b pix=image.at<Vec3b>(x,y);
should be :
Vec3b pix=image.at<Vec3b>(y,x); // row,col !!

Open CV with CDT error?

I have configure an Openc CV include file path in Tool Setting, but it still gives warning in my code.
warning is :
Unresolved inclusion: <highgui.h>
my code is :
#include <cv.h>
#include <highgui.h>
using namespace cv;
int main()
{
Mat image;
image = imread( argv[1], 1 );
if( argc != 2 || !image.data )
{
printf( "No image data \n" );
return -1;
}
namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
imshow( "Display Image", image );
waitKey(0);
return 0;
}
You need to use a different include if you work with cv::Mat:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

Resources