1. cv2.imread()

import cv2

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

This function reads an image from a file and returns it as a NumPy array.

2. cv2.imshow()

import cv2

image = cv2.imread("image.jpg")
cv2.imshow("Image", image)

key = cv2.waitKey(0)

 

This function displays an image on a window.

3. cv2.waitKey()

import cv2

image = cv2.imread("image.jpg")
cv2.imshow("Image", image)

key = cv2.waitKey(0)

This function waits for a key to be pressed and returns the ASCII code of the key.

4. cv2.imwrite()

import cv2

image = cv2.imread("image.jpg")
cv2.imwrite("image_output.jpg", image)

This function writes an image to a file.

5. cv2.resize()

import cv2

image = cv2.imread("image.jpg")
resized_image = cv2.resize(image, (image.shape[1] // 2, image.shape[0] // 2))

This function resizes an image.

6. cv2.flip()

import cv2

image = cv2.imread("image.jpg")
flipped_image = cv2.flip(image, 0)

This function flips an image horizontally.

7. cv2.threshold()

import cv2

image = cv2.imread("image.jpg")
thresholded_image = cv2.threshold(image, 128, 255, cv2.THRESH_BINARY)[1]

This function applies a threshold to an image.

8. cv2.findContours()

import cv2

image = cv2.imread("image.jpg")
contours, hierarchy = cv2.findContours(image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

This function finds contours in an image.

9. cv2.drawContours()

import cv2

image = cv2.imread("image.jpg")
contours, hierarchy = cv2.findContours(image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(image, contours, -1, (0, 0, 0), 2)

 

This function draws contours on an image.

10. cv2.HoughCircles()

import cv2

image = cv2.imread("image.jpg")
circles = cv2.HoughCircles(image, cv2.HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=10, maxRadius=100)

 

This function finds circles in an image.

 

'PYTHON' 카테고리의 다른 글

2. python _ opencv  (0) 2023.05.26

+ Recent posts