Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
kongfanhe committed Oct 2, 2021
0 parents commit 045d4b8
Show file tree
Hide file tree
Showing 16 changed files with 160 additions and 0 deletions.
Empty file added README.md
Empty file.
Binary file added bookpage.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added opencv_logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plane.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added poker.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions test00_hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

import cv2

print(cv2.getVersionString())

image = cv2.imread("opencv_logo.jpg")
print(image.shape)


cv2.imshow("image", image)
cv2.waitKey()

15 changes: 15 additions & 0 deletions test02_color.py
Original file line number Diff line number Diff line change
@@ -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()

9 changes: 9 additions & 0 deletions test03_crop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

import cv2

image = cv2.imread("opencv_logo.jpg")

crop = image[10:170, 40:200]

cv2.imshow("crop", crop)
cv2.waitKey()
13 changes: 13 additions & 0 deletions test04_draw.py
Original file line number Diff line number Diff line change
@@ -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()
14 changes: 14 additions & 0 deletions test05_blur.py
Original file line number Diff line number Diff line change
@@ -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()

13 changes: 13 additions & 0 deletions test06_corner.py
Original file line number Diff line number Diff line change
@@ -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()
22 changes: 22 additions & 0 deletions test07_match.py
Original file line number Diff line number Diff line change
@@ -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()


14 changes: 14 additions & 0 deletions test08_gradient.py
Original file line number Diff line number Diff line change
@@ -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()

16 changes: 16 additions & 0 deletions test09_threshold.py
Original file line number Diff line number Diff line change
@@ -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()

18 changes: 18 additions & 0 deletions test10_morphology.py
Original file line number Diff line number Diff line change
@@ -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()
14 changes: 14 additions & 0 deletions test11_camera.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 045d4b8

Please sign in to comment.