Маркер ArUco не может быть обнаружен библиотекой OpenCV ArUco в JAVAJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Маркер ArUco не может быть обнаружен библиотекой OpenCV ArUco в JAVA

Сообщение Anonymous »

Я работал над проектом, в котором мне нужно было обнаружить маркеры ArUco на изображениях, снятых веб-камерой. Я следил за документацией, пока не обнаружил, что Java-реализация модуля OpenCV ArUco отличается от того, что было описано в документации, и отклонился от поиска собственного способа обнаружения маркеров ArUco. Вот минимальный воспроизводимый пример:

Код: Выделить всё

public class Main {
public static void main(String[] args) {
OpenCV.loadLocally();

// ---------------------------------------------------------------
// Adding the marker to detect in the dictionary.
byte[][] marker =
{{0, 1, 1, 0, 0, 1}, {0, 1, 1, 0, 1, 0}, {1, 1, 0, 0, 0, 0},
{1, 0, 0, 1, 1, 0}, {0, 0, 1, 1, 0, 0}, {0, 0, 1, 1, 0, 0}};

Mat mat = new Mat(6, 6, CvType.CV_8UC1);
for (int i = 0; i < 6; i++)
for (int j = 0; j < 6; j++)
mat.put(i, j, marker[i][j]);
Mat compressed = Dictionary.getByteListFromBits(mat);

Dictionary dict = new Dictionary(compressed, 6);
ArucoDetector detector = new ArucoDetector(dict);

// ---------------------------------------------------------------
// Initializing webcam (/dev/video0) and looping
VideoCapture cap = new VideoCapture("/dev/video0");

while (cap.isOpened()) {
Mat image = new Mat();

cap.read(image);
if (image.empty())
continue;

ArrayList corners = new ArrayList();
Mat ids = new Mat();

try {
detector.detectMarkers(image, corners, ids);
if (!corners.isEmpty())                         // If the marker is detected,
System.out.println(corners.size());         // this should print something.
} catch (CvException e) {
System.out.println(e.getMessage());
}
}
}
}
(Библиотека обнаружения OpenCV и ArUco установлена ​​Gradle)
Приведенный выше код был написан для обнаружения маркера в центре изображения.
Заранее благодарим за помощь, при необходимости я предоставлю дополнительную информацию.

Изменить:< /p>
Как описано во многих документах, сообщениях в блогах и вопросах о stackoverflow, я попробовал метод getPredependentDictionary, но получил следующую ошибку:

Код: Выделить всё

            ArucoDetector detector = new ArucoDetector(Aruco.getPredefinedDictionary(Aruco.DICT_6X6_250));
^
constructor ArucoDetector.ArucoDetector(long) is not applicable
(argument mismatch; org.opencv.aruco.Dictionary cannot be converted to long)
constructor ArucoDetector.ArucoDetector(org.opencv.objdetect.Dictionary) is not applicable
(argument mismatch; org.opencv.aruco.Dictionary cannot be converted to org.opencv.objdetect.Dictionary)
Вот код исходного вопроса с измененным словарем.

Код: Выделить всё

public class Main {
public static void main(String[] args) {
OpenCV.loadLocally();

// ---------------------------------------------------------------
// Adding the marker to detect in the dictionary.
byte[][] marker =
{{0, 1, 1, 0, 0, 1}, {0, 1, 1, 0, 1, 0}, {1, 1, 0, 0, 0, 0},
{1, 0, 0, 1, 1, 0}, {0, 0, 1, 1, 0, 0}, {0, 0, 1, 1, 0, 0}};

Mat mat = new Mat(6, 6, CvType.CV_8UC1);
for (int i = 0; i < 6; i++)
for (int j = 0; j < 6; j++)
mat.put(i, j, marker[i][j]);
Mat compressed = Dictionary.getByteListFromBits(mat);

// Dictionary dict = new Dictionary(compressed, 6);
ArucoDetector detector = new ArucoDetector(Aruco.getPredefinedDictionary(Aruco.DICT_6X6_250));

// ---------------------------------------------------------------
// Initializing webcam (/dev/video0) and looping
VideoCapture cap = new VideoCapture("/dev/video0");

while (cap.isOpened()) {
Mat image = new Mat();

cap.read(image);
if (image.empty())
continue;

ArrayList corners = new ArrayList();
Mat ids = new Mat();

try {
detector.detectMarkers(image, corners, ids);
if (!corners.isEmpty())                         // If the marker is detected,
System.out.println(corners.size());         // this should print something.
} catch (CvException e) {
System.out.println(e.getMessage());
}
}
}
}
Я также попытался преобразовать возвращаемое значение getPredefineDictionary в org.opencv.objdetect.Dictionary, что требуется для org.opencv.objdetect.ArucoDetector< /code>, но кастинг также не удался.


Подробнее здесь: https://stackoverflow.com/questions/787 ... ry-in-java
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»