android - how to find accurate edges of the image? -


enter image description here

the above image output

i using opencv edge dection c++ code,as written below

jniexport jfloatarray jnicall java_com_test_getpoints (jnienv *env, jobject thiz,jobject bitmap) {     __android_log_print(android_log_verbose, appname, "scaning getpoints");     int ret;     androidbitmapinfo info;     void* pixels = 0;      if ((ret = androidbitmap_getinfo(env, bitmap, &info)) < 0) {         __android_log_print(android_log_verbose, appname,"androidbitmap_getinfo() failed ! error=%d", ret);         return 0;     }      if (info.format != android_bitmap_format_rgba_8888 )     {       __android_log_print(android_log_verbose, appname,"bitmap format not rgba_8888!");         return 0;     }      if ((ret = androidbitmap_lockpixels(env, bitmap, &pixels)) < 0) {         __android_log_print(android_log_verbose, appname,"androidbitmap_lockpixels() failed ! error=%d", ret);     }      mat mbgra(info.height, info.width, cv_8uc4, pixels);  =========================================     vector<point> img_pts = getpoints(mbgra);   =====================================       jfloatarray jarray = env->newfloatarray(8);      if (jarray != null)     {         jfloat *ptr = env->getfloatarrayelements(jarray, null);          (int i=0,j=i+4; j<8; i++,j++)         {             ptr[i] = img_pts[i].x;             ptr[j] = img_pts[i].y;         }         env->releasefloatarrayelements(jarray, ptr, null);     }     androidbitmap_unlockpixels(env, bitmap);     return jarray; }   vector<point> getpoints(mat image) {     int width = image.size().width;     int height = image.size().height;     mat image_proc = image.clone();     vector<vector<point> > squares;    mat blurred(image_proc);     medianblur(image_proc, blurred, 9);      mat gray0(blurred.size(), cv_8u), gray;     vector<vector<point> > contours;      (int c = 0; c < 3; c++)     {         int ch[] = {c, 0};         mixchannels(&blurred, 1, &gray0, 1, ch, 1);                const int threshold_level = 2;         (int l = 0; l < threshold_level; l++)         {           if (l == 0)             {                 canny(gray0, gray, 10, 20, 3); //               dilate(gray, gray, mat(), point(-1,-1));             }             else             {                 gray = gray0 >= (l+1) * 255 / threshold_level;             }            findcontours(gray, contours, cv_retr_list, cv_chain_approx_simple);            vector<point> approx;             (size_t = 0; < contours.size(); i++)             {                approxpolydp(mat(contours[i]), approx, arclength(mat(contours[i]), true)*0.02, true);                if (approx.size() == 4 &&                     fabs(contourarea(mat(approx))) > 1000 &&                     iscontourconvex(mat(approx)))                 {                     double maxcosine = 0;                     (int j = 2; j < 5; j++)                     {                         double cosine = fabs(angle(approx[j%4], approx[j-2], approx[j-1]));                         maxcosine = max(maxcosine, cosine);                     }                      if (maxcosine < 0.3)                         squares.push_back(approx);                 }             }         }          double largest_area = -1;         int largest_contour_index = 0;         for(int i=0;i<squares.size();i++)         {             double =contourarea(squares[i],false);             if(a>largest_area)             {                 largest_area = a;                 largest_contour_index = i;             }         }          __android_log_print(android_log_verbose, appname, "scaning size() %d",squares.size());         vector<point> points;         if(squares.size() > 0)         {             points = squares[largest_contour_index];         }         else         {             points.push_back(point(0, 0));             points.push_back(point(width, 0));             points.push_back(point(0, height));             points.push_back(point(width, height));         }          return points;     } } 

enter image description here

how find accurate edges per above screen shoot.

i new opencv can 1 guide me,thanks response.

the ouput image required output


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -