40 providerName = getProperty<std::string>(
"providerName").getValue();
41 usingImageProvider(providerName);
43 offeringTopic(getProperty<std::string>(
"TrackingErrorTopicName").getValue());
45 offeringTopic(getProperty<std::string>(
"DebugObserverName").getValue());
47 frameRate = getProperty<float>(
"Framerate").getValue();
49 useChessboard = getProperty<bool>(
"UseChessBoard").getValue();
51 chessboardWidth = getProperty<int>(
"Chessboard.Width").getValue();
52 chessboardHeight = getProperty<int>(
"Chessboard.Height").getValue();
57 std::unique_lock lock(imageMutex);
60 imageProviderPrx = getProxy<visionx::ImageProviderInterfacePrx>(providerName);
62 cameraImages =
new CByteImage*[2];
67 debugObserver = getTopic<DebugObserverInterfacePrx>(getProperty<std::string>(
"DebugObserverName").getValue());
69 prx = getTopic<TrackingErrorListenerPrx>(getProperty<std::string>(
"TrackingErrorTopicName").getValue());
71 imageWidth = imageProviderPrx->getImageFormat().dimension.width;
72 imageHeight = imageProviderPrx->getImageFormat().dimension.height;
74 enableResultImages(1, imageProviderPrx->getImageFormat().dimension, imageProviderPrx->getImageFormat().type);
83 std::unique_lock lock(imageMutex);
85 if (!waitForImages(getProperty<std::string>(
"providerName").getValue(), 1000))
87 ARMARX_WARNING <<
"Timeout while waiting for camera images (>1000ms)";
91 int numImages = getImages(cameraImages);
99 IplImage* ppIplImages[1] = { IplImageAdaptor::Adapt(cameraImages[0]) };
103 cv::Mat resultImage = cv::cvarrToMat(ppIplImages[0]);
104 cv::cvtColor(resultImage, grayImage, cv::COLOR_BGR2GRAY);
106 std::vector< cv::Point2f > features;
108 cv::Size size = cv::Size(chessboardWidth, chessboardHeight);
114 bool foundCorners = cv::findChessboardCorners(grayImage, size, features, cv::CALIB_CB_ADAPTIVE_THRESH + cv::CALIB_CB_NORMALIZE_IMAGE);
118 float avgX = 0.f, avgY = 0.f;
119 for (cv::Point2f point : features)
124 avgX /= features.size();
125 avgY /= features.size();
127 cv::Point2f imgCenter(imageWidth / 2, imageHeight / 2);
128 cv::Point2f chessboardCenter(avgX, avgY);
129 cv::Point2f point(avgX, imageHeight / 2);
130 cv::circle(resultImage, chessboardCenter, 2, CV_RGB(255, 0, 0), -1);
131 cv::circle(resultImage, imgCenter, 2, CV_RGB(255, 0, 0), -1);
132 cv::line(resultImage, chessboardCenter, imgCenter, CV_RGB(0, 0, 255), 1);
133 cv::line(resultImage, chessboardCenter, point, CV_RGB(0, 255, 0), 1);
134 cv::line(resultImage, imgCenter, point, CV_RGB(0, 255, 0), 1);
136 float trackingErrorX = avgX - (imageWidth / 2);
137 float trackingErrorY = avgY - (imageHeight / 2);
139 float angleX = (trackingErrorX / imageWidth) * 59.7;
140 float angleY = (trackingErrorY / imageHeight) * 44.775;
144 debugValues[
"trackingErrorX"] =
new Variant(trackingErrorX);
145 debugValues[
"trackingErrorY"] =
new Variant(trackingErrorY);
146 debugValues[
"angleX"] =
new Variant(angleX);
147 debugValues[
"angleY"] =
new Variant(angleY);
150 debugObserver->setDebugChannel(
"TrackingError", debugValues);
153 prx->reportNewTrackingError(trackingErrorX, trackingErrorY, angleX, angleY);
169 CByteImage* resultImages[1] = { IplImageAdaptor::Adapt(ppIplImages[0]) };
170 provideResultImages(resultImages);
174 fpsCounter.assureFPS(frameRate);