Код: Выделить всё
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());
}
}
}
}
Приведенный выше код был написан для обнаружения маркера в центре изображения.
Заранее благодарим за помощь, при необходимости я предоставлю дополнительную информацию.
Изменить:< /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());
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... ry-in-java