Changing webcam-pixels to "nearest" color from color palette array

There are many ways to get image / pixel data into and out of opencv objects. Perhaps start with the simplest:

  1. create n PImages, one for each channel, and fill them black
  2. in the loop of your nearestpixel function
  3. depending on result, write the results to each pixel as a white dot into the correct mask image

Now you have n masks.

  1. load each mask into opencv with opencv = new OpenCV(this, img);
  2. close holes with opencv.dilate(); opencv.erode(); – you can also experiment with blur

Now you have n masks with closed holes.

For basic examples of moving color and grayscale pixels in and out of opencv object, see:

There are probably much faster ways of running your custom threshhold directly on the OpenCV buffer – I haven’t worked with it recently, so I’m not sure – but this is a great quick starting point to see if dilate+erode actually does what you want. If not, you may not need opencv at all, so no need to optimize.

1 Like