Я пытаюсь исследовать три направления:
- Обнаружение лиц
- Обнаружение темных прямоугольников (поскольку портреты обычно представляют собой более темные фигуры на более ярком фоне)
- Извлечение имен людей из текстов, распознанных с помощью оптического распознавания символов
Буду очень признателен за любую помощь в обнаружении прямоугольников.
Я начал с Java и OpenCV 3.
Вот применен ли мой код к изображению:
Код: Выделить всё
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat source = Imgcodecs.imread("Path/to/image", Imgcodecs.CV_LOAD_IMAGE_ANYCOLOR);
Mat destination = new Mat(source.rows(), source.cols(), source.type());
Imgproc.cvtColor(source, destination, Imgproc.COLOR_RGB2GRAY);
Imgproc.GaussianBlur(destination, destination, new Size(5, 5), 0, 0, Core.BORDER_DEFAULT);
int threshold = 100;
Imgproc.Canny(destination, destination, 50, 100);
Imgproc.Canny(destination, destination, threshold, threshold*3);
[img]https://i.sstatic.net /KoxG5.jpg[/img]
Пытаемся найти контуры по краям сверху:
Код: Выделить всё
List contourDetections = new ArrayList();
Mat hierarchy = new Mat();
// Find contours
Imgproc.findContours(destination, contourDetections, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
// Draw contours
Imgproc.drawContours(source, contours, -1, new Scalar(255,0,0), 2);

Но не знаю, как извлечь прямоугольники из этих контуров, поскольку многие линии неполные.
Вернемся к краям и попытаемся найти вертикальные и горизонтальные линии с помощью HoughLinesP:
Код: Выделить всё
Mat lines = new Mat();
int thre = 50;
int minLineSize = 250;
int lineGap = 80;
int ignoreLinesShorter = 300;
Imgproc.HoughLinesP(destination, lines, 1, Math.PI/180, thre, minLineSize, lineGap);
for(int c = 0; c < lines.rows(); c++) {
double[] vec = lines.get(c, 0);
double x1 = vec[0],
y1 = vec[1],
x2 = vec[2],
y2 = vec[3];
// Filtering only verticat and horizontal lines
if(x1 == x2 || y1 == y2) {
// Filtering out short lines
if(Math.abs(x1 - x2) > ignoreLinesShorter || Math.abs(y1 - y2) > ignoreLinesShorter) {
Point start = new Point(x1, y1);
Point end = new Point(x2, y2);
// Draw line
Imgproc.line(source, start, end, new Scalar(0,0,255), 2);
}
}
}
[img]https://i .sstatic.net/CdADt.jpg[/img]
Как и в случае с контурами, я все еще не вижу правильных прямоугольников, которые я мог бы обнаружить. Не могли бы вы помочь мне с правильным направлением? Может быть, есть более простой способ выполнить эту задачу?
Подробнее здесь: https://stackoverflow.com/questions/451 ... ith-opencv