Skip to content

Some code snippets

Extracting object from detection api

Python code for cutting object from image from Custom Object Detection Service:

from ximilar.client import DetectionClient

# get Detection Task
client = DetectionClient("__API_TOKEN__")
detection_task, status = client.get_task("__DETECTION_TASK_ID__")

# Getting Detection Result:
result = detection_task.detect([{"_file": "__LOCAL_PATH__", "noresize": True}])

image = cv2.imread("__LOCAL_PATH__")
bbox = result["record"]["_objects"][0]["bound_box"]
first_object = image[bbox[1] : bbox[3], bbox[0] : bbox[2]]

Conversion RGB to LUV

Reference of conversion for check:

https://colormine.org/convert/rgb-to-luv
https://www.easyrgb.com/en/convert.php#inputFORM
https://en.wikipedia.org/wiki/CIELUV

Python code for converting RGB to CIELUV, you can check your code to this implementation and values:

import cv2

cv2.cvtColor(np.array([[[0,0,0]]]).astype('float32')/255.0, cv2.COLOR_RGB2Luv) # convert black
array([[[ 0., -0., -0.]]], dtype=float32)

cv2.cvtColor(np.array([[[255,0,0]]]).astype('float32')/255.0, cv2.COLOR_RGB2Luv) # convert red
array([[[ 53.240585, 175.01476 ,  37.752098]]], dtype=float32)

cv2.cvtColor(np.array([[[255,255,255]]]).astype('float32')/255.0, cv2.COLOR_RGB2Luv) # convert white
array([[[1.0000000e+02, 2.3841858e-05, 9.5367432e-05]]], dtype=float32)

cv2.cvtColor(np.array([[[1,0,0]]]).astype('float32')/255.0, cv2.COLOR_RGB2Luv) # convert almost black
array([[[0.05830765, 0.19167143, 0.04134505]]], dtype=float32)

cv2.cvtColor(np.array([[[0,0,255]]]).astype('float32')/255.0, cv2.COLOR_RGB2Luv) # convert blue
array([[[  32.29567 ,   -9.404743, -130.33951 ]]], dtype=float32)