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?
Related
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include <stdlib.h>
#include "opencv2\highgui.hpp"
#include "opencv2\imgproc.hpp"
#include "opencv2\features2d.hpp"
#include "opencv2\core.hpp"
using namespace std;
using namespace cv;
int main()
{
Mat img = Mat::zeros(Size(60,60),CV_8UC1);
imwrite("test.bmp", img);
Mat img2 = imread("Screw.png");
namedWindow("image", WINDOW_NORMAL);
imshow("image", img);
imshow("img", img2);
waitKey(0);
return 0;
}
I am using Opencv 3.4.6 with visual studio 2015.
I am unable to read any image from system, have tried png and jpg image format.To make sure that image is in the right location I have also used imwrite function to save an blank image, which is working fine.
I have tried opencv 4.0.1 as well giving the same issue.
I think there might be some issue in configuration part. There are so many tutorials available for the configuration procedure. Try below link for the configuration and also
as #mark suggested replace your header file
https://www.youtube.com/watch?v=M-VHaLHC4XI
I am a beginner about OpenCV. I searched and tried to execute some basic OpenCV codes. When I tried running one of them, I got "R6010 -abort() has been called" error. I also tried to debug codes but this time on line 28 it gave me "Microsoft C++ exception: cv::Exception at memory location 0x000000A7F732F350." error.
// work5animage.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
#include "opencv2\core.hpp"
#include "opencv2\imgproc.hpp"
#include "opencv2\highgui.hpp"
using namespace cv;
int main( int argc, const char** argv )
{
// Read images
Mat color= imread("resized_love.jpg");
Mat gray= imread("resized_love.jpg", 0);
// Write images
imwrite("lenaGray.jpg", gray);
// Get same pixel with opencv function
int myRow=color.cols-1;
int myCol=color.rows-1;
Vec3b pixel= color.at<Vec3b>(myRow, myCol); //This is where I get the err.
cout << "Pixel value (B,G,R): (" << (int)pixel[0] << "," <<
(int)pixel[1] << "," << (int)pixel[2] << ")" << endl;
// show images
imshow("Lena BGR", color);
imshow("Lena Gray", gray);
// wait for any key press
waitKey(1000);
return 0;
}
I saw some relavant problems but I couldn't find a convenient answer for me. Thank you for help.
I would suppose jpg doesn't store in the plain 2D format like you want to access it. Convert it to bmp, read that in and try again.
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 have the following code, which runs fine:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/features2d/features2d.hpp>
using namespace std;
using namespace cv;
void main() {
bool running = true;
cv::OrbFeatureDetector OrbDetector;
while (running) {
IplImage *newFrame = cvLoadImage("x1.jpg");
IplImage *newFrameBW = cvCreateImage(cvGetSize(newFrame), newFrame->depth, 1);
cvConvertImage(newFrame, newFrameBW);
vector<KeyPoint> KeyPoints;
}
}
However, adding the line:
OrbDetector.detect(newFrameBW, KeyPoints);
to the while loop results in the following error:
HEAP[Example 4.exe]: Invalid address specified to RtlFreeHeap( 006B0000, 02474D20 )
Example 4.exe has triggered a breakpoint.
I am sure there is nothing wrong with the code, as I have just seen it run successfully on someone elses machine. Is there anything non code related that could be causing this?
The problem is that the OpenCV version you are using does not deal OK with MCVS 2012. Is not a problem of code, as I had a similar one that include vectors and didn't work.
Take a look to this tutorial that will show you how to rebuild the OpenCV library and your code will work pretty well ;)
Here is the link:
http://answers.opencv.org/question/6495/visual-studio-2012-and-rtlfreeheap-error/
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.