调用findChessboardCorners时获取角点的坐标

时间:2017-07-31 13:40:26

标签: java opencv computer-vision javacv

嘿,我在版本1.3.2中使用此库org.bytedeco.javacpp.opencv_core中的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()时,有没有办法获取角落的坐标?

1 个答案:

答案 0 :(得分:0)

我没有找到方法findChessboardCorners的解决方案,但我找到了svFindChessboardCorners的另一种方法import static org.bytedeco.javacpp.opencv_calib3d.*;

  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]);