Error In OpenCv - 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.

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?

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.

Can't open video by OpenCv ErrorUnhandled exception at 0x7695c41f in moving movie.exe:

I write a very simple program to test to open a video by openCV, but I fail.
Here is the code.
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv ;
void main( void) {
namedWindow( "Example3", WINDOW_AUTOSIZE );
VideoCapture cap;
cap.open( "D:\a.mp4" );
cv::Mat frame;
while( 1 ) {
cap >> frame;
//cap.read(frame);
if( !frame.data ) break;
cv::imshow( "Example3", frame );
waitKey(33);
}
}
It just flash the windows, However, if I comment the if( !frame.data ) break;
I will get this:
Unhandled exception at 0x7695c41f in moving movie.exe: Microsoft C++ exception: cv::Exception at memory location 0x0045f968..
Any idea?
cap.open( "D:\a.mp4" ); should be:
cap.open( "D:\\a.mp4" );
Try to put your video in the "current directory" so that you can give the path simply as cap.open( "a.mp4" );.
So, your program should look like following:
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv ;
void main( void)
{
namedWindow( "Example3", WINDOW_AUTOSIZE );
VideoCapture cap;
cap.open( "a.mp4" );
cv::Mat frame;
while( 1 )
{
cap >> frame;
//cap.read(frame);
if( !frame.data ) break;
cv::imshow( "Example3", frame );
waitKey(33);
}
}
PS: I think the way you are giving path for video is also wrong, it should be forward slash / not backward which you are using i.e. \

cv.h: file not found 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.

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