Ask Your Question

John_E's profile - activity

2019-09-17 07:18:46 -0600 received badge  Famous Question (source)
2017-04-29 13:25:26 -0600 received badge  Notable Question (source)
2016-06-14 03:57:16 -0600 received badge  Popular Question (source)
2015-09-02 14:26:45 -0600 received badge  Student (source)
2015-04-02 05:10:07 -0600 commented question Finding contours in vector of connected points

@LBerger I just compiled opencv-3. My application should be simple enough to be able to use opencv-3 without any hidden bugs...

2015-04-01 15:47:31 -0600 commented question Finding contours in vector of connected points

@LBerger I am currently using opencv-2.4.9 with a custom ConnectedComponents class. Your solution looks like it is using opencv-3. Is that correct?

2015-04-01 13:51:51 -0600 commented question Finding contours in vector of connected points

@LBerger It looks like there is a couple of lines missing in your code window. Could you edit your comment please?

2015-04-01 13:33:18 -0600 commented question Finding contours in vector of connected points

@matman ConnectedComponents stores the points of all connected pixels in a cluster, which is useful for other stuff I'm doing. I thought it would be nice to be able to find which of those points describes the contour of the blob without having to threshold again in the canny algorithm.

2015-04-01 12:56:26 -0600 asked a question Finding contours in vector of connected points

Hi!

I use a class called ConnectedComponents to split a binary image into vectors of connected points (Point2i).

I find it convenient to use these point vectors when sorting out which blob to use. But once I sort out the appropriate object, I need to perform stuff like circularity measurements. Thus the need for contours.

Is there an algorithm for finding the contour in a vector of points?

Would it be less taxing to convert the point vector to a mat, perform canny and then findContours?

EDIT

One way of doing it is:

  • Threshold image
  • Use a connectedcomponents class to store individual sets of connected pixels as points
  • Perform canny on the thresholded image
  • Find the edges
  • Map contours with the different sets of connected pixels
  • Decide what set(s) of connectedcomponents we want

What I would rather do is

  • Threshold image
  • Use a connectedcomponents class to store individual sets of connected pixels as points
  • Decide what set(s) of connected pixels to use
  • Find the edges of that single set.
2014-01-24 20:17:37 -0600 received badge  Scholar (source)
2014-01-23 10:02:25 -0600 commented answer Accessing pixels along a circle

@StevenPuttemans I was wrong. Your loop gives the exact same output as mine when accessing it with y, x.

2014-01-23 09:55:06 -0600 received badge  Supporter (source)
2014-01-23 09:44:25 -0600 commented answer Accessing pixels along a circle

@StevenPuttemans The picture in the main post shows the result. The dots doesn't move that much as the needle turns.

2014-01-23 09:31:19 -0600 commented answer Accessing pixels along a circle

@StevenPuttemans Nope. It just scatters the points in a different way.

2014-01-23 09:18:43 -0600 commented answer Accessing pixels along a circle

No. they are on the circle, but not where the circle intersects with the white line.

2014-01-23 09:03:14 -0600 commented answer Accessing pixels along a circle

@StevenPuttemans Thanks that is a smarter way of creating the points. Unfortunately the scattering problem remains when checking the pixel values.

2014-01-23 08:52:20 -0600 received badge  Editor (source)
2014-01-23 08:52:20 -0600 edited question Accessing pixels along a circle

Hi!

Got an annoying problem.

I have:

  • A binary image containing the result of a canny edge detection.
  • A Vector containing all points on a circle.

I want:

To draw a little dot on all points where the circle intersects a white line on the canny image.

The problem:

I can use the points with draw functions such as circle(). But when I use them with Mat::at() I end up accessing pixels outside the image. It is as if I need to translate the points before using at. But to what? image description

The code:

#include <iostream>
#include <iomanip>
#include <sstream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#define NEEDLE_CENTER_X 565
#define NEEDLE_CENTER_Y 602
#define I_CIRCLE_RADIUS 100
#define CANNY_THRESHOLD 70

using namespace std;
using namespace cv;

int main()
{
    namedWindow( "Original", CV_WINDOW_AUTOSIZE );
    namedWindow( "Binary", CV_WINDOW_AUTOSIZE );
    moveWindow( "Binary", 570, 100 );
    moveWindow( "Original", 0, 100 );

    Point needle_center( NEEDLE_CENTER_X, NEEDLE_CENTER_Y );

    //Get points in circle
    Size axes( I_CIRCLE_RADIUS, I_CIRCLE_RADIUS );
    vector<Point> circle_points;
    ellipse2Poly( needle_center, axes, 0, 0, 360, 1, circle_points );

    //Step through images
    for( int i = 1; i <= 21; i++ )
    {
        stringstream file;
        file << "img/" << setw( 2 ) << setfill( '0' ) << i << ".png";

        //Read image
        Mat original = imread( file.str(), CV_LOAD_IMAGE_UNCHANGED );
        circle( original, needle_center, 2, CV_RGB( 0, 255, 0 ), 1, CV_AA, 1 );

        //Make a grayscale copy
        Mat gray( original.size(), CV_8UC1 );
        cvtColor( original, gray, CV_BGR2GRAY );

        //Find edges in grayscale image
        Mat edges( original.size(), CV_8UC1 );
        Canny( gray, edges, CANNY_THRESHOLD, CANNY_THRESHOLD * 3, 3 );

        //Iterate pixels in circle
        for( auto current_point : circle_points )
        {
            if( (edges.at<uchar>( current_point )) != 0 )
                circle( original, current_point, 1, CV_RGB( 255, 0, 0 ), 1, CV_AA, 1 );
        }

        imshow( "Binary", edges );
        imshow( "Original", original );

        if( (waitKey( 0 )) == 1048603 )
            break;
    }

    destroyAllWindows();

    return 0;
}

Any help is appreciated.

//John