SEHException in VS2010 with OpenCV 2.4.9 - Visual C++
Since it's my first post here: Hello Word! I'm having problem with my code for realtime stereovision. I'm getting "SEHException was unhandled" info when i'm trying to call cvFindStereoCorrespondenceBM function. The problem exists only when i'm trying to use pictures taken from camera (with tryb==1). When i'm calling same function with image files (tryb==0) taken by same cameras it works fine (aside having quite bad maps). Here is my code:
#pragma once
#include "stdafx.h"
inline void mystereoBM(CvStereoBMState *przeniesionyBM, int tryb, int * koniec, int camera1, int camera2, char *left_filename, char *right_filename, bool skalibrowany, bool * generuj)
{
CvMat * my1 = (CvMat*)cvLoad("Config\\my1.xml");
CvMat * mx2 = (CvMat*)cvLoad("Config\\mx2.xml");
CvMat * my2 = (CvMat*)cvLoad("Config\\my2.xml");
CvMat * mx1 = (CvMat*)cvLoad("Config\\mx1.xml");
IplImage* obraz;
IplImage* frame1=NULL;
IplImage* frame2=NULL;
CvCapture* cap1;
CvCapture* cap2;
IplImage* Temp1 = NULL; //TODO: wywalić
int aux;
uchar *ptr_dst;
CvStereoBMState *BMState;
IplImage *cv_image_left;
IplImage *cv_image_right;
CvMat *cv_image_depth;
IplImage *cv_image_depth_aux;
{
BMState = przeniesionyBM;
if (tryb==0)
{
cv_image_left = cvLoadImage(left_filename, 0);
cv_image_right = cvLoadImage(right_filename, 0);
if (!cv_image_left || !cv_image_right) return;
}
else if (tryb==1)
{
cap1 = cvCreateCameraCapture(camera1);
cap2 = cvCreateCameraCapture(camera2);
if (!cap1 || !cap2) return;
frame1 = cvQueryFrame( cap1 );
frame2 = cvQueryFrame( cap2 );
if (!frame1 || !frame2) return;
Temp1 = cvCreateImage(cvGetSize(frame1), frame1->depth, frame1->nChannels);
cv_image_left = cvCreateImage(cvGetSize(frame1), frame1->depth, frame1->nChannels);
cv_image_right = cvCreateImage(cvGetSize(frame2), frame2->depth, frame2->nChannels);
}
int norm_width = cv_image_left->width;
int norm_height = cv_image_left->height;
cv_image_depth = cvCreateMat ( cv_image_left->height, cv_image_left->width, CV_16S);
cv_image_depth_aux = cvCreateImage (cvGetSize(cv_image_left),IPL_DEPTH_8U, 3);
}
if ((tryb==0)&&(!skalibrowany))
{
cvRemap( cv_image_left, cv_image_left, mx1, my1 );
cvRemap( cv_image_right, cv_image_right, mx2, my2 );
}
while ( 1 ) {
if (*generuj)
{
if (tryb==1)
{
if (!cap1 || !cap2)
break;
frame1 = cvQueryFrame( cap1 );
frame2 = cvQueryFrame( cap2 );
if (!frame1 || !frame2)
break;
cvCopy(frame1 , cv_image_left, NULL);
cvCopy(frame2 , cv_image_right, NULL);
//cvSaveImage("Capture\\Kurwa.jpg",cv_image_left);
//cvSaveImage("Capture\\Kurwa1.jpg",cv_image_right);
//cvCvtColor(cv_image_left,cv_image_left,CV_BGR2GRAY);
//cvCvtColor(cv_image_right,cv_image_right,CV_BGR2GRAY);
if (!skalibrowany)
{
cvRemap( cv_image_left, cv_image_left, mx1, my1 );
cvRemap( cv_image_right, cv_image_right, mx2, my2 );
}
}
else
*generuj=false;
cvFindStereoCorrespondenceBM (
cv_image_left,
cv_image_right,
cv_image_depth,
BMState); // Problem is here
cvNormalize( cv_image_depth, cv_image_depth, 0, 256, CV_MINMAX, NULL );
for (int i = 0; i < cv_image_depth->rows; i++)
{
aux = cv_image_depth->cols * i;
ptr_dst = (uchar*)(cv_image_depth_aux->imageData + i*cv_image_depth_aux->widthStep);
for (int j = 0; j < cv_image_depth->cols; j++ )
{
ptr_dst[3*j] = (uchar)((short int*)(cv_image_depth->data.ptr + cv_image_depth->step*i))[j];
ptr_dst[3*j+1] = (uchar)((short int*)(cv_image_depth->data.ptr + cv_image_depth->step*i))[j];
ptr_dst[3*j+2] = (uchar)((short int*)(cv_image_depth->data.ptr + cv_image_depth->step*i))[j];
}
}
obraz = cv_image_depth_aux;
}
//cvShowImage( "Obraz L", cv_image_left );
//cvShowImage( "Obraz P", cv_image_right );
cvShowImage( "Dyspozycja", obraz);
if (( (cvWaitKey(10) & 255) == 27)||(*koniec==1) )
break;
}
cvSave( "Capture\\dyspozycja.pgm", obraz);
cvDestroyWindow("Dyspozycja");
//cvDestroyWindow("Obraz L");
//cvDestroyWindow("Obraz P");
if (tryb==1)
{
cvReleaseCapture(&cap1);
cvReleaseCapture(&cap2);
}
cvReleaseStereoBMState( &przeniesionyBM );
}
Problem isn't with cvFidStereoCorrespondenceBM alone, when i was trying to call cvCvtColor i've got same exception. I hope someone of you knows solution to my problem :)
you should avoid the old c-api in favour of c++