Reputation:
I learn in this link.
My test code:
import cv2
import numpy as np
img = cv2.imread( 'E:/image/sudoku.png' )
gray = cv2.cvtColor( img,cv2.COLOR_BGR2GRAY )
edges = cv2.Canny( gray,50,150,apertureSize = 3 )
minLineLength = 100
maxLineGap = 10
lines = cv2.HoughLinesP( edges,1,np.pi/180,100,minLineLength,maxLineGap )
for line in lines:
for x1,y1,x2,y2 in line:
cv2.line( img,( x1,y1 ),( x2,y2 ),( 0,255,0 ),2 )
cv2.imwrite( 'E:/image/myhoughlinesp.jpg',img )
cv2.imshow( '1',img )
cv2.waitKey(0)
The result of my code running:
But the picture generated by the official website is like this:
If you don't change the code.(Use that link's code),the generated picture is like this:
When I change the code, although there are a lot of green lines,but doesn't have the official website's good effect.
Why do I have a different picture from the official website?
Upvotes: 2
Views: 1235
Reputation:
I know why the effect is different.
The function cv2.HoughLinesP() in python3.X has 7 parameters.
def HoughLinesP(image, rho, theta, threshold, lines=None, minLineLength=None, maxLineGap=None):
But the code of the official website only writes 6 parameters.So you should write the name of the parameter,like this:
import cv2
import numpy as np
img = cv2.imread( 'E:/image/sudoku.png' )
gray = cv2.cvtColor( img,cv2.COLOR_BGR2GRAY )
edges = cv2.Canny( gray,50,150,apertureSize = 3 )
minLineLength = 100
maxLineGap = 10
lines = cv2.HoughLinesP( edges,1,np.pi/180,100,minLineLength=minLineLength,maxLineGap=maxLineGap )
for line in lines:
for x1,y1,x2,y2 in line:
cv2.line( img,( x1,y1 ),( x2,y2 ),( 0,255,0 ),2 )
cv2.imwrite( 'E:/image/myhoughlinesp.jpg',img )
cv2.imshow( '1',img )
cv2.waitKey(0)
Result picture:
Upvotes: 2