29 #include <Image/ByteImage.h>
30 #include <Image/ImageProcessor.h>
31 #include <Image/IplImageAdaptor.h>
32 #include <Calibration/Calibration.h>
36 #include <opencv2/highgui/highgui.hpp>
37 #include <opencv2/imgproc/imgproc_c.h>
49 #ifdef OLP_SHOW_RESULT_IMAGES
59 m_pOldVisualizationImageIpl = cvCloneImage(m_pIplImageLeft);
62 this->calibration = calibration;
73 int nMaxColors = 1000;
74 colors =
new CvScalar[nMaxColors];
75 colors[0] = cvScalar(255, 20, 20);
76 colors[1] = cvScalar(0, 0, 255);
77 colors[2] = cvScalar(0, 240, 255);
78 colors[3] = cvScalar(0, 255, 0);
79 colors[4] = cvScalar(255, 255, 0);
80 colors[5] = cvScalar(255, 0, 255);
81 colors[6] = cvScalar(45, 200, 105);
82 colors[7] = cvScalar(180, 240, 150);
83 colors[8] = cvScalar(160, 30, 55);
84 colors[9] = cvScalar(230, 130, 70);
85 colors[10] = cvScalar(70, 190, 210);
86 colors[11] = cvScalar(75, 160, 110);
87 colors[12] = cvScalar(150, 210, 155);
88 colors[13] = cvScalar(150, 30, 180);
89 colors[14] = cvScalar(210, 80, 55);
90 colors[15] = cvScalar(120, 120, 120);
91 colors[16] = cvScalar(170, 70, 75);
92 colors[17] = cvScalar(170, 200, 175);
93 colors[18] = cvScalar(40, 70, 75);
94 colors[19] = cvScalar(220, 70, 190);
96 for (
int n = 20; n < nMaxColors; n++)
98 colors[n] = cvScalar(20 + rand() / (RAND_MAX / 235), 20 + rand() / (RAND_MAX / 235), 20 + rand() / (RAND_MAX / 235));
106 screenshotFileName.append(
"hyp0000.bmp");
108 segmentationImageFileName.append(
"segm0000.bmp");
110 segmentedCameraImageFileName.append(
"segmcam0000.bmp");
111 screenshotCounter = 0;
119 #ifdef OLP_SHOW_RESULT_IMAGES
120 cv::destroyWindow(
"Hypotheses (left)");
122 cv::destroyWindow(
"Confirmed hypotheses");
125 cvReleaseImage(&m_pIplImageLeft);
126 cvReleaseImage(&m_pIplImageRight);
127 cvReleaseImage(&m_pOldVisualizationImageIpl);
128 delete screenshotImage;
129 delete segmentationImage;
130 delete segmentedCameraImage;
137 const CSIFTFeatureArray& aAllPoints, std::vector<CMSERDescriptor3D*>& aAllMSERs, std::vector<CMSERDescriptor3D*>& aCorrespondingMSERs,
138 bool bConfirmedHypotheses, CByteImage* pResultImageLeft, CByteImage* pResultImageRight,
const bool bMakeScreenshot,
const bool bIsLeftImage)
146 #ifdef OLP_SHOW_RESULT_IMAGES
147 cvReleaseImage(&m_pOldVisualizationImageIpl);
148 m_pOldVisualizationImageIpl = cvCloneImage(m_pIplImageLeft);
157 ((uchar*)(m_pIplImageLeft->imageData + j * m_pIplImageLeft->widthStep))[i * m_pIplImageLeft->nChannels + 2] = pByteImageColorLeft->pixels[3 * (
OLP_IMG_WIDTH * j + i)];
158 ((uchar*)(m_pIplImageLeft->imageData + j * m_pIplImageLeft->widthStep))[i * m_pIplImageLeft->nChannels + 1] = pByteImageColorLeft->pixels[3 * (
OLP_IMG_WIDTH * j + i) + 1];
159 ((uchar*)(m_pIplImageLeft->imageData + j * m_pIplImageLeft->widthStep))[i * m_pIplImageLeft->nChannels + 0] = pByteImageColorLeft->pixels[3 * (
OLP_IMG_WIDTH * j + i) + 2];
161 ((uchar*)(m_pIplImageRight->imageData + j * m_pIplImageRight->widthStep))[i * m_pIplImageRight->nChannels + 2] = pByteImageColorRight->pixels[3 * (
OLP_IMG_WIDTH * j + i)];
162 ((uchar*)(m_pIplImageRight->imageData + j * m_pIplImageRight->widthStep))[i * m_pIplImageRight->nChannels + 1] = pByteImageColorRight->pixels[3 * (
OLP_IMG_WIDTH * j + i) + 1];
163 ((uchar*)(m_pIplImageRight->imageData + j * m_pIplImageRight->widthStep))[i * m_pIplImageRight->nChannels + 0] = pByteImageColorRight->pixels[3 * (
OLP_IMG_WIDTH * j + i) + 2];
168 #ifndef OLP_USE_ARMAR3_ARMAR3_4
173 ImageProcessor::ConvertImage(pByteImageColorLeft, pScreenshotImageGrey);
174 ImageProcessor::ConvertImage(pScreenshotImageGrey, screenshotImage);
175 delete pScreenshotImageGrey;
188 const int nNumHypotheses = aHypotheses.GetSize();
191 CvFont cFont1, cFont2, cFont3;
192 cvInitFont(&cFont1, CV_FONT_HERSHEY_SIMPLEX, 0.9, 0.9, 0, 3);
193 cvInitFont(&cFont2, CV_FONT_HERSHEY_SIMPLEX, 0.9, 0.9, 0, 2);
194 cvInitFont(&cFont3, CV_FONT_HERSHEY_SIMPLEX, 0.3, 0.3, 0, 1);
200 char* pcN =
new char[4];
202 for (
int n = nNumHypotheses - 1; n >= 0; n--)
204 cColor = colors[aHypotheses[n]->nHypothesisNumber];
205 const int nHypothesisSize = aHypotheses[n]->aNewPoints.size() + aHypotheses[n]->aVisibleConfirmedPoints.size();
208 Vec2d* pPoints2D =
new Vec2d[nHypothesisSize];
210 for (
int i = 0; i < (int)aHypotheses[n]->aNewPoints.size(); i++)
212 calibration->WorldToImageCoordinates(aHypotheses[n]->aNewPoints.at(i)->vPosition, pPoints2D[i],
false);
215 for (
int i = 0; i < (int)aHypotheses[n]->aVisibleConfirmedPoints.size(); i++)
217 calibration->WorldToImageCoordinates(aHypotheses[n]->aVisibleConfirmedPoints.at(i)->vPosition, pPoints2D[aHypotheses[n]->aNewPoints.size() + i],
false);
221 for (
int i = 0; i < nHypothesisSize; i++)
227 cvCircle(m_pIplImageLeft, cvPoint((
int)pPoints2D[i].x, (
int)pPoints2D[i].y), 0, cColor);
230 if (!bConfirmedHypotheses)
232 cvCircle(m_pIplImageLeft, cvPoint((
int)pPoints2D[i].x, (
int)pPoints2D[i].y), 1, cColor);
236 if ((!bConfirmedHypotheses) && bMakeScreenshot)
238 MarkConfirmedPoint(screenshotImage, (
int)pPoints2D[i].x, (
int)pPoints2D[i].y, cColor);
240 else if (bMakeScreenshot)
242 MarkUnconfirmedPoint(screenshotImage, (
int)pPoints2D[i].x, (
int)pPoints2D[i].y, cColor);
261 for (
int i = aHypotheses[n]->aNewPoints.size(); i < nHypothesisSize; i++)
264 cvCircle(m_pIplImageLeft, cvPoint((
int)pPoints2D[i].x, (
int)pPoints2D[i].y), 1, cColor);
265 cvCircle(m_pIplImageLeft, cvPoint((
int)pPoints2D[i].x, (
int)pPoints2D[i].y), 2, cColor);
269 MarkConfirmedPoint(screenshotImage, (
int)pPoints2D[i].x, (
int)pPoints2D[i].y, cColor);
276 for (
int n = nNumHypotheses - 1; n >= 0; n--)
278 cColor = colors[aHypotheses[n]->nHypothesisNumber];
279 sprintf(pcN,
"%d", aHypotheses[n]->nHypothesisNumber);
281 calibration->WorldToImageCoordinates(aHypotheses[n]->vCenter, vCenter2d,
false);
283 cvCircle(m_pIplImageLeft, cvPoint((
int)vCenter2d.x, (
int)vCenter2d.y), 4, cColor);
284 cvCircle(m_pIplImageLeft, cvPoint((
int)vCenter2d.x, (
int)vCenter2d.y), 7, cColor);
285 cvPutText(m_pIplImageLeft, pcN, cvPoint((
int)vCenter2d.x, (
int)vCenter2d.y), &cFont1, cvScalar(0, 0, 255));
286 cvPutText(m_pIplImageLeft, pcN, cvPoint((
int)vCenter2d.x, (
int)vCenter2d.y), &cFont2, cColor);
296 #ifndef OLP_USE_ARMAR3_ARMAR3_4
301 screenshotImage->SaveToFile(screenshotFileName.c_str());
303 if (nNumHypotheses > 0)
309 ImageProcessor::Zero(segmentationImage);
313 segmentationImage->SaveToFile(segmentationImageFileName.c_str());
317 segmentedCameraImage->pixels[3 * i] = pByteImageColorLeft->pixels[3 * i] * segmentationImage->pixels[i] / 255;
318 segmentedCameraImage->pixels[3 * i + 1] = pByteImageColorLeft->pixels[3 * i + 1] * segmentationImage->pixels[i] / 255;
319 segmentedCameraImage->pixels[3 * i + 2] = pByteImageColorLeft->pixels[3 * i + 2] * segmentationImage->pixels[i] / 255;
323 segmentedCameraImage->SaveToFile(segmentedCameraImageFileName.c_str());
332 if (pResultImageLeft)
338 pResultImageLeft->pixels[3 * (
OLP_IMG_WIDTH * j + i) + 0] = ((uchar*)(m_pIplImageLeft->imageData + j * m_pIplImageLeft->widthStep))[i * m_pIplImageLeft->nChannels + 2];
339 pResultImageLeft->pixels[3 * (
OLP_IMG_WIDTH * j + i) + 1] = ((uchar*)(m_pIplImageLeft->imageData + j * m_pIplImageLeft->widthStep))[i * m_pIplImageLeft->nChannels + 1];
340 pResultImageLeft->pixels[3 * (
OLP_IMG_WIDTH * j + i) + 2] = ((uchar*)(m_pIplImageLeft->imageData + j * m_pIplImageLeft->widthStep))[i * m_pIplImageLeft->nChannels + 0];
345 if (pResultImageRight)
351 pResultImageRight->pixels[3 * (
OLP_IMG_WIDTH * j + i) + 0] = ((uchar*)(m_pOldVisualizationImageIpl->imageData + j * m_pOldVisualizationImageIpl->widthStep))[i * m_pOldVisualizationImageIpl->nChannels + 2];
352 pResultImageRight->pixels[3 * (
OLP_IMG_WIDTH * j + i) + 1] = ((uchar*)(m_pOldVisualizationImageIpl->imageData + j * m_pOldVisualizationImageIpl->widthStep))[i * m_pOldVisualizationImageIpl->nChannels + 1];
353 pResultImageRight->pixels[3 * (
OLP_IMG_WIDTH * j + i) + 2] = ((uchar*)(m_pOldVisualizationImageIpl->imageData + j * m_pOldVisualizationImageIpl->widthStep))[i * m_pOldVisualizationImageIpl->nChannels + 0];
358 #ifdef OLP_SHOW_RESULT_IMAGES
361 if (bConfirmedHypotheses)
390 #ifdef OLP_SHOW_RESULT_IMAGES
393 if (bConfirmedHypotheses)
410 void CHypothesisVisualization::MarkConfirmedPoint(CByteImage* pImage,
int x,
int y, CvScalar cColor)
417 pImage->pixels[(int)(3 * ((y - 2)*pImage->width + x) + 0)] = (
char)cColor.val[2];
418 pImage->pixels[(int)(3 * ((y - 2)*pImage->width + x) + 1)] = (char)cColor.val[1];
419 pImage->pixels[(
int)(3 * ((y - 2)*pImage->width + x) + 2)] = (
char)cColor.val[0];
421 pImage->pixels[(int)(3 * ((y - 1)*pImage->width + x) + 0)] = (char)cColor.val[2];
422 pImage->pixels[(
int)(3 * ((y - 1)*pImage->width + x) + 1)] = (
char)cColor.val[1];
423 pImage->pixels[(int)(3 * ((y - 1)*pImage->width + x) + 2)] = (char)cColor.val[0];
425 pImage->pixels[(
int)(3 * (y * pImage->width + x) + 0)] = (char)cColor.val[2];
426 pImage->pixels[(
int)(3 * (y * pImage->width + x) + 1)] = (char)cColor.val[1];
427 pImage->pixels[(
int)(3 * (y * pImage->width + x) + 2)] = (char)cColor.val[0];
429 pImage->pixels[(
int)(3 * ((y + 1)*pImage->width + x) + 0)] = (
char)cColor.val[2];
430 pImage->pixels[(int)(3 * ((y + 1)*pImage->width + x) + 1)] = (char)cColor.val[1];
431 pImage->pixels[(
int)(3 * ((y + 1)*pImage->width + x) + 2)] = (
char)cColor.val[0];
433 pImage->pixels[(int)(3 * ((y + 2)*pImage->width + x) + 0)] = (char)cColor.val[2];
434 pImage->pixels[(
int)(3 * ((y + 2)*pImage->width + x) + 1)] = (
char)cColor.val[1];
435 pImage->pixels[(int)(3 * ((y + 2)*pImage->width + x) + 2)] = (char)cColor.val[0];
437 pImage->pixels[(
int)(3 * (y * pImage->width + x - 2) + 0)] = (char)cColor.val[2];
438 pImage->pixels[(
int)(3 * (y * pImage->width + x - 2) + 1)] = (char)cColor.val[1];
439 pImage->pixels[(
int)(3 * (y * pImage->width + x - 2) + 2)] = (char)cColor.val[0];
441 pImage->pixels[(
int)(3 * (y * pImage->width + x - 1) + 0)] = (char)cColor.val[2];
442 pImage->pixels[(
int)(3 * (y * pImage->width + x - 1) + 1)] = (char)cColor.val[1];
443 pImage->pixels[(
int)(3 * (y * pImage->width + x - 1) + 2)] = (char)cColor.val[0];
445 pImage->pixels[(
int)(3 * (y * pImage->width + x + 1) + 0)] = (char)cColor.val[2];
446 pImage->pixels[(
int)(3 * (y * pImage->width + x + 1) + 1)] = (char)cColor.val[1];
447 pImage->pixels[(
int)(3 * (y * pImage->width + x + 1) + 2)] = (char)cColor.val[0];
449 pImage->pixels[(
int)(3 * (y * pImage->width + x + 2) + 0)] = (char)cColor.val[2];
450 pImage->pixels[(
int)(3 * (y * pImage->width + x + 2) + 1)] = (char)cColor.val[1];
451 pImage->pixels[(
int)(3 * (y * pImage->width + x + 2) + 2)] = (char)cColor.val[0];
456 void CHypothesisVisualization::MarkUnconfirmedPoint(CByteImage* pImage,
int x,
int y, CvScalar cColor)
463 pImage->pixels[(int)(3 * (y * pImage->width + x) + 0)] = (
char)cColor.val[2];
464 pImage->pixels[(int)(3 * (y * pImage->width + x) + 1)] = (
char)cColor.val[1];
465 pImage->pixels[(int)(3 * (y * pImage->width + x) + 2)] = (
char)cColor.val[0];