Ask Your Question
1

how to find the coordinate of top/bottom/left and right points

asked 2013-12-09 06:39:08 -0600

ati gravatar image

updated 2016-01-22 07:03:52 -0600

how do I find the coordinate of these 4 points in a detected object(which does not have any specific shape)? image description

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
6

answered 2013-12-09 06:52:31 -0600

Haris gravatar image

updated 2013-12-09 07:18:43 -0600

You can follow below method to achieve this.

  • Segment the four dotted region. Use inRange to segment the dots, better to convert to HSV color space before inRange.
  • Use OpenCV Find contour get the contour in image.
  • Use OpenCV moments to find the centre point of your contour

    Code:-

    #include <iostream>
    #include "opencv2/opencv.hpp"
    #include <stdio.h>     
    using namespace std;
    using namespace cv;
    
    int main( int argc, char** argv )
    {
        Mat src=imread("img.png",1);
        Mat hsv,thr;
        cvtColor(src,hsv,CV_BGR2HSV);
       // inRange(hsv,Scalar(160,0,120), Scalar(179,255,200), thr);
        inRange(src,Scalar(20,0,120), Scalar(25,0,200), thr);        
       vector<vector<Point> > contours;
       vector<Vec4i> hierarchy;
       findContours( thr, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
    
      /// Get the moments
      vector<Moments> mu(contours.size() );
      for( int i = 0; i < contours.size(); i++ )
         { mu[i] = moments( contours[i], false ); }
    
      ///  Get the mass centers:
      vector<Point2f> mc( contours.size() );
      for( int i = 0; i < contours.size(); i++ )
         { mc[i] = Point2f( mu[i].m10/mu[i].m00 , mu[i].m01/mu[i].m00 ); }
    
      /// Draw contours
      for( int i = 0; i< contours.size(); i++ )
         {
           circle( src, mc[i], 10, Scalar(0,0,255), 1,CV_AA, 0 );
         }
    
    
    imshow("src",src);
    waitKey();
    
    waitKey(); }

Result:

image description

edit flag offensive delete link more
0

answered 2014-10-07 11:43:03 -0600

Pauie gravatar image

what if there are no dots how to find the extreme points of an object in an image? topmost, leftmost, rightmost, bottom

edit flag offensive delete link more

Comments

1

Then you should create a black-white mask of your retrieved object. Loop over the image, at each white pixel, see if the current pixel has a value that is better then a previous found candidate for topmost leftmost rightmost or bottom pixel. If so replace.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-10-08 04:24:03 -0600 )edit
1

Or use contour approach like, find contour->bounding box for contour etc...See the tutorial here

Haris gravatar imageHaris ( 2014-10-08 07:26:22 -0600 )edit
1

This is of great help

oyashi gravatar imageoyashi ( 2015-03-30 17:38:25 -0600 )edit

Question Tools

Stats

Asked: 2013-12-09 06:39:08 -0600

Seen: 11,636 times

Last updated: Oct 07 '14