I have this nasty problem with opencv 2.4.2.
I use VS 2012 to compile this short test programm.
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
using namespace cv;
int main()
{
Mat sudoku = imread("sudoku.jpg",0);
namedWindow("Lines", CV_WINDOW_AUTOSIZE);
imshow("Lines", sudoku);
}
Imshow is the problem. When I remove it, it runs without any problem. I found a tip here which said to use debug libs instead but it didn't help.
First of all, you have to check if image is loaded correctly. To do this just check if image.data is NULL or not.
Secondly, after calling imshow you have to call waitKey to show image:
http://opencv.willowgarage.com/documentation/cpp/user_interface.html#cv-waitkey
Here's the whole code:
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat sudoku = imread("sudoku.jpg",0);
if (sudoku.data == NULL)
{
cout << "No image found! Check path." << endl;
return 1;//ERROR
}
else
{
namedWindow("Lines", CV_WINDOW_AUTOSIZE);
imshow("Lines", sudoku);
waitKey();//without this image won't be shown
return 0;//OK
}
}
Related
I am using darknet to detect objects from live video stream and want to pass each frame to dlib for tracking that object but i'm confused that how i pass frames from darknet's demo.c to dlib and do the tracking.
Do i need to use c c++ connector ? if yes, how? any explanation or clues would be helpful.
thanks...
Dlib file where i want to pass ipl image and want to track the object.
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <dlib/dir_nav.h>
#include "dlib/opencv.h"
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace dlib;
using namespace std;
extern "C"{
int enx = 203, int eny = 190, int enw = 98, int enh = 86;
void track(IplImage * ipl, int enx, int eny, int enw, int enh)
{
Mat frame = cvarrToMat(ipl);
image_window win;
correlation_tracker tracker;
array2d<rgb_pixel> img;
std::cout << "Starting" << std::endl;
assign_image(img, cv_image<bgr_pixel>(frame));
tracker.start_track(img, centered_rect(point(enx, eny), enw, enh));
win.set_image(img);
win.clear_overlay();
win.add_overlay(tracker.get_position());
while(ipl) {
Mat frame = cvarrToMat(ipl);
assign_image(img, cv_image<bgr_pixel>(frame));
tracker.update(img);
win.set_image(img);
win.clear_overlay();
win.add_overlay(tracker.get_position());
}
}
}
I would recommend you to look at https://github.com/AlexeyAB/darknet/blob/master/src/yolo_console_dll.cpp
where you will find many ideas about darknet data manipulation. Including tracker
I am training out the tutorial in opencv.
it had no error when compile.
I know the code for the tutorial is for opencv2.4 and I had change the coding for cvquery and videoframe.
My output is like this
.
My webcam is working fine but it not showing anything in my result.
If you wish to perform face detection using HaarCascades, you can use this code:
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
CascadeClassifier facecascade;
int main()
{
Mat frame;
facecascade.load("haarcascade_frontalface_alt.xml");
if(facecascade.empty())
{
cout<<"Error";
}
VideoCapture cap(0);
int i=0,j=0,k=0;
while(1)
{
cap>>frame;
Mat frame_gray;
cvtColor(frame,frame_gray,CV_BGR2GRAY);
vector<Rect>faces;
facecascade.detectMultiScale(frame_gray,faces,1.1,2,0|CV_HAAR_SCALE_IMAGE,Size(70,70));
if(faces.size()>0)
{
for(i=0;i<faces.size();i++)
{
rectangle(frame_gray,faces[i],Scalar(200,200,250),2,8,0);
}
char no[5];
sprintf(no,"No. of faces detected = %d",int(faces.size()));
putText(frame_gray,no,Point(10,30),FONT_HERSHEY_TRIPLEX,1,Scalar(255,255,255),1);
imshow("out",frame_gray);
char c= waitKey(5);
if(c=='b')
break;
}
return 0;
}
All my OpenCV functions are working perfectly fine. But cvResize() is not found by the compiler. I guess this function is not installed during installation.
The following program tells me the error that cvResize identifier is undefined
Is it possible to download this function separately and use it? How?
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <ctype.h>
#include <iostream>
using namespace std;
int main( int argc, char** argv )
{
// Create an IplImage object *image
IplImage *source = cvLoadImage( argv[1]);
// Here we retrieve a percentage value to a integer
int percent = atoi(argv[3]);
// declare a destination IplImage object with correct size, depth and channels
IplImage *destination = cvCreateImage
( cvSize((int)((source->width*percent)/100) , (int)((source->height*percent)/100) ), source->depth, source->nChannels );
//use cvResize to resize source to a destination image
cvResize(source, destination);
// save image with a name supplied with a second argument
cvSaveImage( argv[2], destination );
return 0;
}
You are missing an include:
#include "opencv2/imgproc/imgproc_c.h"
I fixed the error by
#import <opencv2/imgproc/imgproc_c.h>
I am using the following part code to get surf features plotted:
I am using the following part code to get surf features plotted:
#include<iostream>
using namespace std;
#include<vector>
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/features2d/features2d.hpp"
using namespace cv;
int main(int argc,char** argv)
{
VideoCapture vid(0);
if (!vid.isOpened())
{
cout<<"Camera not present..Halting the system";
return -1;
}
namedWindow("Camera_Inp",1);
namedWindow("Surfout",1);
Mat camcap,surfimg;
Mat grayimg;
SurfFeatureDetector featureimg(1000);
vector<KeyPoint>keypoints;
while(vid.isOpened()==true)
{
vid>>camcap;
imshow("Camera_Inp",camcap);
cvtColor(camcap,grayimg,CV_RGB2GRAY);
featureimg.detect(grayimg,keypoints);
drawKeypoints(grayimg,keypoints,surfimg,Scalar(255,255,255),0);
imshow("Surfout",surfimg);
if (waitKey(30)>=0)return -1;
}
return -1;
}
Visual Studio gives me the following error:
Stack around the variable 'keypoints' was corrupted.
The visual Studio debugger gives the error that:
Stack around the variable 'keypoints' was corrupted
Any help!!
I am using Background Subtraction and want to display the contents. Somehow the code seems to break all the time due to a memory exception. The error seems to be in cvCopy function. Can't figure it out.
#include "cv.h"
#include "highgui.h"
#include "opencv2\core\operations.hpp"
#include "opencv2\core\core.hpp"
#include "opencv2\core\types_c.h"
#include "opencv\cxcore.h"
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(int, char**)
{
bool flag=0;
VideoCapture cap(0); // open the default camera
VideoCapture cap1(0);
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat gray,bg,result,frame,result1,final,frame1;
//CvMemStorage* contours = NULL;
cap>>frame;
cvtColor(frame,bg,CV_BGR2GRAY);
namedWindow("GRAY",1);
for(;;)
{
//final = Mat::zeros(mGreenScale.rows, mGreenScale.cols, CV_8UC3);
cap >> frame; // get a new frame from camera
cap1 >> frame1;
cvtColor(frame, gray, CV_BGR2GRAY);
absdiff(gray,bg,result);
threshold(result,result1,50,255,THRESH_BINARY);
//cvCopy(const CvArr* src, CvArr* dst, const CvArr* mask=NULL)ΒΆ
//cvCopy(&frame1, &final, &result1);
//findContours(result1,contours, ;CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
//drawContours(final,contours,-1,CV_RGB(0,255,0));
//imshow("GRAY",result1);
//imshow("GRAY", result);
imshow("GRAY1",final);
if(flag)
{
imshow("BG",bg);
}
//if(waitKey(0)==27) break;
if(waitKey(1)==32)
{
cvtColor(frame,bg,CV_BGR2GRAY);
flag=!flag;
}
if(waitKey(1)==27)
{
break;
}
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
Instead of mixing the C and C++ APIs I would recommend you stick to the C++ API where possible. If you merely want to copy a matrix, just use either Mat::clone() or Mat::copyTo(). Since you want to use a mask, use the copyTo member function like this:
Mat final;
frame1.copyTo(final, result1);
Hope that helps!