Java opencv Laplacian Degenction размытие дает низкие оценки для четких изображений - как установить правильный порог? ⇐ JAVA
Java opencv Laplacian Degenction размытие дает низкие оценки для четких изображений - как установить правильный порог?
Я строю инструмент обнаружения размывающихся изображений на основе Java с помощью OpenCV. Чтобы
повысить точность, я реализовал метод дисперсии на основе плитки, чтобы оценить локальное размытие, а не глобальное размытие.package com.example.validator;
import org.opencv.core.*;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class TileBasedBlurDetection {
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
public static boolean isImageBlurry(String imagePath, double threshold, int tileSize) {
Mat image = Imgcodecs.imread(imagePath, Imgcodecs.IMREAD_GRAYSCALE);
if (image.empty()) {
System.err.println("Could not load image: " + imagePath);
return false;
}
int height = image.rows();
int width = image.cols();
double maxBlurScore = 0;
for (int y = 0; y < height; y += tileSize) {
for (int x = 0; x < width; x += tileSize) {
int roiWidth = Math.min(tileSize, width - x);
int roiHeight = Math.min(tileSize, height - y);
Rect roi = new Rect(x, y, roiWidth, roiHeight);
Mat tile = new Mat(image, roi);
Mat laplacian = new Mat();
Imgproc.Laplacian(tile, laplacian, CvType.CV_64F);
MatOfDouble mean = new MatOfDouble();
MatOfDouble stddev = new MatOfDouble();
Core.meanStdDev(laplacian, mean, stddev);
double variance = Math.pow(stddev.get(0, 0)[0], 2);
if (variance > maxBlurScore) {
maxBlurScore = variance;
}
}
}
System.out.println("Max blur score from tiles: " + maxBlurScore);
return maxBlurScore < threshold;
}
public static void main(String[] args) {
String imagePath = "D:\\id_ card image\\Family Card Sample (ID Card).jpg";
double blurThreshold = 100.0;
int tileSize = 100;
boolean isBlurry = isImageBlurry(imagePath, blurThreshold, tileSize);
System.out.println("Is image blurry? " + isBlurry);
}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... ges-how-to
Я строю инструмент обнаружения размывающихся изображений на основе Java с помощью OpenCV. Чтобы
повысить точность, я реализовал метод дисперсии на основе плитки, чтобы оценить локальное размытие, а не глобальное размытие.package com.example.validator;
import org.opencv.core.*;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class TileBasedBlurDetection {
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
public static boolean isImageBlurry(String imagePath, double threshold, int tileSize) {
Mat image = Imgcodecs.imread(imagePath, Imgcodecs.IMREAD_GRAYSCALE);
if (image.empty()) {
System.err.println("Could not load image: " + imagePath);
return false;
}
int height = image.rows();
int width = image.cols();
double maxBlurScore = 0;
for (int y = 0; y < height; y += tileSize) {
for (int x = 0; x < width; x += tileSize) {
int roiWidth = Math.min(tileSize, width - x);
int roiHeight = Math.min(tileSize, height - y);
Rect roi = new Rect(x, y, roiWidth, roiHeight);
Mat tile = new Mat(image, roi);
Mat laplacian = new Mat();
Imgproc.Laplacian(tile, laplacian, CvType.CV_64F);
MatOfDouble mean = new MatOfDouble();
MatOfDouble stddev = new MatOfDouble();
Core.meanStdDev(laplacian, mean, stddev);
double variance = Math.pow(stddev.get(0, 0)[0], 2);
if (variance > maxBlurScore) {
maxBlurScore = variance;
}
}
}
System.out.println("Max blur score from tiles: " + maxBlurScore);
return maxBlurScore < threshold;
}
public static void main(String[] args) {
String imagePath = "D:\\id_ card image\\Family Card Sample (ID Card).jpg";
double blurThreshold = 100.0;
int tileSize = 100;
boolean isBlurry = isImageBlurry(imagePath, blurThreshold, tileSize);
System.out.println("Is image blurry? " + isBlurry);
}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... ges-how-to
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение