OpenCV Aruco Markers在工业相机上无法识别

时间:2017-09-13 10:11:54

标签: c++ opencv aruco

我正致力于在工业自动化技术C2相机上检测ARUCO标记,这些相机旨在检测三角测量扫描仪中的激光条纹,但它们也可以捕获图像。 我的问题是,无论我使用的相机如何,除了前面提到的相机之外,都会检测到相同的标记。 我的代码的最小工作示例如下:

#include <opencv2/highgui.hpp>
#include <opencv2/aruco/charuco.hpp>

using namespace std;
using namespace cv;

int main(int argc, char *argv[]) {

int squaresX = 10;
int squaresY = 7;
float squareLength = 28;
float markerLength = 19;
int dictionaryId = 6;
bool showRejected = true;
bool refindStrategy = true;

Ptr<aruco::DetectorParameters> detectorParams = aruco::DetectorParameters::create();

Ptr<aruco::Dictionary> dictionary =
    aruco::getPredefinedDictionary(aruco::PREDEFINED_DICTIONARY_NAME(dictionaryId));

// create charuco board object
Ptr<aruco::CharucoBoard> charucoboard =
    aruco::CharucoBoard::create(squaresX, squaresY, squareLength, markerLength, dictionary);
Ptr<aruco::Board> board = charucoboard.staticCast<aruco::Board>();

Mat image = imread("C:\\Users\\Piotrek\\Desktop\\calib\\022.jpg"), imageCopy;

vector< int > markerIds, charucoIds;
vector< vector< Point2f > > markerCorners, rejectedMarkers;
vector< Point2f > charucoCorners;

// detect markers
aruco::detectMarkers(image, dictionary, markerCorners, markerIds, detectorParams,
    rejectedMarkers);

image.copyTo(imageCopy);
if (markerIds.size() > 0) {
    aruco::drawDetectedMarkers(imageCopy, markerCorners);
}

if (showRejected && rejectedMarkers.size() > 0)
    aruco::drawDetectedMarkers(imageCopy, rejectedMarkers, noArray(), Scalar(100, 0, 255));

//display results
imshow("out", imageCopy);
waitKey(0);

return 0;
}

Sample image from camera:

问题在于检测到标记但是由于未知原因它们被拒绝:

Rejected markers

我使用的是OpenCV 3.1。

2 个答案:

答案 0 :(得分:1)

问题解决了。我必须翻转图像,现在可以完美地检测到标记。

答案 1 :(得分:0)

是的,在x方向上翻转图像会解决它。

opencv cv::flip(image, flippedImage, 1)