Opencv Tutorial: 1 Import
Opencv Tutorial: 1 Import
1 Import
In [1]: import cv2
2 Read Image
In [17]: image = cv2.imread("jp.jpg")
4 Showing an image
In [23]: cv2.imshow("Image", image)
cv2.waitKey(10000)
cv2.destroyAllWindows()
6 ROI
In [29]: roi = image[100:500, 50:450]
cv2.imshow("ROI", roi)
cv2.waitKey(10000)
cv2.destroyAllWindows()
1
7 Resize
In [32]: resized = cv2.resize(image, (500, 500))
cv2.imshow("Fixed Resize", resized)
cv2.waitKey(10000)
cv2.destroyAllWindows()
8 Rotate
In [35]: center = (w//2, h//2)
M = cv2.getRotationMatrix2D(center, -45, 1.0)
rotated = cv2.warpAffine(image, M, (w, h))
cv2.imshow("Rotated", rotated)
cv2.waitKey(10000)
cv2.destroyAllWindows()
9 Smoothing
In [42]: blurred = cv2.GaussianBlur(image, (25, 25), 0)
cv2.imshow("Blurred", blurred)
cv2.waitKey(10000)
cv2.destroyAllWindows()
10 Drawing
In [43]: output = image.copy()
cv2.rectangle(output, (200, 300), (500, 800), (0, 0, 255), 2)
cv2.imshow("Rectangle", output)
cv2.waitKey(10000)
cv2.destroyAllWindows()
2
cv2.waitKey(10000)
cv2.destroyAllWindows()