嘿,我正在使用这个库 org.bytedeco.javacpp.opencv_core
版本 1.3.2 中的 JavaCV 作为 gradle 依赖项。
我正在运行这段代码来获取棋盘上的角,但我无法获取每个检测到的角的坐标:
Mat imageCorners = new Mat();
Size boardSize = new Size(9,6);
boolean found = findChessboardCorners(capturedFrame,boardSize,imageCorners,CV_CALIB_CB_ADAPTIVE_THRESH+CV_CALIB_CB_NORMALIZE_IMAGE);
但是对于该方法检测到的54个角,存储角的矩阵只有54x1的大小。
if (found) {
FloatRawIndexer sI = imageCorners.createIndexer();
for (int y = 0; y < imageCorners.rows(); y++) {
for (int x = 0; x < imageCorners.cols(); x++) {
logger.debug("Row: " + y + " Column " + x);
logger.debug(sI.get(y, x));
}
}
}
日志文件如下所示:
14:57:50.057 [main] DEBUG JavaCVTransformation2 - Row: 0 Column 0
14:57:50.059 [main] DEBUG JavaCVTransformation2 - 164.02007
14:57:50.059 [main] DEBUG JavaCVTransformation2 - Row: 1 Column 0
14:57:50.059 [main] DEBUG JavaCVTransformation2 - 224.07906
14:57:50.059 [main] DEBUG JavaCVTransformation2 - Row: 2 Column 0
14:57:50.059 [main] DEBUG JavaCVTransformation2 - 283.54288
14:57:50.059 [main] DEBUG JavaCVTransformation2 - Row: 3 Column 0
14:57:50.059 [main] DEBUG JavaCVTransformation2 - 343.4154
14:57:50.060 [main] DEBUG JavaCVTransformation2 - Row: 4 Column 0
14:57:50.060 [main] DEBUG JavaCVTransformation2 - 402.7718
14:57:50.060 [main] DEBUG JavaCVTransformation2 - Row: 5 Column 0
14:57:50.060 [main] DEBUG JavaCVTransformation2 - 462.38278
14:57:50.060 [main] DEBUG JavaCVTransformation2 - Row: 6 Column 0
14:57:50.060 [main] DEBUG JavaCVTransformation2 - 522.2342
14:57:50.060 [main] DEBUG JavaCVTransformation2 - Row: 7 Column 0
14:57:50.060 [main] DEBUG JavaCVTransformation2 - 580.99805
14:57:50.061 [main] DEBUG JavaCVTransformation2 - Row: 8 Column 0
14:57:50.061 [main] DEBUG JavaCVTransformation2 - 640.7774
14:57:50.061 [main] DEBUG JavaCVTransformation2 - Row: 9 Column 0
14:57:50.061 [main] DEBUG JavaCVTransformation2 - 151.04564
绘制它非常好,所以我认为每个角的某个地方必须有两个坐标。
drawChessboardCorners(capturedFrame, boardSize, imageCorners, found);
有没有办法在调用findChessboardCorners()
时获取角的坐标?
最佳答案
我没有找到方法findChessboardCorners
的解决方案,但我从import static org.bytedeco.javacpp.opencv_calib3d.*; 找到了另一种方法
与它一起工作。svFindChessboardCorners
;
IplImage iplImage = frameConverter.convertToIplImage(capturedFrame);
CvSize boardSize = new CvSize(9, 6);
float[] corners = new float[108];
int found = cvFindChessboardCorners(iplImage, boardSize, corners);
此方法会将角坐标存储在 float 组中,因此访问第一个点将如下所示:
Point2f srcp1 = new Point2f(corners[0], corners[1]);
关于java - 调用 findChessboardCorners 时获取角的坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45417582/