-2

With following code I can detect Edges of Rectangle but now I wanted to click on each Edge of Rectangle? How I can do this ?

import numpy as np
import cv2
import matplotlib.pyplot as plt
import matplotlib
import win32api

matplotlib.rcParams["savefig.dpi"] = 400 # to get high resolution

img = cv2.imread('1.png');
plt.imshow( img )
plt.title('Original Image')
plt.show()

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# Apply Canny edge detection method on the image 
edges = cv2.Canny(gray,75,150,apertureSize = 3) 

plt.imshow(edges )
plt.title('My Image edges')
plt.show()

#lines = cv2.HoughLines(edges,1,np.pi/180, 200) 
lines = cv2.HoughLinesP(edges,1,np.pi/180, 150) 
print(lines)
  • There is no easy way to click on the edge - that is not something opencv can do for you; You will need to implement it by your own. – Dmitrii Z. Oct 05 '18 at 13:56

1 Answers1

0

You can use the following:

if (lines.any() == True): 
    for line in lines: 
        x1,y1, _, _ = line[0]
        cv2.Rectangle(img,(x1,y1),(x1+3,y1+3),(0,255,0),3)
        cv2.imshow('image', img)
        cv2.waitKey(0)
        cv2.destroyAllWindow()

this code will go throw all the edges one by one

jakelit
  • 2,124
  • 1
  • 10
  • 5
  • Thanks for your answer. However I am able to draw lines over detected edges. But I wanted to click on it . see full code here >> https://github.com/afarane/Tools_PythonOpenCV/blob/master/Image_Edge_HoughLines/HoughLines.ipynb – Abhijeet Farane Oct 08 '18 at 17:51