下面是我最小代码:
package charucotest;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.CvType;
import org.opencv.core.Scalar;
import org.opencv.core.*;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.opencv.objdetect.QRCodeDetector;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import org.opencv.core.MatOfByte;
import org.opencv.core.Size;
import org.opencv.videoio.VideoCapture;
import java.util.concurrent.*;
import org.opencv.aruco.Aruco;
import org.opencv.aruco.ArucoDetector;
import org.opencv.aruco.DetectorParameters;
import org.opencv.aruco.Dictionary;
import java.util.ArrayList;
import java.util.List;
public class App {
public static JFrame frame;
public static String currentpath;
public static void main(String[] args) {
currentpath = System.getProperty("user.dir");
System.out.println("current path is:" + currentpath);
System.load(currentpath+"/lib/libopencv_java460.so");
Dictionary dictionary= Aruco.getPredefinedDictionary(Aruco.DICT_4X4_50);
DetectorParameters parameters= DetectorParameters.create();
//parameters.set_cornerRefinementMethod(Aruco.CORNER_REFINE_NONE);
//parameters.set_cornerRefinementMethod();
ArucoDetector detector= new ArucoDetector(dictionary,parameters);
System.out.println("Welcome to OpenCV " + Core.VERSION);
List<Mat> corners = new ArrayList<Mat>();
//List<Mat> rejectedImgPoints = new ArrayList<Mat>();
Mat ids = new Mat();
// [12,12]
Mat img2 = Imgcodecs.imread(currentpath+"/assets/card.jpg");
detector.detectMarkers(img2, corners, ids);
System.out.println("OpenCV Mat: " + ids.dump());
System.out.println("OpenCV size idds " + ids.size());
System.out.println("OpenCV Mat Corner: " + String.valueOf(corners.size()));
}
}
opencv库已经加载,如果我有两行代码,我可以解码qrcode,所以它可以工作。
但当我试图读取我的资产卡时:
它一无所获,
我已经验证了aruco代码似乎是好的4x4 50:https://chev.me/arucogen/
所以我不知道为什么它没有找到arcuo代码。
测试项目如下:
https://github.com/bussiere/charucotest/blob/master/app/src/main/java/charucotest/App.java编辑:此讨论板的事件:
或者通过将检测字典更改为6x6并使用此板(qrcode检测工作正常)
1条答案
按热度按时间vuktfyat1#
ArUco标记不应直接放置在图像的边缘。标记需要一个完整和宽的黑色边框。
请检查此修改后的输入图像:
更新
当我用这个图像运行上面的代码时,我得到了下面的输出: