Skip to content

Commit a9af479

Browse files
authored
Add files via upload
1 parent 40b1872 commit a9af479

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

opencv_tutorial_01.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import imutils
2+
import cv2
3+
4+
image = cv2.imread("jp.png")
5+
(h, w, d) = image.shape
6+
print("width={}, height={}, depth={}".format(w, h, d))
7+
8+
(B, G, R) = image[100, 50]
9+
print("R={}, G={}, B={}".format(R, G, B))
10+
11+
roi = image[60:160, 320:420]
12+
cv2.imshow("ROI", roi)
13+
14+
resized = cv2.resize(image, (200, 200))
15+
cv2.imshow("Fixed Resizing", resized)
16+
17+
r = 300 / w
18+
dim = (300, int(h*r))
19+
resizedAspectRatio = cv2.resize(image, dim)
20+
cv2.imshow("Aspect Ratio Resize", resizedAspectRatio)
21+
22+
resizeAuto = imutils.resize(image, width=300)
23+
cv2.imshow("Auto Resize", resizeAuto)
24+
25+
center = (w // 2, h // 2)
26+
M = cv2.getRotationMatrix2D(center, -45, 1.0)
27+
rotated = cv2.warpAffine(image, M, (w, h))
28+
cv2.imshow("OpenCV Rotation", rotated)
29+
30+
autoRotated = imutils.rotate(image, -45)
31+
cv2.imshow("Imutils Rotation", autoRotated)
32+
33+
rotateWithOutCrop = imutils.rotate_bound(image, 45)
34+
cv2.imshow("Rotate with out cropping", rotateWithOutCrop)
35+
36+
blurred = cv2.GaussianBlur(image, (11, 11), 0)
37+
cv2.imshow("Blurred", blurred)
38+
39+
output = image.copy()
40+
cv2.rectangle(output, (320, 60), (420, 160), (0, 0, 255), 2)
41+
cv2.imshow("Rectangle", output)
42+
43+
outputCircle = image.copy()
44+
cv2.circle(outputCircle, (300, 150), 20, (255, 0, 0), -1)
45+
cv2.imshow("Circle", outputCircle)
46+
47+
outputLine = image.copy()
48+
cv2.line(outputLine, (60, 20), (400, 200), (0, 0, 255), 5)
49+
cv2.imshow("Line", outputLine)
50+
51+
outputText = image.copy()
52+
cv2.putText(outputText, "OpenCV + Jurassic Park!!!", (10, 25),
53+
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
54+
cv2.imshow("Text", outputText)
55+
56+
cv2.imshow("Image", image)
57+
cv2.waitKey(0)

0 commit comments

Comments
 (0)