I am new to opencv. While building the basic code, I am getting this error:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <cv.h>
#include <highgui.h>
using namespace cv;
int main()
{
Mat image;// new blank image
image = cv::imread("test.png", 0);// read the file
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;
}
Error: c:\mingw\bin..\lib\gcc\mingw32\4.8.1......\crt2.0 --- Undefined reference to '_setargv'
Please help me.
Related
Hi I am trying to run a simple OpenCV program to detect contours in a picture. however, findcontours keeps throwing exceptions.
here is my code:
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <opencv2\opencv.hpp>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
/** #function main */
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <math.h>
#include <string.h>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, const char * argv[]) {
IplImage* img = cvLoadImage("C:\\Users\\310217955\\Documents\\Visual Studio 2010\\Projects\\aviTest\\Debug\\Pictures\\Capture.jpg");
cv::Mat image = cv::cvarrToMat(img);
if (!image.data) {
std::cout << "Image file not found\n";
return 1;
}
//Prepare the image for findContours
cv::cvtColor(image, image, CV_BGR2GRAY);
cv::threshold(image, image, 128, 255, CV_THRESH_BINARY);
//Find the contours. Use the contourOutput Mat so the original image doesn't get overwritten
//std::vector<std::vector<cv::Point> > contours;
vector<cv::Mat> contours;
cv::Mat contourOutput = image.clone();
cv::findContours( contourOutput, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE );
//Draw the contours
cv::Mat contourImage(image.size(), CV_8UC3, cv::Scalar(0,0,0));
cv::Scalar colors[3];
colors[0] = cv::Scalar(255, 0, 0);
colors[1] = cv::Scalar(0, 255, 0);
colors[2] = cv::Scalar(0, 0, 255);
for (size_t idx = 0; idx < contours.size(); idx++) {
cv::drawContours(contourImage, contours, idx, colors[idx % 3]);
}
cv::imshow("Input Image", image);
cvMoveWindow("Input Image", 0, 0);
cv::imshow("Contours", contourImage);
cvMoveWindow("Contours", 200, 0);
cv::waitKey(0);
system("PAUSE");
return 0;
}
here is an image of the exception:
how can I get around this? is there a dll file im missing or some settings i need to resolve?
I did the following changes to the code
vector<Vec4i> hierarchy;
findContours( contourOutput, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE);
but now I get the following exception:
Well your code works perfectly fine.I only commented out the header files stdafx.h and nonfree.hpp in my project file . This is the output i gotenter image description here
Make sure you providing the correct path to the input img or paste your input image in your visual studio solution directory and just load the image directly.
The problem may be with one of the modules. I would suggest reinstalling opencv(try downloading the latest version) and try again. Make sure you are adding xyzd.lib files like opencv_highgui330d.lib opencv_imgproc330d.lib
in linker>>Input>> additional dependencies. the version might differ for you.
Hope this helps you!
I have a simple code,but it confuse me one day
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
void example2_4(IplImage* image)
{
cvNamedWindow("Example2_4-in", CV_WINDOW_AUTOSIZE);
cvNamedWindow("Example2_4-out", CV_WINDOW_AUTOSIZE);
cvShowImage("Example2_4-in", image);
IplImage* out = cvCreateImage(
cvGetSize(image),
IPL_DEPTH_8U,
3
);
cvSmooth(image, out, CV_GAUSSIAN, 5, 5);
cvSmooth(out, out, CV_GAUSSIAN, 5, 5);
cvShowImage("Example2_4-out", out);
cvReleaseImage(&out);
cvWaitKey(0);
cvDestroyWindow("Example2_4-in");
cvDestroyWindow("Example2_4-out");
}
int main()
{
IplImage* img = cvLoadImage("lena.png");//This is my current image,you can use yourself's to test
cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE);
cvShowImage("Example1", img);
example2_4(img);
cvReleaseImage(&img);
cvDestroyWindow("Example1");
}
It always give a error information like the follow image
Could I know which sentence call the "logger.h" file and result that
error?
How to avoid such error?
I'm trying to run the following code and convert the RGB image to YCbCr color model. But when building this code segment it gives the above error. I have attached a screenshot. Can you refer that and give me a solution.
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "iostream"
#include "opencv2/opencv.hpp"
using namespace cv;
using namespace cv2;
using namespace std;
int main()
{
Mat src1;
src1 = imread("face.jpg", CV_LOAD_IMAGE_COLOR);
namedWindow("Original image", CV_WINDOW_AUTOSIZE);
imshow("Original image", src1);
Mat gray, edge, draw;
//cvtColor(src1, gray, CV_BGR2GRAY);
Mat imgYCC = cv2.cvtColor(src1, cv2.COLOR_BGR2YCR_CB);
//equalizeHist(gray, draw);
//Canny(gray, edge, 50, 255, 3);
edge.convertTo(draw, CV_8U);
namedWindow("image", CV_WINDOW_AUTOSIZE);
imshow("image", imgYCC);
waitKey(0);
return 0;
}
The namespace cv2 doesn't exists. It's the name of the python wrapper.
Just remove the line:
using namespace cv2;
and don't use it in your code, e.g.:
Mat imgYCC = cvtColor(src1, COLOR_BGR2YCR_CB);
why the following errors occur when i try to implement dct in opencv?
Assertion failed (type == CV_32FC1 || type == CV_64FC1) in dct,
here is the code:
#include <cv.h>
#include "opencv2/imgproc/imgproc.hpp"
#include <highgui.h>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat image,dimage(image);
image = imread( "lena.jpg", 1 );
if( !image.data )
{
printf( "No image data \n" );
return -1;
}
namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
imshow( "Display Image", image );
dimage=Mat::zeros(image.rows,image.cols,CV_32F);
dct(image, dimage, DCT_INVERSE == 0 );
namedWindow( "DCT Image", CV_WINDOW_AUTOSIZE );
imshow( "DCT image", dimage );
waitKey(0);
return 0;
}
you have to convert your image from uchar to float first (and maybe back to uchar later):
// also please use the c++ headers, not the old c-ones !
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
Mat image = imread( "lena.jpg", 0 ); // grayscale
Mat fimage;
image.convertTo(fimage, CV_32F, 1.0/255); // also scale to [0..1] range (not mandatory)
// you're lucky with lena (512x512), for odd sizes, you have to
// pad it to pow2 size, or use dft() instead:
Mat dimage;
dct( fimage, dimage );
// process dimage,
// then same way back:
dct( dimage, dimage, DCT_INVERSE );
dimage.convertTo(image, CV_8U); // maybe scale back to [0..255] range (depending on your processing)
imshow("result",image);
waitKey();
I am trying to capture a video and store it in a file and then read the same video file. I am able to write it but not able to read the same file. On pressing escape, the program is supposed to quit the webcam and play the recorded video but displays the following error instead:
mpeg1video # 0x2a16f40] ac-tex damaged at 14 28
[mpeg1video # 0x2a16f40] Warning MVs not available
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /home/ujjwal/Downloads/OpenCV-2.4.0/modules/core/src/array.cpp, line 2482
terminate called after throwing an instance of 'cv::Exception'
what(): /home/ujjwal/Downloads/OpenCV-2.4.0/modules/core/src/array.cpp:2482: error: (-206) Unrecognized or unsupported array type in function cvGetMat
The code is:
#include <sstream>
#include <string>
#include <iostream>
#include <opencv/highgui.h>
#include <opencv/cv.h>
using namespace cv;
int main(int argc, char* argv[])
{
Mat inputVideo;
Mat frame;
Mat HSV;
Mat tracking;
char checkKey;
VideoCapture capture;
capture.open(0);
capture.set(CV_CAP_PROP_FRAME_WIDTH, 640);
capture.set(CV_CAP_PROP_FRAME_HEIGHT,480);
VideoWriter writer("OutputFile.mpeg", CV_FOURCC('P','I','M','1'), 50, Size(640, 480));
while(1){
capture.read(inputVideo);
imshow("Original Video",inputVideo);
writer.write(inputVideo);
checkKey = cvWaitKey(20);
if(checkKey == 27)
break;
}
capture.open("OutputFile.mpeg");
capture.set(CV_CAP_PROP_FRAME_WIDTH, 640);
capture.set(CV_CAP_PROP_FRAME_HEIGHT,480);
while(1){
capture.read(inputVideo);
imshow("Tracking Video", inputVideo);
}
return 0;
}
Can someone please help me? Thanks!
You need to correct several things to make it work:
You have to create the window before showing images in the window.
You have to close the writer to finish writing before open it later.
You need to add cvWaitKey(20) for the second image showing (check out here for why this is essential).
The whole fixed code is as follows:
#include <sstream>
#include <string>
#include <iostream>
#include <opencv/highgui.h>
#include <opencv/cv.h>
using namespace cv;
int main(int argc, char* argv[])
{
Mat inputVideo;
Mat frame;
Mat HSV;
Mat tracking;
char checkKey;
VideoCapture capture;
capture.open(0);
capture.set(CV_CAP_PROP_FRAME_WIDTH, 640);
capture.set(CV_CAP_PROP_FRAME_HEIGHT,480);
VideoWriter writer("OutputFile.mpeg", CV_FOURCC('P','I','M','1'), 50, Size(640, 480));
namedWindow("Original Video", WINDOW_AUTOSIZE );
while(1){
capture.read(inputVideo);
imshow("Original Video",inputVideo);
writer.write(inputVideo);
checkKey = cvWaitKey(20);
if(checkKey == 27)
break;
}
writer.release();
capture.open("OutputFile.mpeg");
capture.set(CV_CAP_PROP_FRAME_WIDTH, 640);
capture.set(CV_CAP_PROP_FRAME_HEIGHT,480);
namedWindow("Tracking Video", WINDOW_AUTOSIZE );
while(1){
capture.read(inputVideo);
if (!inputVideo.empty())
{
imshow("Tracking Video", inputVideo);
checkKey = cvWaitKey(20);
}
else
break;
}
return 0;
}