I have old project, where I did something like this:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
(...)
CvCapture* capture;
cv::Mat frame;
capture = cvCaptureFromCAM(0);
frame = cvQueryFrame(capture);
(...)
And it worked.
Now I have created new project and now I have error:
error C2440: '=' : cannot convert from 'IplImage *' to 'cv::Mat *'
Only difference between these projects I notice is that the new one is written in CLR C++. Both use openCV 2.4.11.
Why cvQueryFrame() in my old project was able to return cv::Mat and new one doesnt? What did I missed?
I'm using Code::Blocks with the library OpenCV
I wrote the following code
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace cv;
using namespace std;
int main(int argc)
{
src = imread( argc[1], 1 );
cout << "Hello world!" << endl;
return 0;
}
When I run the code the following window appear
what is the solution to the problem :(
You have to add the correct libraries: Howto use libraries with Code::Blocks
I am aware my question is similar to:
OpenCV 2.0 C++ API using imshow: returns unhandled exception and "bad-flag"
Though I hv tried all the suggested and verified solutions from this page as well as other related pages, I still face the same problem of corrupted window names. Here is my code:
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
#include <math.h>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include"ip.h"
#include"histogram.h"
#include <opencv2\highgui\highgui.hpp>
#include "opencv2/core/core.hpp"
using namespace cv;
using namespace std;
void main()
{
IplImage *img01 = cvLoadImage("E:\liberty.jpg",CV_LOAD_IMAGE_GRAYSCALE);
cv::Mat img1(img01, false);
cv::namedWindow("Image 1");
cv::imshow("Image 1",img1);
cv::waitKey(0);
cv::destroyWindow("Image 1");
}
What should i do?Please help.
Is your image loading to img01?
Try changing '\' to'/' in IplImage *img01 = cvLoadImage("E:\liberty.jpg",CV_LOAD_IMAGE_GRAYSCALE);
I have a problem, in ROS I process a camera feed with openCv.
Now i try to implement the cvKalman, but this type is not recognized, however the opencv example works well.
What am i missing, why is not recognized this type?
here is my include to the ROS node:
#include <ros/ros.h>
#include <math.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
// for img processing
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv/cv.h>
Try including with "s not <s such as:
#include "ros/ros.h"
I solves the problem by using the KalmanFilter wrapper class, but still I dont understand why I cant use the simple Kalman class.
I am working on detecting edges and finding quadrilateral shapes on image using opencv 2.4.2 libraries. Everthing was going smooth, until I got these compilation errors
../src/GoodFeaturesToDetect.cpp:198:109: error: ‘cvFindContours’ was not declared in this scope
../src/GoodFeaturesToDetect.cpp:203:106: error: ‘cvContourPerimeter’ was not declared in this scope
../src/GoodFeaturesToDetect.cpp:203:114: error: ‘cvApproxPoly’ was not declared in this scope
../src/GoodFeaturesToDetect.cpp:206:64: error: ‘cvContourArea’ was not declared in this scope
Here are my headers:
#include <opencv2/core/core.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace cv;
using namespace std;
void DrawLine( Mat img, Point start, Point end );
vector<Point2f> FindCornersUsingGoodFeaturesToTrack(Mat toTrack);
void ConnectPointsWithLine(Mat img,vector<Point2f> corners);
void DrawQuad(Mat img, Point a, Point b, Point c, Point d);
void DetectAndDrawQuads(Mat img);
Here is the method that calls the function(s)
void DetectAndDrawQuads(Mat img){
CvSeq* contours;
CvSeq* result;
CvMemStorage *storage=cvCreateMemStorage(0);
Mat gray;
cvtColor(img,gray,CV_BGR2GRAY);
cvFindContours(&gray,storage, &contours, sizeof(CvContour),CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE, Point(0,0));
//Loop through all the contours discovered
//Figure out which ones form a quad
while(contours){
result=cvApproxPoly(contours, sizeof(CvContour),storage, CV_POLY_APPROX_DP,cvContourPerimeter(contours)*0.02,0);
if(result->total=4 && fabs(cvContourArea(result, CV_WHOLE_SEQ)) > 20){
CvPoint *pt[4];
for(int i=0; i<4; i++)
pt[i]=(CvPoint*) cvGetSeqElem(result,i);
DrawQuad(gray,*pt[0],*pt[1],*pt[2],*pt[3]);
}
contours = contours->h_next;
}
}
DetectAndDrawQuads gets called from main()..
Here are the linked libraries
opencv_contrib opencv_flann opencv_legacy opencv_calib3d opencv_ml opencv_imgproc opencv_highgui opencv_objdetect opencv_core opencv_features2d
I am working on Eclipse CDT (Helois)
I would appreciate any hint. Thanks.
First, your should use #include <> for opencv headers (like your first line, in contrast to second and third lines).
Methods that start with cv like cvFindContours are from older opencv C interface and are separate from the newer C++ ones. for example cvFindContour is defined in opencv2/imgproc/imgproc_c.h and not in opencv2/imgproc/imgproc.hpp (note the _c.h part).
On a side note you've included stdlib.h twice.
It turns out that the methods I was calling are from openCv 2.0. I had to change cvFindContours to findContours(...), cvApproxPoly to approxPolyDP and so on as described in OpenCV 2.4.2.