OpenCV is used for image processing in MH Software & Service. In order to consider the fastest processing method on Raspberry Pi, we are comparing the processing speed of OpenCV and numpy.
We processed each process 500,000 times, investigated which was faster, and adopted the faster one to speed up the processing of the TiD thermo AI device TiD.
import cv2
import numpy as np
#Please decide the file name appropriately
file_name = "test.jpg "
img = None
org = cv2.imread(file_name)
for i in range(500000):
# Resize: OpenCV is fast.
#img = cv2.resize(org, (300,300), cv2.INTER_CUBIC)
#img = cv2.resize(org, dsize=(300,300))
#img = org.repeat(2, axis=0).repeat(2, axis=1)
# Frip: OpenCV is fast.
#img = cv2.flip(org, 1)
#img = np.fliplr(org)
# BGR to RGB: Numpy is fast.
#img = org
#img = cv2.cvtColor(org, cv2.COLOR_BGR2RGB)
#img = org[:, :, ::-1]
# Grayslace: OpenCV is fast.
#img = cv2.cvtColor(org, cv2.COLOR_BGR2GRAY)
#img = 0.299 * org[:, :, 0] + 0.587 * org[:, :, 1] + 0.114 * org[:, :, 2]
# Rotate: OpenCV is fast.
#img = np.rot90(org)
#img = cv2.rotate(org, cv2.ROTATE_90_CLOCKWISE) #2.99[sec]
YouTube: Thermal Camera (Thermo AI Device TiD) Python Edition web: Thermo AI Device TiD Python Acceleration (URL is subject to change.)
Recommended Posts