Ask Your Question
0

How to capture the coordinates of lines

asked 2014-11-19 12:42:56 -0600

Agribot gravatar image

I’m a newby interested in learning how to use opencv and python programming I’m trying to learn how to capture the coordinates (x and y points) of the start and finish of a grid of vertical and horizontal lines drawing in a picture and then store those coordinates in a text file for use by another program. Outline of Logic;- import cv2 import numpy as np ) Read-in the picture to an image im = cv2.imread ('grid1.jpg') ( the picture can be a simple grid of black lines on a white background, so it may not be necessary to process it to clarify the lines) ) Scan the image find the lines ?? ) Identify, or calculate the coordinates where the vertical and horizontal lines start and end ?? ) Write the coordinate of each intersection, one at a time, into a list ?? ) Write that list to a text file np.savetxt('output_file', list) Can someone show some python code that would do that ?

I’ve started to read about some of the standard opencv library methods, such as the information about SimpleBlobDetector and FeatureDetector¶ provided at

http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_feature_detectors.html#simpleblobdetector

and about moments at http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/moments/moments.html python-opencv, finding centroid of an image

but that information is beyond me at the moment ( and some of it is for C++, not for someone learning Python ) My environment is;- Opencv 2.4 Windows 7 Visual Studio 2013 express for Windows Desktop Anaconda Python 2.7

Now, I know that many of you might think the problem is basic, but I believe many newbies trying to get develop an understanding of opencv for Python will appreciate your answers !

Many Thanks for your help

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2014-11-24 10:00:04 -0600

theodore gravatar image

Well, from your description I think that the HoughTransform algorithm for lines is what you are looking for. Using the latter algorithm it is really easy to retrieve the starting and the ending point/s of the line/s, which are stored in a vector. Moreover, you can get more information related to the found line/s, like angle, etc...

If you search in the net you will find several examples, on how to use the embedded function of the OpenCV library related to HoughTranform algorithm, both in C++ and in Python. Furthermore, here you can find a function about how you can obtain the intersection point of the lines. It is in C++, but I think that it is not gonna be a big deal to port it to Python.

Chears, tt :-)

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-11-19 12:42:56 -0600

Seen: 2,396 times

Last updated: Nov 24 '14