Ask Your Question
1

TypeError: integer argument expected, got float line 35

asked 2018-06-18 09:35:38 -0600

kiderburm gravatar image

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

berak gravatar image

...

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)
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
4

answered 2018-10-31 06:34:17 -0600

supra56 gravatar image

Just add slash.

cv2.circle(img_dst,(idx % w, idx // w) , 3, (0,0,255), -1)
edit flag offensive delete link more

Comments

1

am i wrong, or is this more a python3 problem ? (python2 was much less strict about that, iirc)

berak gravatar imageberak ( 2018-11-05 10:04:18 -0600 )edit
1

@berak. It is python 3 problem. Dated back to 2012, I Always used python 3 whenever I used single slash. But when new version 3.1 or later I had prbolem but couldn't solvedd it. I had to get support from python community. They informed me to used double slash or int throughout pytnon 3. Python 2 discountined 2019.

supra56 gravatar imagesupra56 ( 2018-11-05 10:24:38 -0600 )edit
1

thanks for confirming it !

berak gravatar imageberak ( 2018-11-05 10:27:25 -0600 )edit

You're welcome. I had to see this comparison python 2 and python 3.

supra56 gravatar imagesupra56 ( 2018-11-05 10:33:16 -0600 )edit
0

answered 2018-11-05 09:55:12 -0600

ameypar94 gravatar image

cv2.circle accepts only integers as the circle center co-ordinates. So, make sure you pass integers to the function. One way to do this is: cv2.circle(img_dst,(idx % w, idx // w) , 3, (0,0,255), -1) Or else: cv2.circle(img_dst,(idx % w, int(idx /3)) , 3, (0,0,255), -1)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-06-18 09:35:38 -0600

Seen: 6,342 times

Last updated: Nov 05 '18