B4J Question Colour Tracking with OpenCV

ElliotHC

Active Member
Licensed User
I have a project where I need to track a few different moving coloured shapes. Is there a tutorial or code snippet which is geared mostly around tracking colours?

Thanks
 

kimstudio

Active Member
Licensed User
Longtime User
Google the thread subject should return many tutorials as this is a basic application for OpenCV. The jOpenCV lib for B4J is encapsulated very well so conversion from the example to B4J line by line should be straight.

Basically:

convert image colorspace from RGB to HSV
mark every pixel in range of target color by upper/lower thresholds as 1 and all others 0
do erosion/dilation of image to fill the holes at area marked with 1, in case of noises (optional)
do connect component labelling (findcontours) to get the area and its center
 
Upvote 0
Top