1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-26 05:43:05 +04:00

python: 'cv2.' -> 'cv.' via 'import cv2 as cv'

This commit is contained in:
Alexander Alekhin
2017-12-11 12:55:03 +03:00
parent 9665dde678
commit 5560db73bf
162 changed files with 2083 additions and 2084 deletions
@@ -1,7 +1,7 @@
from __future__ import print_function
import sys
import cv2
import cv2 as cv
alpha = 0.5
@@ -15,8 +15,8 @@ else:
if 0 <= alpha <= 1:
alpha = input_alpha
## [load]
src1 = cv2.imread('../../../../data/LinuxLogo.jpg')
src2 = cv2.imread('../../../../data/WindowsLogo.jpg')
src1 = cv.imread('../../../../data/LinuxLogo.jpg')
src2 = cv.imread('../../../../data/WindowsLogo.jpg')
## [load]
if src1 is None:
print ("Error loading src1")
@@ -26,10 +26,10 @@ elif src2 is None:
exit(-1)
## [blend_images]
beta = (1.0 - alpha)
dst = cv2.addWeighted(src1, alpha, src2, beta, 0.0)
dst = cv.addWeighted(src1, alpha, src2, beta, 0.0)
## [blend_images]
## [display]
cv2.imshow('dst', dst)
cv2.waitKey(0)
cv.imshow('dst', dst)
cv.waitKey(0)
## [display]
cv2.destroyAllWindows()
cv.destroyAllWindows()
@@ -1,4 +1,4 @@
import cv2
import cv2 as cv
import numpy as np
W = 400
@@ -7,7 +7,7 @@ def my_ellipse(img, angle):
thickness = 2
line_type = 8
cv2.ellipse(img,
cv.ellipse(img,
(W / 2, W / 2),
(W / 4, W / 16),
angle,
@@ -22,7 +22,7 @@ def my_filled_circle(img, center):
thickness = -1
line_type = 8
cv2.circle(img,
cv.circle(img,
center,
W / 32,
(0, 0, 255),
@@ -45,16 +45,16 @@ def my_polygon(img):
[W / 4, 3 * W / 8], [13 * W / 32, 3 * W / 8],
[5 * W / 16, 13 * W / 16], [W / 4, 13 * W / 16]], np.int32)
ppt = ppt.reshape((-1, 1, 2))
cv2.fillPoly(img, [ppt], (255, 255, 255), line_type)
cv.fillPoly(img, [ppt], (255, 255, 255), line_type)
# Only drawind the lines would be:
# cv2.polylines(img, [ppt], True, (255, 0, 255), line_type)
# cv.polylines(img, [ppt], True, (255, 0, 255), line_type)
## [my_polygon]
## [my_line]
def my_line(img, start, end):
thickness = 2
line_type = 8
cv2.line(img,
cv.line(img,
start,
end,
(0, 0, 0),
@@ -92,7 +92,7 @@ my_filled_circle(atom_image, (W / 2, W / 2))
my_polygon(rook_image)
## [rectangle]
# 2.b. Creating rectangles
cv2.rectangle(rook_image,
cv.rectangle(rook_image,
(0, 7 * W / 8),
(W, W),
(0, 255, 255),
@@ -106,10 +106,10 @@ my_line(rook_image, (W / 4, 7 * W / 8), (W / 4, W))
my_line(rook_image, (W / 2, 7 * W / 8), (W / 2, W))
my_line(rook_image, (3 * W / 4, 7 * W / 8), (3 * W / 4, W))
## [draw_rook]
cv2.imshow(atom_window, atom_image)
cv2.moveWindow(atom_window, 0, 200)
cv2.imshow(rook_window, rook_image)
cv2.moveWindow(rook_window, W, 200)
cv.imshow(atom_window, atom_image)
cv.moveWindow(atom_window, 0, 200)
cv.imshow(rook_window, rook_image)
cv.moveWindow(rook_window, W, 200)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv.waitKey(0)
cv.destroyAllWindows()
@@ -1,7 +1,7 @@
from __future__ import print_function
import sys
import cv2
import cv2 as cv
import numpy as np
@@ -19,34 +19,34 @@ def main(argv):
filename = argv[0] if len(argv) > 0 else "../../../../data/lena.jpg"
I = cv2.imread(filename, cv2.IMREAD_GRAYSCALE)
I = cv.imread(filename, cv.IMREAD_GRAYSCALE)
if I is None:
print('Error opening image')
return -1
## [expand]
rows, cols = I.shape
m = cv2.getOptimalDFTSize( rows )
n = cv2.getOptimalDFTSize( cols )
padded = cv2.copyMakeBorder(I, 0, m - rows, 0, n - cols, cv2.BORDER_CONSTANT, value=[0, 0, 0])
m = cv.getOptimalDFTSize( rows )
n = cv.getOptimalDFTSize( cols )
padded = cv.copyMakeBorder(I, 0, m - rows, 0, n - cols, cv.BORDER_CONSTANT, value=[0, 0, 0])
## [expand]
## [complex_and_real]
planes = [np.float32(padded), np.zeros(padded.shape, np.float32)]
complexI = cv2.merge(planes) # Add to the expanded another plane with zeros
complexI = cv.merge(planes) # Add to the expanded another plane with zeros
## [complex_and_real]
## [dft]
cv2.dft(complexI, complexI) # this way the result may fit in the source matrix
cv.dft(complexI, complexI) # this way the result may fit in the source matrix
## [dft]
# compute the magnitude and switch to logarithmic scale
# = > log(1 + sqrt(Re(DFT(I)) ^ 2 + Im(DFT(I)) ^ 2))
## [magnitude]
cv2.split(complexI, planes) # planes[0] = Re(DFT(I), planes[1] = Im(DFT(I))
cv2.magnitude(planes[0], planes[1], planes[0])# planes[0] = magnitude
cv.split(complexI, planes) # planes[0] = Re(DFT(I), planes[1] = Im(DFT(I))
cv.magnitude(planes[0], planes[1], planes[0])# planes[0] = magnitude
magI = planes[0]
## [magnitude]
## [log]
matOfOnes = np.ones(magI.shape, dtype=magI.dtype)
cv2.add(matOfOnes, magI, magI) # switch to logarithmic scale
cv2.log(magI, magI)
cv.add(matOfOnes, magI, magI) # switch to logarithmic scale
cv.log(magI, magI)
## [log]
## [crop_rearrange]
magI_rows, magI_cols = magI.shape
@@ -69,12 +69,12 @@ def main(argv):
magI[0:cx, cy:cy + cy] = tmp
## [crop_rearrange]
## [normalize]
cv2.normalize(magI, magI, 0, 1, cv2.NORM_MINMAX) # Transform the matrix with float values into a
cv.normalize(magI, magI, 0, 1, cv.NORM_MINMAX) # Transform the matrix with float values into a
## viewable image form(float between values 0 and 1).
## [normalize]
cv2.imshow("Input Image" , I ) # Show the result
cv2.imshow("spectrum magnitude", magI)
cv2.waitKey()
cv.imshow("Input Image" , I ) # Show the result
cv.imshow("spectrum magnitude", magI)
cv.waitKey()
if __name__ == "__main__":
main(sys.argv[1:])
@@ -3,7 +3,7 @@ import sys
import time
import numpy as np
import cv2
import cv2 as cv
## [basic_method]
def is_grayscale(my_image):
@@ -23,7 +23,7 @@ def sharpen(my_image):
if is_grayscale(my_image):
height, width = my_image.shape
else:
my_image = cv2.cvtColor(my_image, cv2.CV_8U)
my_image = cv.cvtColor(my_image, cv.CV_8U)
height, width, n_channels = my_image.shape
result = np.zeros(my_image.shape, my_image.dtype)
@@ -47,13 +47,13 @@ def sharpen(my_image):
def main(argv):
filename = "../../../../data/lena.jpg"
img_codec = cv2.IMREAD_COLOR
img_codec = cv.IMREAD_COLOR
if argv:
filename = sys.argv[1]
if len(argv) >= 2 and sys.argv[2] == "G":
img_codec = cv2.IMREAD_GRAYSCALE
img_codec = cv.IMREAD_GRAYSCALE
src = cv2.imread(filename, img_codec)
src = cv.imread(filename, img_codec)
if src is None:
print("Can't open image [" + filename + "]")
@@ -61,10 +61,10 @@ def main(argv):
print("mat_mask_operations.py [image_path -- default ../../../../data/lena.jpg] [G -- grayscale]")
return -1
cv2.namedWindow("Input", cv2.WINDOW_AUTOSIZE)
cv2.namedWindow("Output", cv2.WINDOW_AUTOSIZE)
cv.namedWindow("Input", cv.WINDOW_AUTOSIZE)
cv.namedWindow("Output", cv.WINDOW_AUTOSIZE)
cv2.imshow("Input", src)
cv.imshow("Input", src)
t = round(time.time())
dst0 = sharpen(src)
@@ -72,8 +72,8 @@ def main(argv):
t = (time.time() - t) / 1000
print("Hand written function time passed in seconds: %s" % t)
cv2.imshow("Output", dst0)
cv2.waitKey()
cv.imshow("Output", dst0)
cv.waitKey()
t = time.time()
## [kern]
@@ -82,17 +82,17 @@ def main(argv):
[0, -1, 0]], np.float32) # kernel should be floating point type
## [kern]
## [filter2D]
dst1 = cv2.filter2D(src, -1, kernel)
dst1 = cv.filter2D(src, -1, kernel)
# ddepth = -1, means destination image has depth same as input image
## [filter2D]
t = (time.time() - t) / 1000
print("Built-in filter2D time passed in seconds: %s" % t)
cv2.imshow("Output", dst1)
cv.imshow("Output", dst1)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv.waitKey(0)
cv.destroyAllWindows()
return 0