Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

finding absolute straight lines/ rectangles for contours

While trying to detect the straight lines in an image, I'm unable to find the Hough transform of the image.

I have first converted the image to grayscale but unable to find the straight lines. image description

Thus, can you help me to make the contours which were detected as pure straight lines/rectangles. Such that I can easily find the horizontal lines(i will do it later) in the image. `def hou(): import math img = cv2.imread('image5GR.jpg') #gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) edges = cv2.Canny(img,50,150,apertureSize = 3) minLineLength = 20 maxLineGap = 10 lines = cv2.HoughLinesP(edges,1,math.pi/180,100,minLineLength,maxLineGap) for x1,y1,x2,y2 in lines[0]: cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2) while True: cv2.imshow('houghlines',img) if cv2.waitKey(20) & 0xFF == 27: break cv2.destroyAllWindows()

import cv2
hou()`

Finally, the image I am getting, which isn't appropriate(only shows a small green line at the bottom) image description

same question is posted in StackOverflow question

finding absolute straight lines/ rectangles for contours

While trying to detect the straight lines in an image, I'm unable to find the Hough transform of the image.

I have first converted the image to grayscale but unable to find the straight lines. image description

Thus, can you help me to make the contours which were detected as pure straight lines/rectangles. Such that I can easily find the horizontal lines(i will do it later) in the image. image.

`def hou():
   import math
   img = cv2.imread('image5GR.jpg')
   #gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
   edges = cv2.Canny(img,50,150,apertureSize = 3)
   minLineLength = 20
   maxLineGap = 10
   lines = cv2.HoughLinesP(edges,1,math.pi/180,100,minLineLength,maxLineGap)
   for x1,y1,x2,y2 in lines[0]:
      cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2)
   while True:
     cv2.imshow('houghlines',img)
     if cv2.waitKey(20) & 0xFF == 27:
        break
   cv2.destroyAllWindows()

cv2.destroyAllWindows() import cv2
hou()`

hou()`

Finally, the image I am getting, which isn't appropriate(only shows a small green line at the bottom) image description

same question is posted in StackOverflow question