Search code examples
pythonimageopencvcropimage-recognition

Recognizing Image Target Lines


I'm trying to write a script that views an image, looks at lines on the image, and creates bounding boxes around the lines. Here is what I'm talking about...

I have this image: Image of Setup

I'm trying to have a way of intelligently cropping each section using a script. The best idea I came up with was to have colored tape around each of the sections like this: Image with tape

Given this image with the colored tape the program should be able to find the colored lines and identify where they intersect. Here is a visual of what the program should be able to locate: (Black lines are where the tape is, red dots are the intersecting positions) Program view

The end game here is for the program to be able to use this data to

  1. Know how many sections there are (in this case 9)
  2. Know where the sections are and create a bounding box around each one

Visually something like this: Image with cropped section bounding boxes

OpenCV has facial detection and feature detection so something like this with a static image should be fairly possible. What is the best method to accomplish this?


Solution

  • There are many ways to do what you want.

    One is to use sift:

    https://docs.opencv.org/3.3.0/da/df5/tutorial_py_sift_intro.html

    You will need to use keypoint detection, something like:

    sift = cv2.SIFT()
    kp = sift.detect(img,None)
    

    You can check if the points are right with: img2 = cv2.drawKeyPoints(kp)

    Then you will need to use cv2.boundingRect

    box = cv2.boundingRect(kp)
    

    If your marker is of a different color then the rest of the image, you only need to make a color filter to find the points.