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/
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 have this simple code to open an image but it shows blank image in the "Video" window. I have checked release and debug lib's to make sure. It is in release mode and the lib is release lib. The picture is there, and I also tried full path for the image but still doesn't work. Also tried different image formats: jpg, png, bmp. It is OpenCV 3.4.1 release, and VS 2017 (also tried 2015).
#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
namedWindow("Video");
Mat frame1 = imread("Penguins.bmp", CV_LOAD_IMAGE_COLOR );
imshow("Video", frame1);
system("Pause");
return 0;
}
Thanks in advance
You need to use the waitKey() function after imshow(). You can pass in a delay parameter to show the image for a certain time (in milliseconds).
Example:
#--- It will display the image for 30 ms
waitKey(30);
#--- It will display the image until a key is pressed
waitKey();
Check THIS PAGE for more.
There is also a demo example shown HERE
I am trying to read an image in mat form in opencv and display it.
the code compiles fine but when run gives runtime error and the image is not displayed.
here is my code:
#include "stdafx.h"
#include<cv.h>
#include<highgui.h>
#include<iostream>
using namespace cv;
using namespace std;
void main()
{
Mat Img;
Img=imread("C:/Documents and Settings/image1.jpg");
cvNamedWindow("Image",CV_WINDOW_AUTOSIZE);
imshow( "Image", Img );
cvWaitKey(0);
}
Could anyone please tell me where am I going wrong?
Most probably imread() is failing. You will know for certain unless you start checking the success of the functions, such an important thing to do when you code.
There's a couple of reasons why it might fail:
You don't have permission to access the file.
The path is wrong.
In your case, it's probably the first. So change your code to:
Mat Img;
Img = imread("C:\\Documents and Settings\\image1.jpg");
if (Img.empty()) {
std::cout << "!!! Failed to open the file\n";
return;
}
and notice how the path to file is different.
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.
These are includes which I am using
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc_c.h>
This is namespace
using namespace cv;
But when I am using matchTemplate function, I am catching the following problem
error C3861: 'matchTemplate': identifier not found
Can anyone help me to solve this problem?
Additional information:
I am using OpenCV2.3
thank you for spending time to view and comment my problem
Best Regards
Hayk
You need imgproc.hpp included, the one that you included has the C version only : cvMatchTemplate