我想在opencv中实现一袋单词。检测器->检测(img,keypoint);检测关键点之后,当我想使用keypoint.clear()清除键点时;或者当函数想返回时,将出现以下错误。
“在0x011f45bb处未处理的异常( BOW.exe: 0xC0000005:访问冲突读取位置0x42ebe098.)”
并且检测到的关键点具有奇异的点坐标,如cv::Point_ pt{x=-1.5883997e+038y=-1.5883997e+038 }
代码的一部分
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("FlannBased");
Ptr<DescriptorExtractor> extractor = new SurfDescriptorExtractor();
Ptr<FeatureDetector> detector = new SurfFeatureDetector(2000);
void extractTrainingVocabulary() {
IplImage *img;
int i,j;
CvSeq *imageKeypoints = 0;
for(j=1;j<=60;j++)
for(i=1;i<=60;i++){
sprintf( ch,"%d%s%d%s",j," (",i,").jpg");
const char* imageName = ch;
Mat img = imread(ch);
vector<KeyPoint> keypoint;
detector->detect(img, keypoint);
Mat features;
extractor->compute(img, keypoint, features);
bowTrainer.add(features);
keypoint.clear();//problem
}
return;
}发布于 2011-08-14 02:36:59
我注意到关于您的代码,在extractTrainingVocabulary()上声明IplImage* img;,在循环中声明另一个变量,名称相同(但类型不同):Mat img = imread(ch);。
尽管这可能不是问题所在,但这肯定不是一个好的做法。我会立即修复这个问题,并更新你问题上的代码。
https://stackoverflow.com/questions/7050290
复制相似问题