-1

Image for setting the reference In the image shown, i need to detect the edge and draw a straight line through the points connecting the edges on both the sides and set this line as the origin for measuring the position of the indents on the key. I am using opencv python for image processing.

What i have tried: I tried it edge detection using canny edge function in OpenCV Python. This is my python code for edge detection:

import cv2
import numpy as np
from matplotlib import pyplot as plt    

img = cv2.imread('edge.png',0)
img = cv2.medianBlur(img,5)
cv2.imshow("image",img)
edges = cv2.Canny(img,100,200)
print(edges)

plt.imshow(edges)
plt.show()

This is the output from the above code:Edge detected output

from here how do i extract the vertical edges on both the sides? I need to access the coordinates of just the vertical edges as shown in the first image.

Ashwini
  • 31
  • 1
  • 4
  • 2
    Welcome to Stack Overflow. Please take the **tour** (https://stackoverflow.com/tour) and read the information guides in the **help center** (https://stackoverflow.com/help). Users are much more likely to help if you (1) show some research effort on your own (Google and StackOverflow searches), (2) learn what are appropriate questions for this forum, (3) show your images and (4) provide a minimal, complete, and verifiable example to your specific problem. – fmw42 Dec 01 '19 at 18:16
  • 1
    “A solution with sample code will be really helpful” - StackOverflow doesn’t work like that, in particular it isn’t a code-writing service - you need to show some effort to try solve this problem yourself and having presumably hit a problem and having researched it and tried to debug your code but having failed you come here as a last resort then you include a complete working sample of your code Which reproduces the problem you are hitting in your question. This must be a [mre] or you’ll get less help and downvotes – DisappointedByUnaccountableMod Dec 01 '19 at 19:05

1 Answers1

1

If I had to do this, I would first locate the horizontal edges (first transition to dark when moving vertically). From this, locate the oblique edges (first transition to dark when moving to the left) at a fixed distance from the horizontal edges.

Nothing really difficult.

enter image description here

In case the horizontality of the key is not guaranteed, use four measurement points on the horizontal edges to find the exact orientation.

  • thank you sir. How do i access the coordinates of just the vertical edges from both the sides and use it as the origin for position measurements? – Ashwini Dec 10 '19 at 10:54