[PYTHON] Get image features with OpenCV

Load an image with OpenCV and get the average of its saturation and brightness. Since it is treated as a numpy matrix, knowledge of numpy is also required when dealing with OpenCV in Python. In the following example, the transposed matrix (T) is used to calculate the average of each layer.

import sys,cv2

img = cv2.imread(sys.argv[1],1) # 0=grayscale, 1=color
hsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)

print("Shape: {0}".format(hsv.shape))
print("Salute(mean): %.2f" % (hsv.T[1].flatten().mean()))
print("Value(mean): %.2f" % (hsv.T[2].flatten().mean()))

The following repository has a bit of sample code for OpenCV Python bindings.


Recommended Posts

Get image features with OpenCV
Image editing with python OpenCV
Image recognition with Keras + OpenCV
Real-time image processing basics with opencv
[Python] Using OpenCV with Python (Image Filtering)
Find image similarity with Python + OpenCV
Try blurring the image with opencv2
Image processing with Python & OpenCV [Tone Curve]
Image acquisition from camera with Python + OpenCV
Light image processing with Python x OpenCV
Image processing with Lambda + OpenCV (gray image creation)
Read the graph image with OpenCV and get the coordinates of the final point of the graph
I tried "smoothing" the image with Python + OpenCV
XavierNX accelerates OpenCV image processing with GPU (CUDA)
How to crop an image with Python + OpenCV
I tried "binarizing" the image with Python + OpenCV
[Small story] Test image generation with Python / OpenCV
Image processing with MyHDL
Detect stoop with OpenCV
Binarization with OpenCV / Python
Image recognition with keras
Get started with MicroPython
Get Tweets with Tweepy
Rotate sprites with OpenCV
Image processing with Python
Get date with python
Data Augmentation with openCV
Get started with Mezzanine
Get OpenCV video properties
Easy TopView with OpenCV
Stumble with homebrew opencv3
Image Processing with PIL
I tried to extract features with SIFT of OpenCV
[Python] Get the numbers in the graph image with OCR
[OpenCV / Python] I tried image analysis of cells with OpenCV
Image capture / OpenCV speed comparison with and without GPU
JPEG image generation by specifying quality with Python + OpenCV
Create miscellaneous Photoshop videos with Python + OpenCV ② Create still image Photoshop
Get country code with python
Image download with Flickr API
Image processing with Python (Part 2)
Get table dynamically with sqlalchemy
I tried "gamma correction" of the image with Python + OpenCV
Read image coordinates with Python-matplotlib
Image processing with PIL (Pillow)
Face recognition with Python's OpenCV
"Apple processing" with OpenCV3 + Python3
Try edge detection with OpenCV
Get Twitter timeline with python
Get started with influxDB + Grafana
Camera capture with Python + OpenCV
Get Youtube data with python
[Python] Using OpenCV with Python (Basic)
Image upload & customization with django-ckeditor
Sorting image files with Python (2)
Get information with zabbix api
Get started with Django! ~ Tutorial ④ ~
Binarize photo data with OpenCV
Loop video loading with opencv
Easy image classification with TensorFlow
Create Image Viewer with Tkinter