C++ 使用cvCretateImage()时出现Opencv未处理的异常
我有下面的代码。是一个开放的实时边缘检测,但我在第行有一个错误:C++ 使用cvCretateImage()时出现Opencv未处理的异常,c++,opencv,visual-studio-2013,C++,Opencv,Visual Studio 2013,我有下面的代码。是一个开放的实时边缘检测,但我在第行有一个错误:pProcessedFrame=cvCreateImage(cvSize(pFrame->width,pFrame->height),IPL_DEPTH_8U,1) “opencv2.exe中0x00007FF6CAF1284C处未处理的异常:0xC000005:访问冲突读取位置0x000000000000002C。” 谁能解决这个问题 我的配置是Visual Studio 2013和Opencv 2.4.10 #include
pProcessedFrame=cvCreateImage(cvSize(pFrame->width,pFrame->height),IPL_DEPTH_8U,1)代码>
“opencv2.exe中0x00007FF6CAF1284C处未处理的异常:0xC000005:访问冲突读取位置0x000000000000002C。”
谁能解决这个问题
我的配置是Visual Studio 2013和Opencv 2.4.10
#include <iostream>
#include "opencv/cv.h"
#include "opencv/highgui.h"
using namespace std;
// Define the IplImage pointers we're going to use as globals
IplImage* pFrame;
IplImage* pProcessedFrame;
IplImage* tempFrame;
// Slider for the low threshold value of our edge detection
int maxLowThreshold = 1024;
int lowSliderPosition = 150;
// Slider for the high threshold value of our edge detection
int maxHighThreshold = 1024;
int highSliderPosition = 250;
// Function to find the edges of a given IplImage object
IplImage* findEdges(IplImage* sourceFrame, double thelowThreshold, double theHighThreshold, double theAperture)
{
// Convert source frame to greyscale version (tempFrame has already been initialised to use greyscale colour settings)
cvCvtColor(sourceFrame, tempFrame, CV_RGB2GRAY);
// Perform canny edge finding on tempframe, and push the result back into itself!
cvCanny(tempFrame, tempFrame, thelowThreshold, theHighThreshold, theAperture);
// Pass back our now processed frame!
return tempFrame;
}
// Callback function to adjust the low threshold on slider movement
void onLowThresholdSlide(int theSliderValue)
{
lowSliderPosition = theSliderValue;
}
// Callback function to adjust the high threshold on slider movement
void onHighThresholdSlide(int theSliderValue)
{
highSliderPosition = theSliderValue;
}
int main(int argc, char** argv)
{
// Create two windows
cvNamedWindow("WebCam", CV_WINDOW_AUTOSIZE);
cvNamedWindow("Processed WebCam", CV_WINDOW_AUTOSIZE);
// Create the low threshold slider
// Format: Slider name, window name, reference to variable for slider, max value of slider, callback function
cvCreateTrackbar("Low Threshold", "Processed WebCam", &lowSliderPosition, maxLowThreshold, onLowThresholdSlide);
// Create the high threshold slider
cvCreateTrackbar("High Threshold", "Processed WebCam", &highSliderPosition, maxHighThreshold, onHighThresholdSlide);
// Create CvCapture object to grab data from the webcam
CvCapture* pCapture;
// Start capturing data from the webcam
pCapture = cvCaptureFromCAM(CV_CAP_V4L2);
// Display image properties
cout << "Width of frame: " << cvGetCaptureProperty(pCapture, CV_CAP_PROP_FRAME_WIDTH) << endl; // Width of the frames in the video stream
cout << "Height of frame: " << cvGetCaptureProperty(pCapture, CV_CAP_PROP_FRAME_HEIGHT) << endl; // Height of the frames in the video stream
cout << "Image brightness: " << cvGetCaptureProperty(pCapture, CV_CAP_PROP_BRIGHTNESS) << endl; // Brightness of the image (only for cameras)
cout << "Image contrast: " << cvGetCaptureProperty(pCapture, CV_CAP_PROP_CONTRAST) << endl; // Contrast of the image (only for cameras)
cout << "Image saturation: " << cvGetCaptureProperty(pCapture, CV_CAP_PROP_SATURATION) << endl; // Saturation of the image (only for cameras)
cout << "Image hue: " << cvGetCaptureProperty(pCapture, CV_CAP_PROP_HUE) << endl; // Hue of the image (only for cameras)
// Create an image from the frame capture
pFrame = cvQueryFrame(pCapture);
// Create a greyscale image which is the size of our captured image
pProcessedFrame = cvCreateImage(cvSize(pFrame->width, pFrame->height), IPL_DEPTH_8U, 1);
// Create a frame to use as our temporary copy of the current frame but in grayscale mode
tempFrame = cvCreateImage(cvSize(pFrame->width, pFrame->height), IPL_DEPTH_8U, 1);
// Loop controling vars
char keypress;
bool quit = false;
while (quit == false)
{
// Make an image from the raw capture data
// Note: cvQueryFrame is a combination of cvGrabFrame and cvRetrieveFrame
pFrame = cvQueryFrame(pCapture);
// Draw the original frame in our window
cvShowImage("WebCam", pFrame);
// Process the grame to find the edges
pProcessedFrame = findEdges(pFrame, lowSliderPosition, highSliderPosition, 3);
// Showed the processed output in our other window
cvShowImage("Processed WebCam", pProcessedFrame);
// Wait 20 milliseconds
keypress = cvWaitKey(20);
// Set the flag to quit if escape was pressed
if (keypress == 27)
{
quit = true;
}
} // End of while loop
// Release our stream capture object to free up any resources it has been using and release any file/device handles
cvReleaseCapture(&pCapture);
// Release our images
cvReleaseImage(&pFrame);
cvReleaseImage(&pProcessedFrame);
// This causes errors if you don't set it to NULL before releasing it. Maybe because we assign
// it to pProcessedFrame as the end result of the findEdges function, and we've already released pProcessedFrame!!
tempFrame = NULL;
cvReleaseImage(&tempFrame);
// Destory all windows
cvDestroyAllWindows();
}
#包括
#包括“opencv/cv.h”
#包括“opencv/highgui.h”
使用名称空间std;
//定义我们将用作全局变量的IplImage指针
IplImage*pFrame;
IplImage*pProcessedFrame;
IplImage*tempFrame;
//滑块用于边缘检测的低阈值
int-maxLowThreshold=1024;
int lowSliderPosition=150;
//滑块用于边缘检测的高阈值
int maxHighThreshold=1024;
int highSliderPosition=250;
//函数查找给定IplImage对象的边
IplImage*查找页(IplImage*源帧,双低阈值,双高阈值,双孔径)
{
//将源帧转换为灰度版本(tempFrame已初始化为使用灰度颜色设置)
CVT颜色(源帧、临时帧、CV_rgb2灰色);
//在tempframe上执行canny边缘查找,并将结果推回到自身!
cvCanny(tempFrame、tempFrame、低阈值、高阈值、孔径);
//传回我们现在处理的帧!
返回帧;
}
//回调函数,用于调整滑块移动时的低阈值
void onlow阈值幻灯片(幻灯片右值内)
{
lowSliderPosition=滑动值;
}
//回调函数,用于调整滑块移动的高阈值
在高阈值幻灯片上无效(幻灯片右侧值内)
{
highSliderPosition=滑动值;
}
int main(int argc,字符**argv)
{
//创建两个窗口
cvNamedWindow(“网络摄像头”,CV_窗口_自动调整大小);
cvNamedWindow(“已处理的网络摄像头”,CV_窗口_自动调整大小);
//创建低阈值滑块
//格式:滑块名称、窗口名称、滑块变量引用、滑块最大值、回调函数
cvCreateTrackbar(“低阈值”、“已处理的网络摄像头”和低幻灯片位置、maxLowThreshold、onLowThresholdSlide);
//创建高阈值滑块
cvCreateTrackbar(“高阈值”、“已处理的网络摄像头”和highSliderPosition、maxHighThreshold、onHighThresholdSlide);
//创建CvCapture对象以从网络摄像头抓取数据
CvCapture*pCapture;
//开始从网络摄像头捕获数据
pCapture=cvCaptureFromCAM(CV\u CAP\u V4L2);
//显示图像属性
CUT< P>谢谢大家。我找到了解决方案,我的CAM不捕捉图像,我换成另一个相机,现在代码运行良好。如果代码代码>为空,你的代码无法测试。你应该真正使用C++ API,你使用的C API已经过时了,将来不会支持。(你标记了“C++”,而不是“C”)。请改写代码使用C++ API.过时?你说使用另一个API,像CImg?