Reputation: 21
Does anyone know how to use cv2.circle with the sub-pixel "shift" parameter?
import cv2
import numpy as np
i1 = np.zeros((256, 256, 3), np.float32)
cv2.circle(i1, (199,199), 10, (1,0,0), -1)
cv2.imshow('1', i1)
i2 = np.zeros((256, 256, 3), np.float32)
cv2.circle(i2, (199,199), 10, (1,0,0), -1, shift=1)
cv2.imshow('2', i2)
cv2.waitKey(10000)
I would expect the circle in the second circle to be at (99.5,99.5), 199*(2^-1) = 99.5 For me it appears in the same place as the first. Cheers,
Upvotes: 2
Views: 5197
Reputation: 2021
The shift parameter is like working with everything multiplied by (1 << shift) Thus if you want to draw a circle at (199.5, 199.5) you need to do something like this:
i2 = np.zeros((256, 256, 3), np.float32)
shift = 3
factor = (1 << shift)
cv2.circle(i2, (int(199.5 * factor + 0.5),int(199.5 * factor + 0.5)), 10 * factor, (1,0,0), -1, shift=shift)
cv2.imshow('2', i2)
Upvotes: 2
Reputation: 79
I did not encounter this issue as of today (openCV 3.1.0). However you have to be carefull: The input radius
is shifted as well! Thus in your example the 2nd circle is half the size.
Upvotes: 1