cv::exception 内存位置错误
cv::exception error at memory location
我的项目已经很大,因为它正在从另一个项目中使用,所以我无法添加整个代码。
我正在使用 Visual Studios 2015、OpenCV-3.1.0 和 OpenNI2。
通过调试,我已经能够找到导致此处显示的错误的确切行:
此错误发生在以下代码行:
cvRectangle(&img_8bit, (pt1.x,pt1.y), (pt2.x,pt2.y), CV_RGB(255, 255, 255), -1);
下图显示在该行执行前,每个变量中都有数据,还显示了每个变量的数据类型:
我查看了此论坛上出现的其他一些关于类似问题的帖子,但未能找到适合我的情况的解决方案。
我已经尝试通过将其拆分为 x 和 y 变量而不是仅仅说 pt1 和 pt2 来更改输入两个点的方式。
我也试过改变输入图片的方式,但没有成功。
谁能告诉我这个问题是与变量有关,还是与矩形函数有关,还是与其他问题有关?
-----编辑----------------
我已经能够用更少量的代码重新创建错误,以便可以显示所有内容。
请注意,如果 cvRectangle 行被注释掉,那么它将从存储的位置完美地显示所有图像。
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/videoio.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>
#include <iostream>
#include <sstream>
#include <Windows.h>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
int nFrame = 0;//Current is the first few frames
cv::Mat depthMap;
char m_hitKey = 0;
char image_name[100];
CvPoint pt1, pt2;
pt1.x = 31;
pt1.y = 89;
pt2.x = 96;
pt2.y = 119;
for (int filenum = 0; filenum< 2276; filenum++)
{
++nFrame;//This is the first record at a few frames
std::sprintf(image_name, "%s%d%s", "C:\Users\James Mallett\Dep\dep-", filenum, ".png");
depthMap = cv::imread(image_name, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH);
if (m_hitKey = cv::waitKey(50))//Analyzing Key
{
if (m_hitKey == 27)
{
break;
}
}
cvRectangle(&depthMap, pt1, pt2, CV_RGB(255, 255, 255), -1);
cv::imshow("RGB", depthMap);
}
cv::destroyAllWindows();
return 0;
}
在你的例子中:
cvRectangle(&depthMap, pt1, pt2, CV_RGB(255, 255, 255), -1);
这看起来非常错误,因为 the signature I found online(yes, this is documentation of an earlier version, but this hasn't changed.) 是 ...
void cvRectangle(CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness=1, int line_type=8, int shift=0 )
... 并且 depthMap
属于 cv:Mat
类型。像这样使用名为 cv:rectangle
的匹配签名调用 C++ 函数 ...
cv:rectangle(depthMap, pt1, pt2, CV_RGB(255, 255, 255), -1);
...会更有意义。
CvArr
是 - according to the docs - a "meta type" (what a stupid choice of an API, IMO), thus it may point to any of plImage*
, CvMat*
or even CvSeq*
. Note that cv:Mat
is not in that list. I found a question on this site detailing how to convert between these 类型。
我的项目已经很大,因为它正在从另一个项目中使用,所以我无法添加整个代码。 我正在使用 Visual Studios 2015、OpenCV-3.1.0 和 OpenNI2。
通过调试,我已经能够找到导致此处显示的错误的确切行:
此错误发生在以下代码行:
cvRectangle(&img_8bit, (pt1.x,pt1.y), (pt2.x,pt2.y), CV_RGB(255, 255, 255), -1);
下图显示在该行执行前,每个变量中都有数据,还显示了每个变量的数据类型:
我查看了此论坛上出现的其他一些关于类似问题的帖子,但未能找到适合我的情况的解决方案。
我已经尝试通过将其拆分为 x 和 y 变量而不是仅仅说 pt1 和 pt2 来更改输入两个点的方式。 我也试过改变输入图片的方式,但没有成功。
谁能告诉我这个问题是与变量有关,还是与矩形函数有关,还是与其他问题有关?
-----编辑---------------- 我已经能够用更少量的代码重新创建错误,以便可以显示所有内容。 请注意,如果 cvRectangle 行被注释掉,那么它将从存储的位置完美地显示所有图像。
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/videoio.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>
#include <iostream>
#include <sstream>
#include <Windows.h>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
int nFrame = 0;//Current is the first few frames
cv::Mat depthMap;
char m_hitKey = 0;
char image_name[100];
CvPoint pt1, pt2;
pt1.x = 31;
pt1.y = 89;
pt2.x = 96;
pt2.y = 119;
for (int filenum = 0; filenum< 2276; filenum++)
{
++nFrame;//This is the first record at a few frames
std::sprintf(image_name, "%s%d%s", "C:\Users\James Mallett\Dep\dep-", filenum, ".png");
depthMap = cv::imread(image_name, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH);
if (m_hitKey = cv::waitKey(50))//Analyzing Key
{
if (m_hitKey == 27)
{
break;
}
}
cvRectangle(&depthMap, pt1, pt2, CV_RGB(255, 255, 255), -1);
cv::imshow("RGB", depthMap);
}
cv::destroyAllWindows();
return 0;
}
在你的例子中:
cvRectangle(&depthMap, pt1, pt2, CV_RGB(255, 255, 255), -1);
这看起来非常错误,因为 the signature I found online(yes, this is documentation of an earlier version, but this hasn't changed.) 是 ...
void cvRectangle(CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness=1, int line_type=8, int shift=0 )
... 并且 depthMap
属于 cv:Mat
类型。像这样使用名为 cv:rectangle
的匹配签名调用 C++ 函数 ...
cv:rectangle(depthMap, pt1, pt2, CV_RGB(255, 255, 255), -1);
...会更有意义。
CvArr
是 - according to the docs - a "meta type" (what a stupid choice of an API, IMO), thus it may point to any of plImage*
, CvMat*
or even CvSeq*
. Note that cv:Mat
is not in that list. I found a question on this site detailing how to convert between these 类型。