Open CV Application execution time error? - opencv

i am running my Project "DisplayImage",Open CV application in eclipse, but i got error in DisplayImage.d under Debug Folder the error is :
make: *** multiple target patterns. Stop.
and my code is :
#include <cv.h>
#include <highgui.h>
using namespace cv;
int main( int argc, char** argv )
{
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;
}
i have successfuly include lib and open cv in project,but i got this error when i try to runs the project

Related

Install OpenCV 3.2 with VS2010 in Windows 8 for 64 bit

I want to use OpenCv3.2 in Visual studio 2010,I am using windows 8, 64 bit and install OpenCV 3.2 and done the environment variable setting as append Path:OPENCV_DIR%\bin;C:\Program Files\opencv\build\x64\vc14\bin and also add Libraries in VS2010 from Project Properties->VC ++ Directories->C:\Program Files %28x86%29\opencv\build\include
And add all the hpp files in .cpp file in project.
The included files are:
# include "opencv2/opencv_modules.hpp"
# include <iostream>
# include "opencv2/core/core.hpp"
# include "opencv2/features2d/features2d.hpp"
# include "opencv2/highgui/highgui.hpp"
All are included only # include "opencv2/nonfree/features2d.hpp" is not getting included due to which I can't use the SurfFeatureDetector methods because included in the opencv2/nonfree/features2d.hpp.
/**
* #file SURF_detector
* #brief SURF keypoint detection + keypoint drawing with OpenCV functions
* #author A. Huaman
*/
#include "opencv2/opencv_modules.hpp"
#include <iostream>
#ifndef HAVE_OPENCV_NONFREE
int main(int, char**)
{
std::cout << "The sample requires nonfree module that is not available in your OpenCV distribution." << std::endl;
return -1;
}
#else
# include "opencv2/core/core.hpp"
# include "opencv2/features2d/features2d.hpp"
# include "opencv2/highgui/highgui.hpp"
# include "opencv2/nonfree/features2d.hpp"
using namespace cv;
void readme();
/**
* #function main
* #brief Main function
*/
int main( int argc, char** argv )
{
if( argc != 3 )
{ readme(); return -1; }
Mat img_1 = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
Mat img_2 = imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
if( !img_1.data || !img_2.data )
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; }
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 400;
SurfFeatureDetector detector( minHessian );
std::vector<KeyPoint> keypoints_1, keypoints_2;
detector.detect( img_1, keypoints_1 );
detector.detect( img_2, keypoints_2 );
//-- Draw keypoints
Mat img_keypoints_1; Mat img_keypoints_2;
drawKeypoints(img_1,keypoints_1,img_keypoints_1,Scalar::all(-1),
DrawMatchesFlags::DEFAULT );
drawKeypoints(img_2,keypoints_2,img_keypoints_2,Scalar::all(-1),
DrawMatchesFlags::DEFAULT );
//-- Show detected (drawn) keypoints
imshow("Keypoints 1", img_keypoints_1 );
imshow("Keypoints 2", img_keypoints_2 );
waitKey(0);
return 0;
}
/**
* #function readme
*/
void readme()
{ std::cout << " Usage: ./SURF_detector <img1> <img2>" << std::endl; }
#endif

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;
}

Video reading in opencv

I am new to opencv .I am trying to read video mp4 file but my code always says cannot open video device or file. I have placed video file in code folder .
VideoCapture capture;
capture.open("a.mp4"); // Open file
if (!capture.isOpened())
{
cout << "Cannot open video device or file!" << endl;
getch();
return -1;
}
Mat frame;
namedWindow("video", CV_WINDOW_AUTOSIZE);
while(true)
{
capture >> frame;
if (frame.empty())
break;
imshow("video", frame);
if (waitKey(30) == 'q')
break;
}
I am posting this answer in case someone came across this question as I did.
I was facing almost the same problem, trying to open a video file. My code worked with .avi but failed to open files with .mp4 files.
Turns out openCV needs ffmpeg decoder to be installed on the system. In case of windows OS, you will need to copy opencv_ffmpeg2411.dll file into C:\Windows\System32 directory. The DLL different systems can be found in OpenCV extracted directory.
Hope this helps someone.
this is correct code for video and image reading. I don't know what was the exact error. But using different code from orieally help me do my task in a different way.
// newproject.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "highgui.h"
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
#include <conio.h>
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <conio.h>
using namespace cv;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
//Image Reading
IplImage* img = cvLoadImage( "b.jpg" );
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage( "Example1", img );
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "Example1" );
//Video Reading
// cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );
// CvCapture* capture = cvCreateFileCapture( "video.avi" );
// IplImage* frame;
/* while(1) {
frame = cvQueryFrame( capture );
if( !frame ) break;
cvShowImage( "Example2", frame );
char c = cvWaitKey(33);
if( c == 27 ) break;//if user enter escape key then exit
}*/
//Summarize by sampling
CvCapture* capture = 0;
capture = cvCreateFileCapture( "video.avi" );
if(!capture){
return -1;
}
IplImage *bgr_frame=cvQueryFrame(capture);//Init the video read
double fps = cvGetCaptureProperty (capture,CV_CAP_PROP_FPS);
CvSize size = cvSize((int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH),(int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT));
//double fps = cvGetCaptureProperty (capture,CV_CAP_PROP_FPS);
CvVideoWriter *writer = cvCreateVideoWriter("Ayesha",CV_FOURCC('M','J','P','G'),fps,size);
int x=0;
while(1){
x++;
bgr_frame = cvQueryFrame( capture );
if(!bgr_frame)
break;
if(x==19||x==21){
cvShowImage("Example2",bgr_frame);
cvWriteFrame( writer, bgr_frame );
}
if(x==20){
cvShowImage("Example2",bgr_frame);
cvWriteFrame( writer, bgr_frame );
x=0;
}
char c=cvWaitKey(30);
if (c==27) break;
}
cvReleaseVideoWriter( &writer );
cvReleaseCapture( &capture );
cvDestroyWindow( "Example2" );
}

How to Build and debug Open cv project in Eclipse?

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;
}

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