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.
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;
}