cv.h: file not found opencv - opencv

I'm running this code:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv ) {
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0; }
But it isn't working for me because it shows this error on my screen when I write cmake . in terminal:
cv.h: file not found.
Could anyone help me? It was working one month ago.

you have linking problem, try this out;
g++ `pkg-config --cflags --libs opencv` filename.cpp -o filename

You can change the linker properties in case of Visual studio.
For Makefile you need to make sure that the opencv_dir is set correctly.

Related

OpenCv 3.1.0 undefined reference to imread

This is what my code looks like, I got the undefined reference to imread and so on:
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main( int argc, const char** argv )
{
Mat img = imread("MyPicture.jpg", CV_LOAD_IMAGE_UNCHANGED); //read the image data in the file "MyPic.JPG" and store it in 'img'
if (img.empty()) //check whether the image is loaded or not
{
cout << "Error : Image cannot be loaded..!!" << endl;
//system("pause"); //wait for a key press
return -1;
}
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
imshow("MyWindow", img); //display the image which is stored in the 'img' in the "MyWindow" window
waitKey(0); //wait infinite time for a keypress
destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"
return 0;
}
I am using Codeblocks and the g++ compiler. Also I have linked the opencv_world310d.lib to debug and opencv_world310.lib to release.
Plus I have given the path in searchdirectory compiler and linker.
Any hints?

Error In OpenCv

I installed opencv and configure it from tutorials, but when I am trying a code implementing it, all what is related to opencv is shown as an error as shown in the figure. Can you please help me? I really need it
#include "stdafx.h"
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int Main( void)
{
CvCapture* capture = 0;
// Start Capture From WebCam
capture = cvCaptureFromCAM( CV_CAP_ANY );
if( !capture )
{
cout << "No camera Detected" << endl;
}
// Create New Window
cvNamedWindow( "My OpenCV WebCam", CV_WINDOW_AUTOSIZE );
if( capture )
{
cout << "WebCam Is In capture" << endl;
for(;;)
{
// Get Captured Image And Show It In The New Window
// You Can Do Save It Or Filter It
IplImage* iplImg = cvQueryFrame( capture );
// Use This To Filter Image
//cvNot(iplImg, iplImg);
cvShowImage( "My OpenCV WebCam", iplImg );
if( waitKey( 10 ) >= 0 )
break;
}
}
cvReleaseCapture( &capture );
cvDestroyWindow( "My OpenCV WebCam" );
return 0;
}
From the comments to the question it turned out that the OP was linking to OpenCV 2.4.8, instead of OpenCV 3.0.0.
Correcting the linked libraries name, as well as the library path, solved the issue.

opencv c++ HSV image channel separation exception

I know this question has been asked a number of times and I'm trying to implement their answers but its causing an exception in my code.
OS: Windows 7
OpenCV: 2.4.9
Here is my code:
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
VideoCapture cap(0); //capture the video from webcam
if ( !cap.isOpened() ) // if not success, exit program
{
cout << "Cannot open the web cam" << endl;
return -1;
}
Mat imgHSV;
_sleep(100); //give the camera a chance to wake up
while (true)
{
Mat imgOriginal;
bool success = cap.read(imgOriginal);
if (!success) //if not success, break loop
{
cout << "Cannot read a frame from video stream" << endl;
break;
}
cvtColor(imgOriginal, imgHSV, COLOR_BGR2HSV); //Convert the captured frame from BGR to HSV
vector<Mat> hsv_planes;
split( imgHSV, hsv_planes );
//hsv_planes[0] // H channel
//hsv_planes[1] // S channel
//hsv_planes[2] // V channel
imshow(thresholded_window, hsg_planes[2]); //show the S channel
if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
break;
}
}
return 0;
}
Exception is thrown on the split line: "Unhandled exception at 0x62B978C9 (opencv_core249.dll) in TrackColour.exe: 0xC0000005: Access violation writing location 0xFEEEFEEE."
I figured out my problem, incase this happens to anyone else.
In VS I was doing a debug build but I was linking to the non debug versions of opencv. Notice in my error message opencv_core249, it should have been opencv_core249d (Note the 'd'). I updated my CV linking to use the debug libraries and it works.
The other opencv calls performed fine using the wrong libraries, something must be unique with split.

OPEN CV Program execution error?

I am running my below code in eclipse, i have include the path and libraries successfuly, but when run the code it shows an error.
#include <cv.h>
#include<stdio.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);
printf("this is open cv programming");
return 0;
}
Your main() signature is incomplete
try
int main(int argc, char* argv[])
these parameters represent:
argc // an int indicating the number of arguments passed in to the function
argv[] // an array of character strings, the actual arguments.
The first argument argv[0] is the program name ... so argc is always a minimum of 1.
The second argument, argv[1] will be the first argument your user passes in, bringing argc up to 2. That is what your program is expecting, a single argument from the user, argc == 2.
Try to use the latest version of OpenCV i.e. 2.4.3....however right now you can try to link the debug libraries e.g. opencv_core2.4.xd and run the program to get the Mat image format working.
what is the version of opencv you are using?
try the following code and test...get some picture and run it....
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main()
{
Mat im = imread("C:\\some_picture.jpg");
if(im.empty())
return -1;
imshow("TEST",im);
waitKey();
return 0;
}

MJPEG network stream to OpenCV 2

Can anyone explain to me why this code below does not work?
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include <iostream>
int main(int, char**) {
cv::VideoCapture vcap;
cv::Mat image;
const std::string videoStreamAddress = "http://hg55.no-ip.org/mjpg/video.mjpg";
//Yes, this stream does work! Try to paste it into your browser...
//open the video stream and make sure it's opened
if(!vcap.open(videoStreamAddress)) {
std::cout << "Error opening video stream or file" << std::endl;
return -1;
}
for(;;) {
if(!vcap.read(image)) {
std::cout << "No frame" << std::endl;
cv::waitKey();
}
cv::imshow("Output Window", image);
if(cv::waitKey(1) >= 0) break;
}
}
This code does cannot open the stream...
The code is based on some code in this thread: OpenCV with Network Cameras
The OpenCV 1 code here works without any problem for me.
Thank you very much in advance
I tried to create a new project with Visual Studio 2010 and OpenCV 2.2, instead of OpenCV 2.3.1.
This solved all my problems!

Resources