OpenCV2.4.2将向量转换为Mat,并释放Mat会导致错误

OpenCV2.4.2将向量转换为Mat,并释放Mat会导致错误,opencv,mat,Opencv,Mat,我将向量改为Mat,因为出于某种原因,如果取向量,findHomography只生成零矩阵 下面是简短的代码 { std::vector<Point2f> img1; std::vector<Point2f> img2; Mat mat_from_img1 = Mat(img1,true); Mat mat_from_img2 = Mat(img2,true); Mat H = cv::findHomography(mat_from_img1,mat_from_img

我将向量改为Mat,因为出于某种原因,如果取向量,findHomography只生成零矩阵

下面是简短的代码

{
std::vector<Point2f> img1;
std::vector<Point2f> img2;
Mat mat_from_img1 = Mat(img1,true); 
Mat mat_from_img2 = Mat(img2,true); 
Mat H = cv::findHomography(mat_from_img1,mat_from_img2, CV_RANSAC);

//Do THINGS

}//as soons as getting out of this scope, 
//it calls ~MAT() then Mat::release and causes memory reading violation error.
如何正确地将矢量转换为mat以避免错误? 我试过了


Mat Mat_from_img1=Matimg1,真;或者

您不需要将这些向量转换为Mats。您可以直接将它们传递给-这需要一个输入阵列和一个

参见上的示例


检查img1和img2中的内容-根据您的代码,它们是空的

由于Mat Mat_from_img1=Matimg1,因此true复制它必须为其分配空间的数据。如果不释放数据,您将出现内存泄漏。内存读取冲突错误的代码是什么?传递Point2f向量是正确的方法-如果得到的结果不好,可能没有足够的好点。尝试使用CV_LMEDS而不是CV_RANSAC,看看这是否有什么不同。在您的代码片段中,您实际上并没有将任何点推入向量中,我假设这不是您实际要做的事情?将向量传递到findHomography是正确的方法,但我不知道如果我传递向量,它为什么会返回零矩阵。我必须使用矩阵来得到正确的H矩阵。我意识到当破坏mat H时,会导致内存冲突读取错误。哦,我发现了,这只是我的链接器问题。在发布模式中,我使用了调试模式库。