Я работал над проектом, в котором мне нужно было обнаружить маркеры 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>, но кастинг также не удался.
Я работал над проектом, в котором мне нужно было обнаружить маркеры ArUco на изображениях, снятых веб-камерой. Я следил за документацией, пока не обнаружил, что Java-реализация модуля OpenCV ArUco отличается от того, что было описано в документации, и отклонился от поиска собственного способа обнаружения маркеров ArUco. Вот минимальный воспроизводимый пример: [code]public class Main { public static void main(String[] args) { OpenCV.loadLocally();
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()); } } } } [/code] (Библиотека обнаружения OpenCV и ArUco установлена Gradle) Приведенный выше код был написан для обнаружения маркера в центре изображения. Заранее благодарим за помощь, при необходимости я предоставлю дополнительную информацию.
Изменить:< /p> Как описано во многих документах, сообщениях в блогах и вопросах о stackoverflow, я попробовал метод getPredependentDictionary, но получил следующую ошибку: [code] 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) [/code] Вот код исходного вопроса с измененным словарем. [code]public class Main { public static void main(String[] args) { OpenCV.loadLocally();
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()); } } } } [/code] Я также попытался преобразовать возвращаемое значение getPredefineDictionary в org.opencv.objdetect.Dictionary, что требуется для org.opencv.objdetect.ArucoDetector< /code>, но кастинг также не удался.
Я использую OpenCV для обнаружения маркеров Aruco в кадре, снятом веб-камерой. Проблема возникла из-за следующего фрагмента кода:
public class Detector {
private final ArucoDetector detector;
public Detector() {
DetectorParameters param = new...
Я работаю над приложением, которое обнаруживает маркеры Aruco OpenCV в реальном времени с помощью камеры.
Приведенный ниже Java-код используется для предварительной обработки изображения, обнаружения маркеров и, наконец, выделения и отображения их в...
Я работаю над приложением, которое обнаруживает маркеры Aruco OpenCV в реальном времени с помощью камеры.
Приведенный ниже Java-код используется для предварительной обработки изображения, обнаружения маркеров и, наконец, выделения и отображения их в...
Я работаю над приложением, которое обнаруживает маркеры Aruco OpenCV в реальном времени с помощью камеры.
Приведенный ниже Java-код используется для предварительной обработки изображения, обнаружения маркеров и, наконец, выделения и отображения их в...