From 0f51155e790eef268f42cd99635cc9d23370e8bb Mon Sep 17 00:00:00 2001 From: berak Date: Sun, 28 May 2017 11:07:15 +0200 Subject: [PATCH] py_tutorials: add print() braces for python3 --- .../py_calibration/py_calibration.markdown | 2 +- .../py_core/py_basic_ops/py_basic_ops.markdown | 12 ++++++------ .../py_image_arithmetics.markdown | 4 ++-- .../py_core/py_optimization/py_optimization.markdown | 2 +- .../py_feature2d/py_brief/py_brief.markdown | 4 ++-- .../py_feature2d/py_fast/py_fast.markdown | 10 +++++----- .../py_feature_homography.markdown | 2 +- .../py_surf_intro/py_surf_intro.markdown | 12 ++++++------ .../py_mouse_handling/py_mouse_handling.markdown | 2 +- .../py_colorspaces/py_colorspaces.markdown | 4 ++-- .../py_contour_features/py_contour_features.markdown | 2 +- .../py_contours_more_functions.markdown | 2 +- .../py_thresholding/py_thresholding.markdown | 2 +- .../py_fourier_transform.markdown | 4 ++-- .../py_knn/py_knn_opencv/py_knn_opencv.markdown | 6 +++--- .../py_knn_understanding.markdown | 6 +++--- .../py_setup_in_fedora/py_setup_in_fedora.markdown | 4 ++-- .../py_setup_in_windows/py_setup_in_windows.markdown | 2 +- 18 files changed, 41 insertions(+), 41 deletions(-) diff --git a/doc/py_tutorials/py_calib3d/py_calibration/py_calibration.markdown b/doc/py_tutorials/py_calib3d/py_calibration/py_calibration.markdown index 1e22cedfb0..3e7a401377 100644 --- a/doc/py_tutorials/py_calib3d/py_calibration/py_calibration.markdown +++ b/doc/py_tutorials/py_calib3d/py_calibration/py_calibration.markdown @@ -218,7 +218,7 @@ for i in xrange(len(objpoints)): error = cv2.norm(imgpoints[i], imgpoints2, cv2.NORM_L2)/len(imgpoints2) mean_error += error -print "total error: ", mean_error/len(objpoints) +print( "total error: {}".format(mean_error/len(objpoints)) ) @endcode Additional Resources -------------------- diff --git a/doc/py_tutorials/py_core/py_basic_ops/py_basic_ops.markdown b/doc/py_tutorials/py_core/py_basic_ops/py_basic_ops.markdown index 6414dbed37..1305d8a1d8 100644 --- a/doc/py_tutorials/py_core/py_basic_ops/py_basic_ops.markdown +++ b/doc/py_tutorials/py_core/py_basic_ops/py_basic_ops.markdown @@ -30,18 +30,18 @@ You can access a pixel value by its row and column coordinates. For BGR image, i of Blue, Green, Red values. For grayscale image, just corresponding intensity is returned. @code{.py} >>> px = img[100,100] ->>> print px +>>> print( px ) [157 166 200] # accessing only blue pixel >>> blue = img[100,100,0] ->>> print blue +>>> print( blue ) 157 @endcode You can modify the pixel values the same way. @code{.py} >>> img[100,100] = [255,255,255] ->>> print img[100,100] +>>> print( img[100,100] ) [255 255 255] @endcode @@ -76,7 +76,7 @@ etc. Shape of image is accessed by img.shape. It returns a tuple of number of rows, columns and channels (if image is color): @code{.py} ->>> print img.shape +>>> print( img.shape ) (342, 548, 3) @endcode @@ -85,12 +85,12 @@ good method to check if loaded image is grayscale or color image. Total number of pixels is accessed by `img.size`: @code{.py} ->>> print img.size +>>> print( img.size ) 562248 @endcode Image datatype is obtained by \`img.dtype\`: @code{.py} ->>> print img.dtype +>>> print( img.dtype ) uint8 @endcode diff --git a/doc/py_tutorials/py_core/py_image_arithmetics/py_image_arithmetics.markdown b/doc/py_tutorials/py_core/py_image_arithmetics/py_image_arithmetics.markdown index 8995c93422..10bcd18e59 100644 --- a/doc/py_tutorials/py_core/py_image_arithmetics/py_image_arithmetics.markdown +++ b/doc/py_tutorials/py_core/py_image_arithmetics/py_image_arithmetics.markdown @@ -23,10 +23,10 @@ For example, consider below sample: >>> x = np.uint8([250]) >>> y = np.uint8([10]) ->>> print cv2.add(x,y) # 250+10 = 260 => 255 +>>> print( cv2.add(x,y) ) # 250+10 = 260 => 255 [[255]] ->>> print x+y # 250+10 = 260 % 256 = 4 +>>> print( x+y ) # 250+10 = 260 % 256 = 4 [4] @endcode It will be more visible when you add two images. OpenCV function will provide a better result. So diff --git a/doc/py_tutorials/py_core/py_optimization/py_optimization.markdown b/doc/py_tutorials/py_core/py_optimization/py_optimization.markdown index c0a0da408c..2c3878bd4a 100644 --- a/doc/py_tutorials/py_core/py_optimization/py_optimization.markdown +++ b/doc/py_tutorials/py_core/py_optimization/py_optimization.markdown @@ -44,7 +44,7 @@ for i in xrange(5,49,2): img1 = cv2.medianBlur(img1,i) e2 = cv2.getTickCount() t = (e2 - e1)/cv2.getTickFrequency() -print t +print( t ) # Result I got is 0.521107655 seconds @endcode diff --git a/doc/py_tutorials/py_feature2d/py_brief/py_brief.markdown b/doc/py_tutorials/py_feature2d/py_brief/py_brief.markdown index 57e284c9c8..4daf09d1e1 100644 --- a/doc/py_tutorials/py_feature2d/py_brief/py_brief.markdown +++ b/doc/py_tutorials/py_feature2d/py_brief/py_brief.markdown @@ -69,8 +69,8 @@ kp = star.detect(img,None) # compute the descriptors with BRIEF kp, des = brief.compute(img, kp) -print brief.descriptorSize() -print des.shape +print( brief.descriptorSize() ) +print( des.shape ) @endcode The function brief.getDescriptorSize() gives the \f$n_d\f$ size used in bytes. By default it is 32. Next one is matching, which will be done in another chapter. diff --git a/doc/py_tutorials/py_feature2d/py_fast/py_fast.markdown b/doc/py_tutorials/py_feature2d/py_fast/py_fast.markdown index e30107e96e..590c1e3854 100644 --- a/doc/py_tutorials/py_feature2d/py_fast/py_fast.markdown +++ b/doc/py_tutorials/py_feature2d/py_fast/py_fast.markdown @@ -108,10 +108,10 @@ kp = fast.detect(img,None) img2 = cv2.drawKeypoints(img, kp, None, color=(255,0,0)) # Print all default params -print "Threshold: ", fast.getThreshold() -print "nonmaxSuppression: ", fast.getNonmaxSuppression() -print "neighborhood: ", fast.getType() -print "Total Keypoints with nonmaxSuppression: ", len(kp) +print( "Threshold: {}".format(fast.getThreshold()) ) +print( "nonmaxSuppression:{}".format(fast.getNonmaxSuppression()) ) +print( "neighborhood: {}".format(fast.getType()) ) +print( "Total Keypoints with nonmaxSuppression: {}".format(len(kp)) ) cv2.imwrite('fast_true.png',img2) @@ -119,7 +119,7 @@ cv2.imwrite('fast_true.png',img2) fast.setNonmaxSuppression(0) kp = fast.detect(img,None) -print "Total Keypoints without nonmaxSuppression: ", len(kp) +print( "Total Keypoints without nonmaxSuppression: {}".format(len(kp)) ) img3 = cv2.drawKeypoints(img, kp, None, color=(255,0,0)) diff --git a/doc/py_tutorials/py_feature2d/py_feature_homography/py_feature_homography.markdown b/doc/py_tutorials/py_feature2d/py_feature_homography/py_feature_homography.markdown index 85547541f5..20b2d2e2b9 100644 --- a/doc/py_tutorials/py_feature2d/py_feature_homography/py_feature_homography.markdown +++ b/doc/py_tutorials/py_feature2d/py_feature_homography/py_feature_homography.markdown @@ -85,7 +85,7 @@ if len(good)>MIN_MATCH_COUNT: img2 = cv2.polylines(img2,[np.int32(dst)],True,255,3, cv2.LINE_AA) else: - print "Not enough matches are found - %d/%d" % (len(good),MIN_MATCH_COUNT) + print( "Not enough matches are found - {}/{}".format(len(good), MIN_MATCH_COUNT) ) matchesMask = None @endcode Finally we draw our inliers (if successfully found the object) or matching keypoints (if failed). diff --git a/doc/py_tutorials/py_feature2d/py_surf_intro/py_surf_intro.markdown b/doc/py_tutorials/py_feature2d/py_surf_intro/py_surf_intro.markdown index 7d5bd93fef..dab2addbf4 100644 --- a/doc/py_tutorials/py_feature2d/py_surf_intro/py_surf_intro.markdown +++ b/doc/py_tutorials/py_feature2d/py_surf_intro/py_surf_intro.markdown @@ -92,7 +92,7 @@ examples are shown in Python terminal since it is just same as SIFT only. While matching, we may need all those features, but not now. So we increase the Hessian Threshold. @code{.py} # Check present Hessian threshold ->>> print surf.getHessianThreshold() +>>> print( surf.getHessianThreshold() ) 400.0 # We set it to some 50000. Remember, it is just for representing in picture. @@ -102,7 +102,7 @@ While matching, we may need all those features, but not now. So we increase the # Again compute keypoints and check its number. >>> kp, des = surf.detectAndCompute(img,None) ->>> print len(kp) +>>> print( len(kp) ) 47 @endcode It is less than 50. Let's draw it on the image. @@ -119,7 +119,7 @@ on wings of butterfly. You can test it with other images. Now I want to apply U-SURF, so that it won't find the orientation. @code{.py} # Check upright flag, if it False, set it to True ->>> print surf.getUpright() +>>> print( surf.getUpright() ) False >>> surf.setUpright(True) @@ -139,7 +139,7 @@ etc, this is better. Finally we check the descriptor size and change it to 128 if it is only 64-dim. @code{.py} # Find size of descriptor ->>> print surf.descriptorSize() +>>> print( surf.descriptorSize() ) 64 # That means flag, "extended" is False. @@ -149,9 +149,9 @@ Finally we check the descriptor size and change it to 128 if it is only 64-dim. # So we make it to True to get 128-dim descriptors. >>> surf.extended = True >>> kp, des = surf.detectAndCompute(img,None) ->>> print surf.descriptorSize() +>>> print( surf.descriptorSize() ) 128 ->>> print des.shape +>>> print( des.shape ) (47, 128) @endcode Remaining part is matching which we will do in another chapter. diff --git a/doc/py_tutorials/py_gui/py_mouse_handling/py_mouse_handling.markdown b/doc/py_tutorials/py_gui/py_mouse_handling/py_mouse_handling.markdown index 3862b49181..53529c74d0 100644 --- a/doc/py_tutorials/py_gui/py_mouse_handling/py_mouse_handling.markdown +++ b/doc/py_tutorials/py_gui/py_mouse_handling/py_mouse_handling.markdown @@ -21,7 +21,7 @@ in Python terminal: @code{.py} import cv2 events = [i for i in dir(cv2) if 'EVENT' in i] -print events +print( events ) @endcode Creating mouse callback function has a specific format which is same everywhere. It differs only in what the function does. So our mouse callback function does one thing, it draws a circle where we diff --git a/doc/py_tutorials/py_imgproc/py_colorspaces/py_colorspaces.markdown b/doc/py_tutorials/py_imgproc/py_colorspaces/py_colorspaces.markdown index 8fbd8dc368..b0fa725ddf 100644 --- a/doc/py_tutorials/py_imgproc/py_colorspaces/py_colorspaces.markdown +++ b/doc/py_tutorials/py_imgproc/py_colorspaces/py_colorspaces.markdown @@ -24,7 +24,7 @@ commands in your Python terminal : @code{.py} >>> import cv2 >>> flags = [i for i in dir(cv2) if i.startswith('COLOR_')] ->>> print flags +>>> print( flags ) @endcode @note For HSV, Hue range is [0,179], Saturation range is [0,255] and Value range is [0,255]. Different softwares use different scales. So if you are comparing OpenCV values with them, you need @@ -96,7 +96,7 @@ terminal: @code{.py} >>> green = np.uint8([[[0,255,0 ]]]) >>> hsv_green = cv2.cvtColor(green,cv2.COLOR_BGR2HSV) ->>> print hsv_green +>>> print( hsv_green ) [[[ 60 255 255]]] @endcode Now you take [H-10, 100,100] and [H+10, 255, 255] as lower bound and upper bound respectively. Apart diff --git a/doc/py_tutorials/py_imgproc/py_contours/py_contour_features/py_contour_features.markdown b/doc/py_tutorials/py_imgproc/py_contours/py_contour_features/py_contour_features.markdown index 237725ea42..32243b064e 100644 --- a/doc/py_tutorials/py_imgproc/py_contours/py_contour_features/py_contour_features.markdown +++ b/doc/py_tutorials/py_imgproc/py_contours/py_contour_features/py_contour_features.markdown @@ -27,7 +27,7 @@ im2,contours,hierarchy = cv2.findContours(thresh, 1, 2) cnt = contours[0] M = cv2.moments(cnt) -print M +print( M ) @endcode From this moments, you can extract useful data like area, centroid etc. Centroid is given by the relations, \f$C_x = \frac{M_{10}}{M_{00}}\f$ and \f$C_y = \frac{M_{01}}{M_{00}}\f$. This can be done as diff --git a/doc/py_tutorials/py_imgproc/py_contours/py_contours_more_functions/py_contours_more_functions.markdown b/doc/py_tutorials/py_imgproc/py_contours/py_contours_more_functions/py_contours_more_functions.markdown index 2a96cb0ea0..81b4a74c9f 100644 --- a/doc/py_tutorials/py_imgproc/py_contours/py_contours_more_functions/py_contours_more_functions.markdown +++ b/doc/py_tutorials/py_imgproc/py_contours/py_contours_more_functions/py_contours_more_functions.markdown @@ -99,7 +99,7 @@ im2,contours,hierarchy = cv2.findContours(thresh2,2,1) cnt2 = contours[0] ret = cv2.matchShapes(cnt1,cnt2,1,0.0) -print ret +print( ret ) @endcode I tried matching shapes with different shapes given below: diff --git a/doc/py_tutorials/py_imgproc/py_thresholding/py_thresholding.markdown b/doc/py_tutorials/py_imgproc/py_thresholding/py_thresholding.markdown index 5fc6240238..0f4b7901c7 100644 --- a/doc/py_tutorials/py_imgproc/py_thresholding/py_thresholding.markdown +++ b/doc/py_tutorials/py_imgproc/py_thresholding/py_thresholding.markdown @@ -218,7 +218,7 @@ for i in xrange(1,256): # find otsu's threshold value with OpenCV function ret, otsu = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU) -print thresh,ret +print( "{} {}".format(thresh,ret) ) @endcode *(Some of the functions may be new here, but we will cover them in coming chapters)* diff --git a/doc/py_tutorials/py_imgproc/py_transforms/py_fourier_transform/py_fourier_transform.markdown b/doc/py_tutorials/py_imgproc/py_transforms/py_fourier_transform/py_fourier_transform.markdown index b100e65091..1c503c000b 100644 --- a/doc/py_tutorials/py_imgproc/py_transforms/py_fourier_transform/py_fourier_transform.markdown +++ b/doc/py_tutorials/py_imgproc/py_transforms/py_fourier_transform/py_fourier_transform.markdown @@ -186,12 +186,12 @@ using IPython magic command %timeit. @code{.py} In [16]: img = cv2.imread('messi5.jpg',0) In [17]: rows,cols = img.shape -In [18]: print rows,cols +In [18]: print("{} {}".format(rows,cols)) 342 548 In [19]: nrows = cv2.getOptimalDFTSize(rows) In [20]: ncols = cv2.getOptimalDFTSize(cols) -In [21]: print nrows, ncols +In [21]: print("{} {}".format(nrows,ncols)) 360 576 @endcode See, the size (342,548) is modified to (360, 576). Now let's pad it with zeros (for OpenCV) and find diff --git a/doc/py_tutorials/py_ml/py_knn/py_knn_opencv/py_knn_opencv.markdown b/doc/py_tutorials/py_ml/py_knn/py_knn_opencv/py_knn_opencv.markdown index c58658d7a4..2c06b1ac47 100644 --- a/doc/py_tutorials/py_ml/py_knn/py_knn_opencv/py_knn_opencv.markdown +++ b/doc/py_tutorials/py_ml/py_knn/py_knn_opencv/py_knn_opencv.markdown @@ -51,7 +51,7 @@ ret,result,neighbours,dist = knn.findNearest(test,k=5) matches = result==test_labels correct = np.count_nonzero(matches) accuracy = correct*100.0/result.size -print accuracy +print( accuracy ) @endcode So our basic OCR app is ready. This particular example gave me an accuracy of 91%. One option improve accuracy is to add more data for training, especially the wrong ones. So instead of finding @@ -64,7 +64,7 @@ np.savez('knn_data.npz',train=train, train_labels=train_labels) # Now load the data with np.load('knn_data.npz') as data: - print data.files + print( data.files ) train = data['train'] train_labels = data['train_labels'] @endcode @@ -109,7 +109,7 @@ ret, result, neighbours, dist = knn.findNearest(testData, k=5) correct = np.count_nonzero(result == labels) accuracy = correct*100.0/10000 -print accuracy +print( accuracy ) @endcode It gives me an accuracy of 93.22%. Again, if you want to increase accuracy, you can iteratively add error data in each level. diff --git a/doc/py_tutorials/py_ml/py_knn/py_knn_understanding/py_knn_understanding.markdown b/doc/py_tutorials/py_ml/py_knn/py_knn_understanding/py_knn_understanding.markdown index 5eae4b2f63..a9c36c494b 100644 --- a/doc/py_tutorials/py_ml/py_knn/py_knn_understanding/py_knn_understanding.markdown +++ b/doc/py_tutorials/py_ml/py_knn/py_knn_understanding/py_knn_understanding.markdown @@ -118,9 +118,9 @@ knn = cv2.ml.KNearest_create() knn.train(trainData, cv2.ml.ROW_SAMPLE, responses) ret, results, neighbours ,dist = knn.findNearest(newcomer, 3) -print "result: ", results,"\n" -print "neighbours: ", neighbours,"\n" -print "distance: ", dist +print( "result: {}\n".format(results) ) +print( "neighbours: {}\n".format(neighbours) ) +print( "distance: {}\n".format(dist) ) plt.show() @endcode diff --git a/doc/py_tutorials/py_setup/py_setup_in_fedora/py_setup_in_fedora.markdown b/doc/py_tutorials/py_setup/py_setup_in_fedora/py_setup_in_fedora.markdown index a4ec9bbd36..9da7008dad 100644 --- a/doc/py_tutorials/py_setup/py_setup_in_fedora/py_setup_in_fedora.markdown +++ b/doc/py_tutorials/py_setup/py_setup_in_fedora/py_setup_in_fedora.markdown @@ -30,7 +30,7 @@ $ yum install numpy opencv* Open Python IDLE (or IPython) and type following codes in Python terminal. @code{.py} >>> import cv2 ->>> print cv2.__version__ +>>> print( cv2.__version__ ) @endcode If the results are printed out without any errors, congratulations !!! You have installed OpenCV-Python successfully. @@ -218,7 +218,7 @@ Installation is over. All files are installed in /usr/local/ folder. But to use should be able to find OpenCV module. You have two options for that. -# **Move the module to any folder in Python Path** : Python path can be found out by entering - import sys;print sys.path in Python terminal. It will print out many locations. Move + `import sys; print(sys.path)` in Python terminal. It will print out many locations. Move /usr/local/lib/python2.7/site-packages/cv2.so to any of this folder. For example, @code{.sh} su mv /usr/local/lib/python2.7/site-packages/cv2.so /usr/lib/python2.7/site-packages diff --git a/doc/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.markdown b/doc/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.markdown index 23c5706cd2..f971192579 100644 --- a/doc/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.markdown +++ b/doc/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.markdown @@ -36,7 +36,7 @@ Installing OpenCV from prebuilt binaries -# Open Python IDLE and type following codes in Python terminal. @code >>> import cv2 - >>> print cv2.__version__ + >>> print( cv2.__version__ ) @endcode If the results are printed out without any errors, congratulations !!! You have installed