forked from kongfanhe/opencv_tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 045d4b8
Showing
16 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|