Now Available in Plug-in Store
This article was written by EdOliver and Victor Altamirano
Uses OpenCv to process images and generates interesting filters for the camera in order to experiment later with haarcascades.
Filters:
- Image Equalization (color).
- Binarization of image or Threshold (Red, Green and Blue).
- Grayscale.
- Blur.
- Erosion-Dilatation.
- Negative
How it Works:
Once activated, we can select the desired filter using the “Mode” button, depending on the color that the Wi-Fi symbol has, it will be the effect that will be applied to the image.
- Blue: Image Equalization (color).
- Green: Image Binarization or Threshold (Red, Green and Blue).
- Cyan: Grayscale.
- Magenta: Blur.
- Yellow: Erosion-Dilatation.
- White: Negative.
- Once the filter is selected, we only have to press the Shutter button to take the image and save it, the image will be saved in a folder called “Filtered Images”.
Note: when the filter is being applied the WiFi symbol will flash, until it stops blinking. Do not press any other button, this process takes 1 - 4 seconds depending on the filter.
Development:
The filters were made with the following code:
Image Equalization (color):
fileUrl = String.format("%s/%s_equalize.jpg", Constants.PLUGIN_DIRECTORY, dateTimeStr);
Mat rgbImage = new Mat(img.size(), img.type());
Imgproc.cvtColor(img, img, Imgproc.COLOR_RGB2YCrCb);
List<Mat> channels = new ArrayList<Mat>();
Core.split(img, channels);
Imgproc.equalizeHist(channels.get(0), channels.get(0));
Core.merge(channels, img);
Imgproc.cvtColor(img, img, Imgproc.COLOR_YCrCb2BGR);
Binarization of image or Threshold (Red, Green and Blue):
fileUrl = String.format("%s/%s_threshold.jpg", Constants.PLUGIN_DIRECTORY, dateTimeStr);
Mat rgbImage = new Mat(img.size(), img.type());
Imgproc.cvtColor(img, img, Imgproc.COLOR_RGB2YCrCb);
Imgproc.threshold(img, img, 127.0, 255.0, Imgproc.THRESH_BINARY);
Imgproc.cvtColor(img, img, Imgproc.COLOR_YCrCb2RGB);
Grayscale
fileUrl = String.format("%s/%s_gray.jpg", Constants.PLUGIN_DIRECTORY, dateTimeStr);
Imgproc.cvtColor(img, img, Imgproc.COLOR_RGB2GRAY);
Blur
fileUrl = String.format("%s/%s_blur.jpg", Constants.PLUGIN_DIRECTORY, dateTimeStr);
Imgproc.cvtColor(img, img, Imgproc.COLOR_RGB2BGR);
Imgproc.blur(img, img, new Size(25,25));
Erosion-Dialation
fileUrl = String.format("%s/%s_erodedilate.jpg", Constants.PLUGIN_DIRECTORY, dateTimeStr);
Imgproc.cvtColor(img, img, Imgproc.COLOR_RGB2GRAY);
Imgproc.threshold(img, img, 0, 255, Imgproc.THRESH_BINARY_INV+Imgproc.THRESH_OTSU);
Negative
fileUrl = String.format("%s/%s_negative.jpg", Constants.PLUGIN_DIRECTORY, dateTimeStr);
Core.bitwise_not(img,img);