Я разрабатываю простую оболочку C ++ / CLI для OpenCV для использования в моем приложении C#. Я имею в виду Соответствие шаблонов на основе Edge , но доступный код использует более старые библиотеки openCV (cv200.dll, cxcore200.dll, highgui200.dll).
Когда я реализую ту же программу, используя OpenCV3 (opencv_ffmpeg348_64.dll и другие), я получаю следующую ошибку в одной из строк:
Исключение выдается в 0x0000019972FBDB65 (opencv_world348.dll) в appname.exe: 0xC0000005: расположение чтения нарушения доступа 0x000001996DD8FFF8.
Вот моя функция:
int PatternMatching::FindPattern1(System::Drawing::Bitmap^ sourceImageB,
System::Drawing::Bitmap^ templateImageB,
int lowThreshold,
int highThreashold,
double minScore,
double greediness) {
cv::Point result;
cv::Mat sourceMat = KudammUtils::BitmapToMat(sourceImageB);
cv::Mat templateMat = KudammUtils::BitmapToMat(templateImageB);
IplImage* templateImage = new IplImage(templateMat);
IplImage* searchImage = new IplImage(sourceMat);
cv::imwrite("tmp.jpg", templateMat); // this works
cv::imwrite("sce.jpg", sourceMat); // this works as well
if (templateImage == NULL)
{
cout << "\nERROR: Could not load Template Image";
return 0;
}
if (searchImage == NULL)
{
cout << "\nERROR: Could not load Search Image";
return 0;
}
CvSize templateSize = cvSize(templateImage->width, templateImage->height);
IplImage* grayTemplateImg = cvCreateImage(templateSize, IPL_DEPTH_8U, 1);
cout << "\nhere0";
if (templateImage->nChannels == 3)
{
cvCvtColor(templateImage, grayTemplateImg, CV_RGB2GRAY);
}
else
{
cvCopy(templateImage, grayTemplateImg);
}
cout << "\nhere1";
if (!GM->CreateGeoMatchModel(grayTemplateImg, lowThreshold, highThreashold))
{
cout << "ERROR: could not create model...";
throw gcnew System::Exception("Could not create model");
}
cout << "\nhere2";
GM->DrawContours(templateImage, CV_RGB(255, 0, 0), 1);
cout << " Shape model created.."; // <- GETS PRINTED TILL HERE
CvSize searchSize = cvSize(searchImage->width, searchImage->height);
cout << "\nhere3"; // <- THIS DOESN'T GET PRINTED
IplImage* graySearchImg = cvCreateImage(searchSize, IPL_DEPTH_8U, 1);
cout << "\nhere4";
// Convert color image to gray image.
if (searchImage->nChannels == 3)
cvCvtColor(searchImage, graySearchImg, CV_RGB2GRAY);
else
{
cvCopy(searchImage, graySearchImg);
}
clock_t start_time1 = clock();
score = GM->FindGeoMatchModel(graySearchImg, minScore, greediness, &result);
clock_t finish_time1 = clock();
total_time = (double)(finish_time1 - start_time1) / CLOCKS_PER_SEC;
if (score > minScore) // if score is atleast 0.4
{
cout << " Found at [" << result.x << ", " << result.y << "]\n Score = " << score << "\n Searching Time = " << total_time * 1000 << "ms";
GM->DrawContours(searchImage, result, CV_RGB(0, 255, 0), 1);
}
else
cout << " Object Not found";
cv::Mat outputMat = cv::cvarrToMat(searchImage);
System::Drawing::Bitmap^ outputBitmap = KudammUtils::MatToBitmap(outputMat);
cvReleaseImage(&searchImage);
cvReleaseImage(&templateImage);
cvReleaseImage(&grayTemplateImg);
cvReleaseImage(&graySearchImg);
return 1;
}
Любая идея, что может быть причиной этой ошибки? Что я делаю не так?