C++ testcamcalib.exe中0x01221316处未处理的异常:0xC0000005:访问冲突读取位置0x00cf6000
我正试图用两台摄像机来追踪线路。在进行精明的边缘检测之前,一切正常 在C++ testcamcalib.exe中0x01221316处未处理的异常:0xC0000005:访问冲突读取位置0x00cf6000,c++,visual-c++,C++,Visual C++,我正试图用两台摄像机来追踪线路。在进行精明的边缘检测之前,一切正常 在Canny之后,程序显示了一个内存位置错误,与我的标题中所述的相同: testcamcalib.exe中0x01221316处未处理的异常:0xC0000005:访问冲突读取位置0x00cf6000 指针指向: float rho = lines[i][0], theta = lines[i][1]; 这是我的代码: int main() { //initializing camera and allocate memory
Canny
之后,程序显示了一个内存位置错误,与我的标题中所述的相同:
testcamcalib.exe中0x01221316处未处理的异常:0xC0000005:访问冲突读取位置0x00cf6000
指针指向:
float rho = lines[i][0], theta = lines[i][1];
这是我的代码:
int main()
{
//initializing camera and allocate memory to load the video stream from camera
cv::VideoCapture camera0(1);
cv::VideoCapture camera1(0);
if( !camera0.isOpened() ) return 1;
if( !camera1.isOpened() ) return 1;
while(true) {
//capture and retrieve each frames of the video sequentially, one frame at time will be displayed
// capture from 1st camera
Mat edges0, edges1, dst0, dst1, cdst0, cdst1;
cv::Mat3b frame0;
camera0 >> frame0;
// Performing edge detection on camera 1
cvtColor(frame0, edges0, CV_BGR2GRAY);
GaussianBlur(edges0, edges0, Size(7,7), 1.5, 1.5);
Canny(edges0, dst0, 0, 30, 3);
vector<Vec2f> lines;
// detect lines
HoughLines(dst0, lines, 1, CV_PI/180, 150, 0, 0 );
// draw lines
for( size_t i = 0; i < lines.size(); i++ )
{
float rho = lines[i][0], theta = lines[i][1];
Point pt1, pt2;
double a = cos(theta), b = sin(theta);
double x0 = a*rho, y0 = b*rho;
pt1.x = cvRound(x0 + 1000*(-b));
pt1.y = cvRound(y0 + 1000*(a));
pt2.x = cvRound(x0 - 1000*(-b));
pt2.y = cvRound(y0 - 1000*(a));
line( cdst0, pt1, pt2, Scalar(0,0,255), 3, CV_AA);
}
//capturing frames from second camera
cv::Mat3b frame1;
camera1 >> frame1;
// performing edge detection on camera 2
cvtColor(frame1, edges1, CV_BGR2GRAY);
GaussianBlur(edges1, edges1, Size(7,7), 1.5, 1.5);
Canny(edges1, dst1, 0, 30, 3);
// detect lines
HoughLines(dst1, lines, 1, CV_PI/180, 150, 0, 0 );
// draw lines
for( size_t i = 0; i < lines.size(); i++ )
{
float rho = lines[i][0], theta = lines[i][1];
Point pt1, pt2;
double a = cos(theta), b = sin(theta);
double x0 = a*rho, y0 = b*rho;
pt1.x = cvRound(x0 + 1000*(-b));
pt1.y = cvRound(y0 + 1000*(a));
pt2.x = cvRound(x0 - 1000*(-b));
pt2.y = cvRound(y0 - 1000*(a));
line( cdst1, pt1, pt2, Scalar(0,0,255), 3, CV_AA);
}
cv::imshow("edges0", cdst0);
cv::imshow("edges1", cdst1);
//wait for 40 milliseconds
int c = cvWaitKey(30);
//exit the loop if user press "Esif(27 == char(c)) breakc" key (ASCII value of "Esc" is 27)
;
}
return 0;
}
intmain()
{
//初始化摄像机并分配内存以从摄像机加载视频流
cv::视频捕获摄像机0(1);
cv::视频捕获摄像机1(0);
如果(!camera0.isOpened())返回1;
如果(!camera1.isOpened())返回1;
while(true){
//按顺序捕获和检索视频的每一帧,每次显示一帧
//从第一台摄像机拍摄
垫边0、边1、dst0、dst1、cdst0、cdst1;
cv::Mat3b frame0;
camera0>>frame0;
//在照相机1上执行边缘检测
CVT颜色(框架0、边缘0、CV_BGr2灰色);
GaussianBlur(edges0,edges0,大小(7,7),1.5,1.5);
Canny(edges0、dst0、0、30、3);
矢量线;
//探测线
HoughLines(dst0,lines,1,CV_PI/180,150,0,0);
//划线
对于(size_t i=0;i>框架1;
//在摄像机2上执行边缘检测
CVT颜色(框架1、边缘1、CV_BGr2灰色);
GaussianBlur(边1,边1,大小(7,7),1.5,1.5);
Canny(edges1、dst1、0、30、3);
//探测线
HoughLines(dst1,lines,1,CV_PI/180,150,0,0);
//划线
对于(size_t i=0;i
您可以尝试调试代码。可能是行的第二维度有问题<代码>行[i][0]
或行[i][1]
可能无效。您可以将这两条语句放在单独的行中,并对其进行调试,以了解有关问题的更多信息