circles = cv.HoughCircles(img, cv.HOUGH_GRADIENT, 1, 10, np.array([]), 100, 30, 1, 30)
if circles is not None: # Check if circles have been found and only then iterate over these and add them to the image
+ circles = np.uint16(np.around(circles))
_a, b, _c = circles.shape
for i in range(b):
cv.circle(cimg, (circles[0][i][0], circles[0][i][1]), circles[0][i][2], (0, 0, 255), 3, cv.LINE_AA)
## [Read the image]
parser = argparse.ArgumentParser(description='Code for Back Projection tutorial.')
-parser.add_argument('--input', help='Path to input image.')
+parser.add_argument('--input', help='Path to input image.', default='home.jpg')
args = parser.parse_args()
-src = cv.imread(args.input)
+src = cv.imread(cv.samples.findFile(args.input))
if src is None:
print('Could not open or find the image:', args.input)
exit(0)
# Read the image
parser = argparse.ArgumentParser(description='Code for Back Projection tutorial.')
-parser.add_argument('--input', help='Path to input image.')
+parser.add_argument('--input', help='Path to input image.', default='home.jpg')
args = parser.parse_args()
-src = cv.imread(args.input)
+src = cv.imread(cv.samples.findFile(args.input))
if src is None:
print('Could not open or find the image:', args.input)
exit(0)
## [Draw for each channel]
for i in range(1, histSize):
- cv.line(histImage, ( bin_w*(i-1), hist_h - int(round(b_hist[i-1])) ),
- ( bin_w*(i), hist_h - int(round(b_hist[i])) ),
+ cv.line(histImage, ( bin_w*(i-1), hist_h - int(b_hist[i-1]) ),
+ ( bin_w*(i), hist_h - int(b_hist[i]) ),
( 255, 0, 0), thickness=2)
- cv.line(histImage, ( bin_w*(i-1), hist_h - int(round(g_hist[i-1])) ),
- ( bin_w*(i), hist_h - int(round(g_hist[i])) ),
+ cv.line(histImage, ( bin_w*(i-1), hist_h - int(g_hist[i-1]) ),
+ ( bin_w*(i), hist_h - int(g_hist[i]) ),
( 0, 255, 0), thickness=2)
- cv.line(histImage, ( bin_w*(i-1), hist_h - int(round(r_hist[i-1])) ),
- ( bin_w*(i), hist_h - int(round(r_hist[i])) ),
+ cv.line(histImage, ( bin_w*(i-1), hist_h - int(r_hist[i-1]) ),
+ ( bin_w*(i), hist_h - int(r_hist[i]) ),
( 0, 0, 255), thickness=2)
## [Draw for each channel]
print('** Number of corners detected:', corners.shape[0])
radius = 4
for i in range(corners.shape[0]):
- cv.circle(copy, (corners[i,0,0], corners[i,0,1]), radius, (rng.randint(0,256), rng.randint(0,256), rng.randint(0,256)), cv.FILLED)
+ cv.circle(copy, (int(corners[i,0,0]), int(corners[i,0,1])), radius, (rng.randint(0,256), rng.randint(0,256), rng.randint(0,256)), cv.FILLED)
# Show what you got
cv.namedWindow(source_window)
print('** Number of corners detected:', corners.shape[0])
radius = 4
for i in range(corners.shape[0]):
- cv.circle(copy, (corners[i,0,0], corners[i,0,1]), radius, (rng.randint(0,256), rng.randint(0,256), rng.randint(0,256)), cv.FILLED)
+ cv.circle(copy, (int(corners[i,0,0]), int(corners[i,0,1])), radius, (rng.randint(0,256), rng.randint(0,256), rng.randint(0,256)), cv.FILLED)
# Show what you got
cv.namedWindow(source_window)
sv = svm.getUncompressedSupportVectors()
for i in range(sv.shape[0]):
- cv.circle(image, (sv[i,0], sv[i,1]), 6, (128, 128, 128), thickness)
+ cv.circle(image, (int(sv[i,0]), int(sv[i,1])), 6, (128, 128, 128), thickness)
## [show_vectors]
cv.imwrite('result.png', image) # save the image
for i in range(NTRAINING_SAMPLES):
px = trainData[i,0]
py = trainData[i,1]
- cv.circle(I, (px, py), 3, (0, 255, 0), thick)
+ cv.circle(I, (int(px), int(py)), 3, (0, 255, 0), thick)
# Class 2
for i in range(NTRAINING_SAMPLES, 2*NTRAINING_SAMPLES):
px = trainData[i,0]
py = trainData[i,1]
- cv.circle(I, (px, py), 3, (255, 0, 0), thick)
+ cv.circle(I, (int(px), int(py)), 3, (255, 0, 0), thick)
## [show_data]
#------------------------- 6. Show support vectors --------------------------------------------
sv = svm.getUncompressedSupportVectors()
for i in range(sv.shape[0]):
- cv.circle(I, (sv[i,0], sv[i,1]), 6, (128, 128, 128), thick)
+ cv.circle(I, (int(sv[i,0]), int(sv[i,1])), 6, (128, 128, 128), thick)
## [show_vectors]
cv.imwrite('result.png', I) # save the Image
return hist
## [hog]
-img = cv.imread('digits.png',0)
+img = cv.imread(cv.samples.findFile('digits.png'),0)
if img is None:
raise Exception("we need the digits.png image from samples/data here !")
p1, st, err = cv.calcOpticalFlowPyrLK(old_gray, frame_gray, p0, None, **lk_params)
# Select good points
- good_new = p1[st==1]
- good_old = p0[st==1]
+ if p1 is not None:
+ good_new = p1[st==1]
+ good_old = p0[st==1]
# draw the tracks
for i,(new,old) in enumerate(zip(good_new, good_old)):
a,b = new.ravel()
c,d = old.ravel()
- mask = cv.line(mask, (a,b),(c,d), color[i].tolist(), 2)
- frame = cv.circle(frame,(a,b),5,color[i].tolist(),-1)
+ mask = cv.line(mask, (int(a),int(b)),(int(c),int(d)), color[i].tolist(), 2)
+ frame = cv.circle(frame,(int(a),int(b)),5,color[i].tolist(),-1)
img = cv.add(frame,mask)
cv.imshow('frame',img)
framenum = -1 # Frame counter
- captRefrnc = cv.VideoCapture(sourceReference)
- captUndTst = cv.VideoCapture(sourceCompareWith)
+ captRefrnc = cv.VideoCapture(cv.samples.findFileOrKeep(sourceReference))
+ captUndTst = cv.VideoCapture(cv.samples.findFileOrKeep(sourceCompareWith))
if not captRefrnc.isOpened():
print("Could not open the reference " + sourceReference)