gpt4 book ai didi

image-processing - openCv中的边缘检测导致运行时错误

转载 作者:行者123 更新时间:2023-12-02 17:15:59 25 4
gpt4 key购买 nike

我已使用cvCanny函数检测边缘。

cvCanny( img_b, out, lowThresh*N*N, highThresh*N*N, aperature_size ); 

但是在运行时会给出运行时错误。错误味精根本无法清除。它指的是一些内存位置。请帮我..!!

码:
void switch_callback_h( int position ){
highInt = position;
}
void switch_callback_l( int position ){
lowInt = position;
}

int _tmain(int argc, _TCHAR* argv[])
{

const char* name = "Edge Detection Window";
// Kernel size
int N = 7;
CvCapture* capture = cvCaptureFromCAM(1);
IplImage* frame;

while(1) {
frame = cvQueryFrame( capture );

// Add convolution boarders
CvPoint offset = cvPoint((N-1)/2,(N-1)/2);
cvCopyMakeBorder(frame, img_b, offset, IPL_BORDER_REPLICATE, cvScalarAll(0));

// Make window
cvNamedWindow( name, 1 );

// Edge Detection Variables
int aperature_size = N;
double lowThresh = 20;
double highThresh = 40;

// Create trackbars
cvCreateTrackbar( "High", name, &high_switch_value, 4, switch_callback_h );
cvCreateTrackbar( "Low", name, &low_switch_value, 4, switch_callback_l );
highThresh = 800;
lowThresh = 100;

cvCanny( img_b, out, lowThresh*N*N, highThresh*N*N, aperature_size );

cvShowImage(name, out);
cvReleaseImage( &frame );
cvReleaseImage( &img_b );
cvReleaseImage( &out );
cvDestroyWindow( name );

if( cvWaitKey( 15 ) == 27 )
break;

return 0;
}

最佳答案

非常接近,无法完成这项工作。基本上,这是您的问题:

  • 您正在循环中创建一个窗口。由于窗口每次都具有相同的名称,因此您只需创建一次即可。
  • 您必须先销毁图像,然后才能显示它们。当您调用cvShowImage时,将不会显示您的图像,而在您调用cvWaitKey时,将显示您的图像。到那时,您已经释放了图像,因此将不会显示任何内容。
  • 您正在释放从CvCapture加载的帧。该文档明确指出而不是可以做到这一点:

  • The function cvQueryFrame grabs a frame from a camera or video file, decompresses it and returns it. This function is just a combination of GrabFrame and RetrieveFrame , but in one call. The returned image should not be released or modified by the user. In the event of an error, the return value may be NULL.


  • 您不会在任何地方初始化image_bout。您发布的代码中甚至都没有声明它们。 我不知道您的代码是如何编译的,更不用说运行了。
  • 您正在将image_b指定为canny边缘检测的源,而实际上它应该是frame
  • 您没有释放视频捕获结构

  • 就像我说的那样,有一些小问题。这是有效的代码:
    #include <stdlib.h>
    #include <cv.h>
    #include <highgui.h>
    //
    // Comment this out to use the webcam.
    //
    #define LOAD_IMAGE "/home/misha/Desktop/Lenna.png"
    int main(int argc, char **argv)
    {
    const char *name = "Edge Detection Window";
    int N = 7;
    #ifndef LOAD_IMAGE
    CvCapture *capture = cvCaptureFromCAM(1);
    #endif
    IplImage *frame = NULL;
    IplImage *out = NULL;

    cvNamedWindow(name, 1);

    while (1)
    {
    #ifdef LOAD_IMAGE
    frame = cvLoadImage(LOAD_IMAGE, 0);
    #else
    frame = cvQueryFrame(capture);
    #endif
    out = cvCreateImage(cvGetSize(frame), frame->depth, frame->nChannels);

    int aperature_size = N;
    double lowThresh = 20;
    double highThresh = 40;

    highThresh = 800;
    lowThresh = 100;

    cvCanny(frame, out, lowThresh * N * N, highThresh * N * N,
    aperature_size);

    cvShowImage(name, out);
    #ifndef LOAD_IMAGE
    if (cvWaitKey(15) == 27)
    break;
    #else
    cvWaitKey(0);
    break;
    #endif
    }
    cvReleaseImage(&out);
    cvDestroyWindow(name);
    #ifdef LOAD_IMAGE
    cvReleaseImage(&frame);
    #else
    cvReleaseCapture(&capture);
    #endif
    return 0;
    }

    编译为:
    gcc -ggdb -Wall -o devan.out devan.c `pkg-config --cflags --libs opencv`

    标准图像和输出:

    关于image-processing - openCv中的边缘检测导致运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4838122/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com