Vote count:
0
I'm getting error on my source, and can't find the reason.
Debug Assertion Failed! File : f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c Line : 1322 Expression : _CrtIsValidHeapPointer(pUserData)
Looks like this is kind of memory error, but I don't know why this is happening. I made a source very similar to source in here. http://ift.tt/1pY7hM2
int main()
{
int n;
cout << "numbers of images : ";
cin >> n;
char file_input[30][256] = {0,}, file_output[30][256] = {0,};
Mat img[30];
Mat img_output[30];
for(int i=0; i<n+1; i++) // file name
{
sprintf(file_input[i], "d%d.jpg", i+1);
sprintf(file_output[i], "OUTPUT%d.jpg", i);
img[i] = imread(file_input[i], CV_LOAD_IMAGE_GRAYSCALE);
}
int minHessian = 400;
SurfFeatureDetector detector(minHessian);
vector<KeyPoint> keypoints_object;
vector<KeyPoint> keypoints_scene;
detector.detect(img[0], keypoints_object);
SurfDescriptorExtractor extractor;
Mat descriptors_object;
Mat descriptors_scene;
extractor.compute(img[0], keypoints_object, descriptors_object);
FlannBasedMatcher matcher;
vector<DMatch> matches;
vector<DMatch> good_matches;
for(int i=1; i<n; i++)
{
keypoints_scene.clear();
matches.clear();
good_matches.clear();
detector.detect(img[i], keypoints_scene);
extractor.compute(img[i], keypoints_scene, descriptors_scene);
matcher.match(descriptors_object, descriptors_scene, matches);
double max_dist = 0;
double min_dist = 100;
for(int j=0; j<descriptors_object.rows; j++)
{
double dist = matches[j].distance;
if(dist < min_dist) min_dist = dist;
if(dist > max_dist) max_dist = dist;
}
for(int j=0; j<descriptors_object.rows; j++)
{
if(matches[j].distance < 3*min_dist)
good_matches.push_back(matches[j]);
}
vector<Point2f> obj;
obj.clear();
vector<Point2f> scene;
scene.clear();
for(int j=0; j<good_matches.size(); j++)
{
obj.push_back(keypoints_object[good_matches[i].queryIdx].pt);
scene.push_back(keypoints_scene[good_matches[i].trainIdx].pt);
}
Mat H = findHomography(obj, scene, CV_RANSAC);
warpPerspective(img[i], img_output[i], H, Size(img[0].cols, img[0].rows));
imwrite(file_output[i], img_output[i]);
}
return 0;
}
My input is file "d1.jpg", "d2.jpg", "d3.jpg" and n=3. those pictures are photo of same paper, but is taken on little different angle (within 5 degrees?).
I want to match the images "d2.jpg" and "d3.jpg" on "d1.jpg" exactly, so I used warpPerspective to do so. but the problem occurs, and also the output image is nothing but GRAY, which is NOT what I expected.
Please help. (I apologize for bad English and bad explanation)
Aucun commentaire:
Enregistrer un commentaire