2

I first tried to get the edge of the image by using Canny Edge Detector. Which is the yellow part of the second image, but I want to get ROI (which is the red part) automatically, but not by the coordinates of the image.

I've set thresholds to get the fine edge by controlling variable of low threshold and high threshold.

By this code I found not that bad edge of the image, but I am stuck with the problem that I can't get the ROI which is the inside part of the edge.

I would be very grateful if you give me any kind of help.

first image second image

Here is my code that detects edges of the image:

#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <Windows.h>

int high_switch_value = 0;
int highint = 0;
int low_switch_value = 0;
int lowint = 0;

void switch_callback_h(int position)
{
    highint = position;
}

void switch_callback_l(int position)
{
   lowint = position;
}

int main(int argc, char* argv[])
{
    int N = 7; 
IplImage* img = cvLoadImage("C:\\Users\\user\\Pictures\\sigfox\\Original_image.bmp",0); 
IplImage* img_b = cvCreateImage(cvSize(img->width+N-1,img->height+N-1),
                                 img->depth,img->nChannels); 
IplImage* out = cvCreateImage(cvGetSize(img_b),IPL_DEPTH_8U,img_b->nChannels);

CvPoint offset = cvPoint((N-1)/2,(N-1)/2);
cvCopyMakeBorder(img,img_b,offset,IPL_BORDER_REPLICATE,cvScalarAll(0));

cvNamedWindow("result",CV_WINDOW_AUTOSIZE);
cvNamedWindow("source",CV_WINDOW_AUTOSIZE);

int aperature_size = N;
double low_thresh = 20;
double high_thresh = 40;

cvCreateTrackbar("HIGH","result",&high_switch_value,4,switch_callback_h);
cvCreateTrackbar("LOW","result",&low_switch_value,4,switch_callback_l);

while(1)
{
    switch(highint)
    {
        case 0:
            high_thresh = 200;
            break;

        case 1:
            high_thresh = 400;
            break;

        case 2:
            high_thresh = 600;
            break;

        case 3:
            high_thresh = 800;
            break;

        case 4:
            high_thresh = 1000;
            break;
    }

    switch(lowint)
    {
        case 0:
            low_thresh = 0;
            break;

        case 1:
            low_thresh = 100;
            break;

        case 2:
            low_thresh = 200;
            break;

        case 3:
            low_thresh = 400;
            break;

        case 4:
            low_thresh = 600;
            break;
    }

    cvCanny(img_b,out,low_thresh*N*N,high_thresh*N*N,aperature_size);
    cvShowImage("result",out);
    cvShowImage("source",img);

    if(cvWaitKey(15) == 27)
    {
        break;
    }
}
cvReleaseImage(&img);
cvReleaseImage(&img_b);
cvReleaseImage(&out);
cvDestroyWindow("result");

return 0;

}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
이도일
  • 31
  • 3
  • 1
    please **avoid** using opencv's deprecated c-api. use cv::Mat, not IplImage* code like this should no more be written. – berak May 27 '15 at 14:38
  • @berak thanks! I will study more. Thank you for your advice:) – 이도일 May 27 '15 at 14:42
  • I tidied the question layout for you..... – Brian Tompsett - 汤莱恩 May 29 '15 at 21:42
  • One unrelated advice: **avoid** `#include `, even on windows you should use `#include ` (portability issue) – kebs May 29 '15 at 21:48
  • It is unclear how you define the ROI: vertically, ok, its defined by the top and bottom edges. But horizontally ? What's the criterion ? – kebs May 29 '15 at 21:51
  • @kebs Yes! Vertically is defined by the top and bottom edges. But Horizontally, I don't really need the precise horizontal length of ROI. I just need a rough length of the ROI. Thank you for your comment kebs! – 이도일 May 30 '15 at 12:52

0 Answers0