30 #include <Calibration/Calibration.h>
31 #include <Image/ByteImage.h>
32 #include <Image/ImageProcessor.h>
33 #include <Image/IplImageAdaptor.h>
37 #include <opencv2/highgui/highgui.hpp>
38 #include <opencv2/imgproc/imgproc_c.h>
48 #ifdef OLP_SHOW_RESULT_IMAGES
58 m_pOldVisualizationImageIpl = cvCloneImage(m_pIplImageLeft);
61 this->calibration = calibration;
72 int nMaxColors = 1000;
73 colors =
new CvScalar[nMaxColors];
74 colors[0] = cvScalar(255, 20, 20);
75 colors[1] = cvScalar(0, 0, 255);
76 colors[2] = cvScalar(0, 240, 255);
77 colors[3] = cvScalar(0, 255, 0);
78 colors[4] = cvScalar(255, 255, 0);
79 colors[5] = cvScalar(255, 0, 255);
80 colors[6] = cvScalar(45, 200, 105);
81 colors[7] = cvScalar(180, 240, 150);
82 colors[8] = cvScalar(160, 30, 55);
83 colors[9] = cvScalar(230, 130, 70);
84 colors[10] = cvScalar(70, 190, 210);
85 colors[11] = cvScalar(75, 160, 110);
86 colors[12] = cvScalar(150, 210, 155);
87 colors[13] = cvScalar(150, 30, 180);
88 colors[14] = cvScalar(210, 80, 55);
89 colors[15] = cvScalar(120, 120, 120);
90 colors[16] = cvScalar(170, 70, 75);
91 colors[17] = cvScalar(170, 200, 175);
92 colors[18] = cvScalar(40, 70, 75);
93 colors[19] = cvScalar(220, 70, 190);
95 for (
int n = 20;
n < nMaxColors;
n++)
97 colors[
n] = cvScalar(20 + rand() / (RAND_MAX / 235),
98 20 + rand() / (RAND_MAX / 235),
99 20 + rand() / (RAND_MAX / 235));
107 screenshotFileName.append(
"hyp0000.bmp");
109 segmentationImageFileName.append(
"segm0000.bmp");
111 segmentedCameraImageFileName.append(
"segmcam0000.bmp");
112 screenshotCounter = 0;
117 #ifdef OLP_SHOW_RESULT_IMAGES
118 cv::destroyWindow(
"Hypotheses (left)");
120 cv::destroyWindow(
"Confirmed hypotheses");
123 cvReleaseImage(&m_pIplImageLeft);
124 cvReleaseImage(&m_pIplImageRight);
125 cvReleaseImage(&m_pOldVisualizationImageIpl);
126 delete screenshotImage;
127 delete segmentationImage;
128 delete segmentedCameraImage;
133 const CByteImage* pByteImageColorRight,
136 std::vector<CMSERDescriptor3D*>& aAllMSERs,
137 std::vector<CMSERDescriptor3D*>& aCorrespondingMSERs,
138 bool bConfirmedHypotheses,
139 CByteImage* pResultImageLeft,
140 CByteImage* pResultImageRight,
141 const bool bMakeScreenshot,
142 const bool bIsLeftImage)
150 #ifdef OLP_SHOW_RESULT_IMAGES
151 cvReleaseImage(&m_pOldVisualizationImageIpl);
152 m_pOldVisualizationImageIpl = cvCloneImage(m_pIplImageLeft);
161 ((uchar*)(m_pIplImageLeft->imageData +
162 j * m_pIplImageLeft->widthStep))[i * m_pIplImageLeft->nChannels + 2] =
164 ((uchar*)(m_pIplImageLeft->imageData +
165 j * m_pIplImageLeft->widthStep))[i * m_pIplImageLeft->nChannels + 1] =
166 pByteImageColorLeft->pixels[3 * (
OLP_IMG_WIDTH * j + i) + 1];
167 ((uchar*)(m_pIplImageLeft->imageData +
168 j * m_pIplImageLeft->widthStep))[i * m_pIplImageLeft->nChannels + 0] =
169 pByteImageColorLeft->pixels[3 * (
OLP_IMG_WIDTH * j + i) + 2];
171 ((uchar*)(m_pIplImageRight->imageData +
172 j * m_pIplImageRight->widthStep))[i * m_pIplImageRight->nChannels + 2] =
174 ((uchar*)(m_pIplImageRight->imageData +
175 j * m_pIplImageRight->widthStep))[i * m_pIplImageRight->nChannels + 1] =
176 pByteImageColorRight->pixels[3 * (
OLP_IMG_WIDTH * j + i) + 1];
177 ((uchar*)(m_pIplImageRight->imageData +
178 j * m_pIplImageRight->widthStep))[i * m_pIplImageRight->nChannels + 0] =
179 pByteImageColorRight->pixels[3 * (
OLP_IMG_WIDTH * j + i) + 2];
183 #ifndef OLP_USE_ARMAR3_ARMAR3_4
187 CByteImage* pScreenshotImageGrey =
189 ImageProcessor::ConvertImage(pByteImageColorLeft, pScreenshotImageGrey);
190 ImageProcessor::ConvertImage(pScreenshotImageGrey, screenshotImage);
191 delete pScreenshotImageGrey;
202 const int nNumHypotheses = aHypotheses.GetSize();
205 CvFont cFont1, cFont2, cFont3;
206 cvInitFont(&cFont1, CV_FONT_HERSHEY_SIMPLEX, 0.9, 0.9, 0, 3);
207 cvInitFont(&cFont2, CV_FONT_HERSHEY_SIMPLEX, 0.9, 0.9, 0, 2);
208 cvInitFont(&cFont3, CV_FONT_HERSHEY_SIMPLEX, 0.3, 0.3, 0, 1);
214 char* pcN =
new char[4];
216 for (
int n = nNumHypotheses - 1;
n >= 0;
n--)
218 cColor = colors[aHypotheses[
n]->nHypothesisNumber];
219 const int nHypothesisSize =
220 aHypotheses[
n]->aNewPoints.size() + aHypotheses[
n]->aVisibleConfirmedPoints.size();
223 Vec2d* pPoints2D =
new Vec2d[nHypothesisSize];
225 for (
int i = 0; i < (int)aHypotheses[
n]->aNewPoints.size(); i++)
227 calibration->WorldToImageCoordinates(
228 aHypotheses[
n]->aNewPoints.at(i)->vPosition, pPoints2D[i],
false);
231 for (
int i = 0; i < (int)aHypotheses[
n]->aVisibleConfirmedPoints.size(); i++)
233 calibration->WorldToImageCoordinates(
234 aHypotheses[
n]->aVisibleConfirmedPoints.at(i)->vPosition,
235 pPoints2D[aHypotheses[
n]->aNewPoints.size() + i],
240 for (
int i = 0; i < nHypothesisSize; i++)
247 m_pIplImageLeft, cvPoint((
int)pPoints2D[i].
x, (
int)pPoints2D[i].y), 0, cColor);
250 if (!bConfirmedHypotheses)
252 cvCircle(m_pIplImageLeft,
253 cvPoint((
int)pPoints2D[i].
x, (
int)pPoints2D[i].y),
259 if ((!bConfirmedHypotheses) && bMakeScreenshot)
262 screenshotImage, (
int)pPoints2D[i].
x, (
int)pPoints2D[i].y, cColor);
264 else if (bMakeScreenshot)
266 MarkUnconfirmedPoint(
267 screenshotImage, (
int)pPoints2D[i].
x, (
int)pPoints2D[i].y, cColor);
286 for (
int i = aHypotheses[
n]->aNewPoints.size(); i < nHypothesisSize; i++)
290 m_pIplImageLeft, cvPoint((
int)pPoints2D[i].
x, (
int)pPoints2D[i].y), 1, cColor);
292 m_pIplImageLeft, cvPoint((
int)pPoints2D[i].
x, (
int)pPoints2D[i].y), 2, cColor);
297 screenshotImage, (
int)pPoints2D[i].
x, (
int)pPoints2D[i].y, cColor);
304 for (
int n = nNumHypotheses - 1;
n >= 0;
n--)
306 cColor = colors[aHypotheses[
n]->nHypothesisNumber];
307 sprintf(pcN,
"%d", aHypotheses[
n]->nHypothesisNumber);
309 calibration->WorldToImageCoordinates(aHypotheses[
n]->vCenter, vCenter2d,
false);
311 cvCircle(m_pIplImageLeft, cvPoint((
int)vCenter2d.x, (
int)vCenter2d.y), 4, cColor);
312 cvCircle(m_pIplImageLeft, cvPoint((
int)vCenter2d.x, (
int)vCenter2d.y), 7, cColor);
313 cvPutText(m_pIplImageLeft,
315 cvPoint((
int)vCenter2d.x, (
int)vCenter2d.y),
317 cvScalar(0, 0, 255));
319 m_pIplImageLeft, pcN, cvPoint((
int)vCenter2d.x, (
int)vCenter2d.y), &cFont2, cColor);
326 #ifndef OLP_USE_ARMAR3_ARMAR3_4
331 screenshotImage->SaveToFile(screenshotFileName.c_str());
333 if (nNumHypotheses > 0)
336 aHypotheses[0], calibration, segmentationImage);
340 ImageProcessor::Zero(segmentationImage);
344 segmentationImage->SaveToFile(segmentationImageFileName.c_str());
348 segmentedCameraImage->pixels[3 * i] =
349 pByteImageColorLeft->pixels[3 * i] * segmentationImage->pixels[i] / 255;
350 segmentedCameraImage->pixels[3 * i + 1] =
351 pByteImageColorLeft->pixels[3 * i + 1] * segmentationImage->pixels[i] / 255;
352 segmentedCameraImage->pixels[3 * i + 2] =
353 pByteImageColorLeft->pixels[3 * i + 2] * segmentationImage->pixels[i] / 255;
357 segmentedCameraImage->SaveToFile(segmentedCameraImageFileName.c_str());
365 if (pResultImageLeft)
372 ((uchar*)(m_pIplImageLeft->imageData +
373 j * m_pIplImageLeft->widthStep))[i * m_pIplImageLeft->nChannels + 2];
375 ((uchar*)(m_pIplImageLeft->imageData +
376 j * m_pIplImageLeft->widthStep))[i * m_pIplImageLeft->nChannels + 1];
378 ((uchar*)(m_pIplImageLeft->imageData +
379 j * m_pIplImageLeft->widthStep))[i * m_pIplImageLeft->nChannels + 0];
384 if (pResultImageRight)
391 ((uchar*)(m_pOldVisualizationImageIpl->imageData +
392 j * m_pOldVisualizationImageIpl
393 ->widthStep))[i * m_pOldVisualizationImageIpl->nChannels + 2];
395 ((uchar*)(m_pOldVisualizationImageIpl->imageData +
396 j * m_pOldVisualizationImageIpl
397 ->widthStep))[i * m_pOldVisualizationImageIpl->nChannels + 1];
399 ((uchar*)(m_pOldVisualizationImageIpl->imageData +
400 j * m_pOldVisualizationImageIpl
401 ->widthStep))[i * m_pOldVisualizationImageIpl->nChannels + 0];
406 #ifdef OLP_SHOW_RESULT_IMAGES
409 if (bConfirmedHypotheses)
439 #ifdef OLP_SHOW_RESULT_IMAGES
442 if (bConfirmedHypotheses)
457 CHypothesisVisualization::MarkConfirmedPoint(CByteImage* pImage,
int x,
int y, CvScalar cColor)
464 pImage->pixels[(int)(3 * ((y - 2) * pImage->width +
x) + 0)] = (
char)cColor.val[2];
465 pImage->pixels[(int)(3 * ((y - 2) * pImage->width +
x) + 1)] = (char)cColor.val[1];
466 pImage->pixels[(
int)(3 * ((y - 2) * pImage->width +
x) + 2)] = (
char)cColor.val[0];
468 pImage->pixels[(int)(3 * ((y - 1) * pImage->width +
x) + 0)] = (char)cColor.val[2];
469 pImage->pixels[(
int)(3 * ((y - 1) * pImage->width +
x) + 1)] = (
char)cColor.val[1];
470 pImage->pixels[(int)(3 * ((y - 1) * pImage->width +
x) + 2)] = (char)cColor.val[0];
472 pImage->pixels[(
int)(3 * (y * pImage->width +
x) + 0)] = (char)cColor.val[2];
473 pImage->pixels[(
int)(3 * (y * pImage->width +
x) + 1)] = (char)cColor.val[1];
474 pImage->pixels[(
int)(3 * (y * pImage->width +
x) + 2)] = (char)cColor.val[0];
476 pImage->pixels[(
int)(3 * ((y + 1) * pImage->width +
x) + 0)] = (
char)cColor.val[2];
477 pImage->pixels[(int)(3 * ((y + 1) * pImage->width +
x) + 1)] = (char)cColor.val[1];
478 pImage->pixels[(
int)(3 * ((y + 1) * pImage->width +
x) + 2)] = (
char)cColor.val[0];
480 pImage->pixels[(int)(3 * ((y + 2) * pImage->width +
x) + 0)] = (char)cColor.val[2];
481 pImage->pixels[(
int)(3 * ((y + 2) * pImage->width +
x) + 1)] = (
char)cColor.val[1];
482 pImage->pixels[(int)(3 * ((y + 2) * pImage->width +
x) + 2)] = (char)cColor.val[0];
484 pImage->pixels[(
int)(3 * (y * pImage->width +
x - 2) + 0)] = (char)cColor.val[2];
485 pImage->pixels[(
int)(3 * (y * pImage->width +
x - 2) + 1)] = (char)cColor.val[1];
486 pImage->pixels[(
int)(3 * (y * pImage->width +
x - 2) + 2)] = (char)cColor.val[0];
488 pImage->pixels[(
int)(3 * (y * pImage->width +
x - 1) + 0)] = (char)cColor.val[2];
489 pImage->pixels[(
int)(3 * (y * pImage->width +
x - 1) + 1)] = (char)cColor.val[1];
490 pImage->pixels[(
int)(3 * (y * pImage->width +
x - 1) + 2)] = (char)cColor.val[0];
492 pImage->pixels[(
int)(3 * (y * pImage->width +
x + 1) + 0)] = (char)cColor.val[2];
493 pImage->pixels[(
int)(3 * (y * pImage->width +
x + 1) + 1)] = (char)cColor.val[1];
494 pImage->pixels[(
int)(3 * (y * pImage->width +
x + 1) + 2)] = (char)cColor.val[0];
496 pImage->pixels[(
int)(3 * (y * pImage->width +
x + 2) + 0)] = (char)cColor.val[2];
497 pImage->pixels[(
int)(3 * (y * pImage->width +
x + 2) + 1)] = (char)cColor.val[1];
498 pImage->pixels[(
int)(3 * (y * pImage->width +
x + 2) + 2)] = (char)cColor.val[0];
502 CHypothesisVisualization::MarkUnconfirmedPoint(CByteImage* pImage,
int x,
int y, CvScalar cColor)
509 pImage->pixels[(int)(3 * (y * pImage->width +
x) + 0)] = (
char)cColor.val[2];
510 pImage->pixels[(int)(3 * (y * pImage->width +
x) + 1)] = (
char)cColor.val[1];
511 pImage->pixels[(int)(3 * (y * pImage->width +
x) + 2)] = (
char)cColor.val[0];