hakuna_code
hakuna_code

Reputation: 793

How to find the pixel values of objects detected from yolo in python?

I am using yolo for image detection on my custom dataset, where i train to identiy certain object in the dataset. And post training, the algorithm correctly predicted these objects in the images. I would like to get the rbg values of the predicted objects alone, in opencv i didnot find a way to check the rgb values for objects inside a detected box. In the sample image attached, i would like to see the rgb value of the cup detected.

enter image description here

Upvotes: 0

Views: 1277

Answers (1)

Roy Lee
Roy Lee

Reputation: 329

  1. Get a object's bounding box coordinate

For example, result = [x, y, w, h] or [x1, y1, x2, y2]

  1. Check image to get RGB value by using bbox coordinate

For example, if your result is [x1, y1, x2, y2] and your image shape is img[640,480,3]

rgb_values = img[x1:x2, y1:y2, 0:2]

you will get rgb value of object you detect

Upvotes: 1

Related Questions