Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

TypeError: integer argument expected, got float line 35

import cv2 import numpy as np

img = cv2.imread('Bluelinegap50blur.jpg') gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) edges = cv2.Canny(img, 50, 200)

find lines

rho = 1 theta = np.pi / 180 threshold = 10 min_line_length = 0 max_line_gap = 10 line_image = np.copy(edges) * 0 lines = cv2.HoughLinesP(edges, rho, theta, threshold, np.array([]), min_line_length, max_line_gap)

draw found lines

img_dst = cv2.cvtColor(gray,cv2.COLOR_GRAY2RGB) for line in lines[0]: cv2.line(img_dst, (line[0], line[1]), (line[2], line[3]), (0,255,0), 2)

find corners

gray = np.float32(gray) dst = cv2.cornerHarris(gray, 15, 5, 0.04)

non-maximum suppression via dilation

kernel = np.ones((10,10)) max_dst = cv2.dilate(dst, kernel)
dst = dst * (dst == max_dst)

sort points by strength, find their positions and take 5 highest ones

sortIdx = np.argsort(dst.flatten())[::-1][:5]

draw them

w = img.shape[1]

for idx in sortIdx: cv2.circle(img_dst,(idx % w, idx / w) , 3, (0,0,255), -1)

click to hide/show revision 2
None

updated 2018-06-18 11:00:48 -0600

berak gravatar image

TypeError: integer argument expected, got float line 35

...

import cv2
import numpy as np

np img = cv2.imread('Bluelinegap50blur.jpg') gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) edges = cv2.Canny(img, 50, 200)

200) # find lines

lines rho = 1 theta = np.pi / 180 threshold = 10 min_line_length = 0 max_line_gap = 10 line_image = np.copy(edges) * 0 lines = cv2.HoughLinesP(edges, rho, theta, threshold, np.array([]), min_line_length, max_line_gap)

max_line_gap) # draw found lines

lines img_dst = cv2.cvtColor(gray,cv2.COLOR_GRAY2RGB) for line in lines[0]: cv2.line(img_dst, (line[0], line[1]), (line[2], line[3]), (0,255,0), 2)

2) # find corners

corners gray = np.float32(gray) dst = cv2.cornerHarris(gray, 15, 5, 0.04)

0.04) # non-maximum suppression via dilation

dilation kernel = np.ones((10,10)) max_dst = cv2.dilate(dst, kernel)
dst = dst * (dst == max_dst)

max_dst) # sort points by strength, find their positions and take 5 highest ones

ones sortIdx = np.argsort(dst.flatten())[::-1][:5]

np.argsort(dst.flatten())[::-1][:5] # draw them

them w = img.shape[1]

img.shape[1] for idx in sortIdx: cv2.circle(img_dst,(idx % w, idx / w) , 3, (0,0,255), -1)

-1)