Skip to content

Instantly share code, notes, and snippets.

@nakaly
Created January 5, 2018 06:25
Show Gist options
  • Save nakaly/2ca1a6cd9d13b385141f709246883256 to your computer and use it in GitHub Desktop.
Save nakaly/2ca1a6cd9d13b385141f709246883256 to your computer and use it in GitHub Desktop.
BlurredImage by using Gaussian Filter in open cv
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import javax.imageio.ImageIO;
public class BlurredImage {
private static final int RESIZE_RATIO = 5;
public static void main(String... args) throws IOException {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat originalImage = Imgcodecs.imread("line_login.png");
Mat blurredImage = new Mat(originalImage.rows(), originalImage.cols(), originalImage.type());
Imgproc.GaussianBlur(originalImage, blurredImage, new Size(45, 45), 0);
Size size = blurredImage.size();
Mat resizedImage = new Mat();
Imgproc.resize(blurredImage, resizedImage,
new Size(size.width / RESIZE_RATIO, size.height / RESIZE_RATIO));
Imgcodecs.imwrite("blurred_image.png", resizedImage);
// final ByteArrayOutputStream os = new ByteArrayOutputStream();
// try
// {
// ImageIO.write(blurredImage, "png", os);
// System.out.println(Base64.getEncoder().encodeToString(os.toByteArray()));
// }
// catch (final IOException ioe)
// {
// throw new UncheckedIOException(ioe);
// }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment