OpenCV-Python कंप्यूटर विज़न समस्याओं को हल करने के लिए डिज़ाइन किए गए Python बाइंडिंग की एक लाइब्रेरी है। OpenCV-Python Numpy का उपयोग करता है, जो MATLAB- शैली सिंटैक्स के साथ संख्यात्मक संचालन के लिए एक अत्यधिक अनुकूलित पुस्तकालय है। सभी OpenCV सरणी संरचनाएँ Numpy सरणियों में और से परिवर्तित की जाती हैं।
उदाहरण
# read image as RGB
# Importing cv2 and matplotlib module
import cv2
import matplotlib.pyplot as plt
# reads image as RGB
img = cv2.imread('download.png')
# shows the image
plt.imshow(img)
# read image as GrayScale
# Importing cv2 module
import cv2
# Reads image as gray scale
img = cv2.imread('download.png', 0)
# We can alternatively convert
# image by using cv2color
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Shows the image
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
# read image as YCrCb color space
# Import cv2 module
import cv2
# Reads the image
img = cv2.imread('download.png')
# Convert to YCrCb color space
img = cv2.cvtColor(img, cv2.COLOR_BGR2YCrCb)
# Shows the image
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
# read image as HSV color space
# Importing cv2 module
import cv2
# Reads the image
img = cv2.imread('download.png')
# Converts to HSV color space
img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# Shows the image
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
# Heat map of image
# Importing matplotlib and cv2
import matplotlib.pyplot as plt
import cv2
# reads the image
img = cv2.imread('download.png')
# plot heat map image
plt.imshow(img, cmap ='hot')
# Spectral map of image
# Importing matplotlib and cv2
import matplotlib.pyplot as plt
import cv2
img = cv2.imread('download.png')
plt.imshow(img, cmap ='nipy_spectral') के रूप में matplotlib और cv2import matplotlib.pyplot को इम्पोर्ट करना