Skip to content

Commit 1de02b9

Browse files
committed
Merge pull request opencv#19564 from sturkmen72:patch-4
2 parents f6bc4fd + 9b399f3 commit 1de02b9

File tree

11 files changed

+25
-23
lines changed

11 files changed

+25
-23
lines changed

samples/python/houghcircles.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def main():
3030
circles = cv.HoughCircles(img, cv.HOUGH_GRADIENT, 1, 10, np.array([]), 100, 30, 1, 30)
3131

3232
if circles is not None: # Check if circles have been found and only then iterate over these and add them to the image
33+
circles = np.uint16(np.around(circles))
3334
_a, b, _c = circles.shape
3435
for i in range(b):
3536
cv.circle(cimg, (circles[0][i][0], circles[0][i][1]), circles[0][i][2], (0, 0, 255), 3, cv.LINE_AA)

samples/python/tutorial_code/Histograms_Matching/back_projection/calcBackProject_Demo1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ def Hist_and_Backproj(val):
3838

3939
## [Read the image]
4040
parser = argparse.ArgumentParser(description='Code for Back Projection tutorial.')
41-
parser.add_argument('--input', help='Path to input image.')
41+
parser.add_argument('--input', help='Path to input image.', default='home.jpg')
4242
args = parser.parse_args()
4343

44-
src = cv.imread(args.input)
44+
src = cv.imread(cv.samples.findFile(args.input))
4545
if src is None:
4646
print('Could not open or find the image:', args.input)
4747
exit(0)

samples/python/tutorial_code/Histograms_Matching/back_projection/calcBackProject_Demo2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ def Hist_and_Backproj(mask):
5454

5555
# Read the image
5656
parser = argparse.ArgumentParser(description='Code for Back Projection tutorial.')
57-
parser.add_argument('--input', help='Path to input image.')
57+
parser.add_argument('--input', help='Path to input image.', default='home.jpg')
5858
args = parser.parse_args()
5959

60-
src = cv.imread(args.input)
60+
src = cv.imread(cv.samples.findFile(args.input))
6161
if src is None:
6262
print('Could not open or find the image:', args.input)
6363
exit(0)

samples/python/tutorial_code/Histograms_Matching/histogram_calculation/calcHist_Demo.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@
5353

5454
## [Draw for each channel]
5555
for i in range(1, histSize):
56-
cv.line(histImage, ( bin_w*(i-1), hist_h - int(round(b_hist[i-1])) ),
57-
( bin_w*(i), hist_h - int(round(b_hist[i])) ),
56+
cv.line(histImage, ( bin_w*(i-1), hist_h - int(b_hist[i-1]) ),
57+
( bin_w*(i), hist_h - int(b_hist[i]) ),
5858
( 255, 0, 0), thickness=2)
59-
cv.line(histImage, ( bin_w*(i-1), hist_h - int(round(g_hist[i-1])) ),
60-
( bin_w*(i), hist_h - int(round(g_hist[i])) ),
59+
cv.line(histImage, ( bin_w*(i-1), hist_h - int(g_hist[i-1]) ),
60+
( bin_w*(i), hist_h - int(g_hist[i]) ),
6161
( 0, 255, 0), thickness=2)
62-
cv.line(histImage, ( bin_w*(i-1), hist_h - int(round(r_hist[i-1])) ),
63-
( bin_w*(i), hist_h - int(round(r_hist[i])) ),
62+
cv.line(histImage, ( bin_w*(i-1), hist_h - int(r_hist[i-1]) ),
63+
( bin_w*(i), hist_h - int(r_hist[i]) ),
6464
( 0, 0, 255), thickness=2)
6565
## [Draw for each channel]
6666

samples/python/tutorial_code/TrackingMotion/corner_subpixels/cornerSubPix_Demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def goodFeaturesToTrack_Demo(val):
3030
print('** Number of corners detected:', corners.shape[0])
3131
radius = 4
3232
for i in range(corners.shape[0]):
33-
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)
33+
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)
3434

3535
# Show what you got
3636
cv.namedWindow(source_window)

samples/python/tutorial_code/TrackingMotion/good_features_to_track/goodFeaturesToTrack_Demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def goodFeaturesToTrack_Demo(val):
3030
print('** Number of corners detected:', corners.shape[0])
3131
radius = 4
3232
for i in range(corners.shape[0]):
33-
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)
33+
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)
3434

3535
# Show what you got
3636
cv.namedWindow(source_window)

samples/python/tutorial_code/ml/introduction_to_svm/introduction_to_svm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
sv = svm.getUncompressedSupportVectors()
5454

5555
for i in range(sv.shape[0]):
56-
cv.circle(image, (sv[i,0], sv[i,1]), 6, (128, 128, 128), thickness)
56+
cv.circle(image, (int(sv[i,0]), int(sv[i,1])), 6, (128, 128, 128), thickness)
5757
## [show_vectors]
5858

5959
cv.imwrite('result.png', image) # save the image

samples/python/tutorial_code/ml/non_linear_svms/non_linear_svms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@
9494
for i in range(NTRAINING_SAMPLES):
9595
px = trainData[i,0]
9696
py = trainData[i,1]
97-
cv.circle(I, (px, py), 3, (0, 255, 0), thick)
97+
cv.circle(I, (int(px), int(py)), 3, (0, 255, 0), thick)
9898

9999
# Class 2
100100
for i in range(NTRAINING_SAMPLES, 2*NTRAINING_SAMPLES):
101101
px = trainData[i,0]
102102
py = trainData[i,1]
103-
cv.circle(I, (px, py), 3, (255, 0, 0), thick)
103+
cv.circle(I, (int(px), int(py)), 3, (255, 0, 0), thick)
104104
## [show_data]
105105

106106
#------------------------- 6. Show support vectors --------------------------------------------
@@ -109,7 +109,7 @@
109109
sv = svm.getUncompressedSupportVectors()
110110

111111
for i in range(sv.shape[0]):
112-
cv.circle(I, (sv[i,0], sv[i,1]), 6, (128, 128, 128), thick)
112+
cv.circle(I, (int(sv[i,0]), int(sv[i,1])), 6, (128, 128, 128), thick)
113113
## [show_vectors]
114114

115115
cv.imwrite('result.png', I) # save the Image

samples/python/tutorial_code/ml/py_svm_opencv/hogsvm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def hog(img):
3333
return hist
3434
## [hog]
3535

36-
img = cv.imread('digits.png',0)
36+
img = cv.imread(cv.samples.findFile('digits.png'),0)
3737
if img is None:
3838
raise Exception("we need the digits.png image from samples/data here !")
3939

samples/python/tutorial_code/video/optical_flow/optical_flow.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@
4040
p1, st, err = cv.calcOpticalFlowPyrLK(old_gray, frame_gray, p0, None, **lk_params)
4141

4242
# Select good points
43-
good_new = p1[st==1]
44-
good_old = p0[st==1]
43+
if p1 is not None:
44+
good_new = p1[st==1]
45+
good_old = p0[st==1]
4546

4647
# draw the tracks
4748
for i,(new,old) in enumerate(zip(good_new, good_old)):
4849
a,b = new.ravel()
4950
c,d = old.ravel()
50-
mask = cv.line(mask, (a,b),(c,d), color[i].tolist(), 2)
51-
frame = cv.circle(frame,(a,b),5,color[i].tolist(),-1)
51+
mask = cv.line(mask, (int(a),int(b)),(int(c),int(d)), color[i].tolist(), 2)
52+
frame = cv.circle(frame,(int(a),int(b)),5,color[i].tolist(),-1)
5253
img = cv.add(frame,mask)
5354

5455
cv.imshow('frame',img)

0 commit comments

Comments
 (0)