Hello! I have a problem with OpenCV function cvCvtColor. Here is the code I used:
#include "cv.h"
#include "highgui.h"
int main(void)
{
int g_thresh = 100;
CvCapture* capture = cvCreateCameraCapture(0);
IplImage* g_image = cvQueryFrame(capture);
IplImage* g_image_copy = cvCloneImage(g_image);
cvNamedWindow( "Contours", 1 );
cvShowImage( "Contours", g_image );
IplImage* g_gray = cvCreateImage( cvSize(g_image->width, g_image->height), g_image->depth, 1 );
cvCvtColor( g_image_copy, g_gray, CV_BGR2GRAY );
cvThreshold( g_gray, g_gray, g_thresh, 255, CV_THRESH_BINARY );
CvMemStorage* g_storage = cvCreateMemStorage(0);
CvSeq* contours = 0;
cvFindContours( g_gray, g_storage, &contours );
cvZero( g_gray );
if( contours ){
cvDrawContours(
g_gray,
contours,
cvScalarAll(255),
cvScalarAll(255),
100 );
}
cvShowImage( "Contours", g_gray );
cvWaitKey();
return 0;
}
It's "unhandled exception at "0x1002e4e4" in "opencvsample.exe": 0xC0000005: Access read violation "0xffffffff"." (maybe I make mistakes in translation, I have russian VS2008). It occurs at line
cvCvtColor( g_image_copy, g_gray, CV_BGR2GRAY );
What I need to do to solve problem?