diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/bookpage.jpg b/bookpage.jpg new file mode 100644 index 0000000..8961718 Binary files /dev/null and b/bookpage.jpg differ diff --git a/opencv_logo.jpg b/opencv_logo.jpg new file mode 100644 index 0000000..29f8f1b Binary files /dev/null and b/opencv_logo.jpg differ diff --git a/plane.jpg b/plane.jpg new file mode 100644 index 0000000..62b854e Binary files /dev/null and b/plane.jpg differ diff --git a/poker.jpg b/poker.jpg new file mode 100644 index 0000000..9b0afbe Binary files /dev/null and b/poker.jpg differ diff --git a/test00_hello.py b/test00_hello.py new file mode 100644 index 0000000..ed5c2a3 --- /dev/null +++ b/test00_hello.py @@ -0,0 +1,12 @@ + +import cv2 + +print(cv2.getVersionString()) + +image = cv2.imread("opencv_logo.jpg") +print(image.shape) + + +cv2.imshow("image", image) +cv2.waitKey() + diff --git a/test02_color.py b/test02_color.py new file mode 100644 index 0000000..d95d206 --- /dev/null +++ b/test02_color.py @@ -0,0 +1,15 @@ + + +import cv2 + +image = cv2.imread("opencv_logo.jpg") + +cv2.imshow("blue", image[:, :, 0]) +cv2.imshow("green", image[:, :, 1]) +cv2.imshow("red", image[:, :, 2]) + +gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) +cv2.imshow("gray", gray) + +cv2.waitKey() + diff --git a/test03_crop.py b/test03_crop.py new file mode 100644 index 0000000..9e3893a --- /dev/null +++ b/test03_crop.py @@ -0,0 +1,9 @@ + +import cv2 + +image = cv2.imread("opencv_logo.jpg") + +crop = image[10:170, 40:200] + +cv2.imshow("crop", crop) +cv2.waitKey() diff --git a/test04_draw.py b/test04_draw.py new file mode 100644 index 0000000..7efa335 --- /dev/null +++ b/test04_draw.py @@ -0,0 +1,13 @@ + +import cv2 +import numpy as np + +image = np.zeros([300, 300, 3], dtype=np.uint8) + +cv2.line(image, (100, 200), (250, 250), (255, 0, 0), 2) +cv2.rectangle(image, (30, 100), (60, 150), (0, 255, 0), 2) +cv2.circle(image, (150, 100), 20, (0, 0, 255), 3) +cv2.putText(image, "hello", (100, 50), 0, 1, (255, 255, 255), 2, 1) + +cv2.imshow("image", image) +cv2.waitKey() diff --git a/test05_blur.py b/test05_blur.py new file mode 100644 index 0000000..0edd3ac --- /dev/null +++ b/test05_blur.py @@ -0,0 +1,14 @@ + +import cv2 + +image = cv2.imread("plane.jpg") + +gauss = cv2.GaussianBlur(image, (5, 5), 0) +median = cv2.medianBlur(image, 5) + +cv2.imshow("image", image) +cv2.imshow("gauss", gauss) +cv2.imshow("median", median) + +cv2.waitKey() + diff --git a/test06_corner.py b/test06_corner.py new file mode 100644 index 0000000..8a38e92 --- /dev/null +++ b/test06_corner.py @@ -0,0 +1,13 @@ + +import cv2 + +image = cv2.imread("opencv_logo.jpg") +gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) + +corners = cv2.goodFeaturesToTrack(gray, 500, 0.1, 10) +for corner in corners: + x, y = corner.ravel() + cv2.circle(image, (int(x), int(y)), 3, (255, 0, 255), -1) + +cv2.imshow("corners", image) +cv2.waitKey() diff --git a/test07_match.py b/test07_match.py new file mode 100644 index 0000000..b9f98fe --- /dev/null +++ b/test07_match.py @@ -0,0 +1,22 @@ + +import cv2 +import numpy as np + +image = cv2.imread("poker.jpg") +gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) + +template = gray[75:105, 235:265] + +match = cv2.matchTemplate(gray, template, cv2.TM_CCOEFF_NORMED) +locations = np.where(match >= 0.9) + +w, h = template.shape[0:2] +for p in zip(*locations[::-1]): + x1, y1 = p[0], p[1] + x2, y2 = x1 + w, y1 + h + cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2) + +cv2.imshow("image", image) +cv2.waitKey() + + diff --git a/test08_gradient.py b/test08_gradient.py new file mode 100644 index 0000000..3df57d3 --- /dev/null +++ b/test08_gradient.py @@ -0,0 +1,14 @@ + +import cv2 + +gray = cv2.imread("opencv_logo.jpg", cv2.IMREAD_GRAYSCALE) + +laplacian = cv2.Laplacian(gray, cv2.CV_64F) +canny = cv2.Canny(gray, 100, 200) + +cv2.imshow("gray", gray) +cv2.imshow("laplacian", laplacian) +cv2.imshow("canny", canny) + +cv2.waitKey() + diff --git a/test09_threshold.py b/test09_threshold.py new file mode 100644 index 0000000..ffd1107 --- /dev/null +++ b/test09_threshold.py @@ -0,0 +1,16 @@ + +import cv2 + +gray = cv2.imread("bookpage.jpg", cv2.IMREAD_GRAYSCALE) +ret, binary = cv2.threshold(gray, 10, 255, cv2.THRESH_BINARY) +binary_adaptive = cv2.adaptiveThreshold( + gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 115, 1) +ret1, binary_otsu = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU) + +cv2.imshow("gray", gray) +cv2.imshow("binary", binary) +cv2.imshow("adaptive", binary_adaptive) +cv2.imshow("otsu", binary_otsu) + +cv2.waitKey() + diff --git a/test10_morphology.py b/test10_morphology.py new file mode 100644 index 0000000..987e836 --- /dev/null +++ b/test10_morphology.py @@ -0,0 +1,18 @@ + +import cv2 +import numpy as np + +gray = cv2.imread("opencv_logo.jpg", cv2.IMREAD_GRAYSCALE) + +_, binary = cv2.threshold(gray, 200, 255, cv2.THRESH_BINARY_INV) +kernel = np.ones((5, 5), np.uint8) + +erosion = cv2.erode(binary, kernel) +dilation = cv2.dilate(binary, kernel) + +cv2.imshow("binary", binary) +cv2.imshow("erosion", erosion) +cv2.imshow("dilation", dilation) + + +cv2.waitKey() diff --git a/test11_camera.py b/test11_camera.py new file mode 100644 index 0000000..be247dc --- /dev/null +++ b/test11_camera.py @@ -0,0 +1,14 @@ + +import cv2 + +capture = cv2.VideoCapture(0) + +while True: + ret, frame = capture.read() + cv2.imshow("camera", frame) + key = cv2.waitKey(1) + if key != -1: + break + +capture.release() +