From: Pierre M. <sid...@us...> - 2005-06-02 20:07:35
|
Update of /cvsroot/robotflow/RobotFlow/Vision/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22620 Modified Files: VisualROI.cc PFState2VisualROI.cc Log Message: Added methods for rectangular ROI. Index: VisualROI.cc =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Vision/src/VisualROI.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** VisualROI.cc 26 May 2005 19:45:09 -0000 1.5 --- VisualROI.cc 2 Jun 2005 20:07:26 -0000 1.6 *************** *** 106,164 **** void VisualROI::DrawROI(IplImage *io_frame, const unsigned char *i_color) const { ! if (!io_frame) { ! throw new GeneralException ("VisualROI::DrawROI : invalid image reference.",__FILE__,__LINE__); ! } ! ! if (!i_color) { ! throw new GeneralException ("VisualROI::DrawROI : invalid color reference.",__FILE__,__LINE__); ! } ! ! if (!m_perim) { ! throw new GeneralException ("VisualROI::DrawROI : cannot draw ROI with uninitialized region data.",__FILE__,__LINE__); ! } ! ! unsigned char *p_pixels = (unsigned char *)io_frame->imageData; ! const short *p_perim = this->GetCstPerim(); ! int imgWidth = io_frame->width; ! int imgHeight = io_frame->height; ! int numChannels = io_frame->nChannels; ! int i, c, x, y; ! short deltaX, deltaY; ! bool broken = true; ! ! // Start at the top center of the region ! x = m_xCen; ! y = m_yCen; ! p_pixels += numChannels*(y*imgWidth + x); ! ! // Overlay region of interest ! for (i=m_perimLength; i>0; i--) { ! deltaX = *p_perim++; ! deltaY = *p_perim++; ! x += deltaX; ! y += deltaY; ! ! // Draw only if region is visible ! if (y>0 && y<imgHeight && x>0 && x<imgWidth) { ! if (!broken) { ! // Relative position ! p_pixels += numChannels*(deltaY*imgWidth + deltaX); ! } ! else { ! // Absolute position ! p_pixels = (unsigned char *)(io_frame->imageData + numChannels*(y*imgWidth + x)); ! broken = false; ! } ! ! for (c=0; c<numChannels; c++) { ! *p_pixels++ = i_color[c]; ! } ! ! p_pixels -= numChannels; ! } ! else { ! broken = true; } } } --- 106,125 ---- void VisualROI::DrawROI(IplImage *io_frame, const unsigned char *i_color) const { ! try { ! switch(m_type) { ! case e_VISUALROI_rectangular: ! DrawRectangularRegion(io_frame, i_color); ! break; ! case e_VISUALROI_elliptical: ! DrawEllipticalRegion(io_frame, i_color); ! break; ! case e_VISUALROI_unknown: ! default: ! throw new GeneralException ("VisualROI::DrawROI : unknown region geometric type",__FILE__,__LINE__); } } + catch (BaseException *e) { + throw e->add(new GeneralException("Exception caught in VisualROI::VisualROI:",__FILE__,__LINE__)); + } } *************** *** 166,232 **** unsigned char *io_pixels, const unsigned char *i_color) const { ! if (!io_pixels) { ! throw new GeneralException ("VisualROI::DrawROI : invalid pixels reference.",__FILE__,__LINE__); ! } ! ! if (!i_color) { ! throw new GeneralException ("VisualROI::DrawROI : invalid color reference.",__FILE__,__LINE__); ! } ! ! if (!m_perim) { ! throw new GeneralException ("VisualROI::DrawROI : cannot draw ROI with uninitialized region data.",__FILE__,__LINE__); ! } ! ! unsigned char *p_pixels = io_pixels; ! const short *p_perim = this->GetCstPerim(); ! int imgWidth = i_width; ! int imgHeight = i_height; ! int numChannels = i_numChannels; ! int i, c, x, y; ! short deltaX, deltaY; ! bool broken = true; ! ! // Start at the top center of the region ! x = m_xCen; ! y = m_yCen; ! p_pixels += numChannels*(y*imgWidth + x); ! ! // Overlay region of interest ! for (i=m_perimLength; i>0; i--) { ! deltaX = *p_perim++; ! deltaY = *p_perim++; ! x += deltaX; ! y += deltaY; ! ! // Draw only if region is visible ! if (y>0 && y<imgHeight && x>0 && x<imgWidth) { ! if (!broken) { ! // Relative position ! p_pixels += numChannels*(deltaY*imgWidth + deltaX); ! } ! else { ! // Absolute position ! p_pixels = (unsigned char *)(io_pixels + numChannels*(y*imgWidth + x)); ! broken = false; ! } ! ! for (c=0; c<numChannels; c++) { ! *p_pixels++ = i_color[c]; ! } ! ! p_pixels -= numChannels; ! } ! else { ! broken = true; } } } void VisualROI::Reset(int i_hsX, int i_hsY, int i_angle) { - delete [] m_perim; - delete [] m_normVects; - delete [] m_mask; - m_hsX = i_hsX; m_hsY = i_hsY; --- 127,150 ---- unsigned char *io_pixels, const unsigned char *i_color) const { ! try { ! switch(m_type) { ! case e_VISUALROI_rectangular: ! DrawRectangularRegion(i_width, i_height, i_numChannels, io_pixels, i_color); ! break; ! case e_VISUALROI_elliptical: ! DrawEllipticalRegion(i_width, i_height, i_numChannels, io_pixels, i_color); ! break; ! case e_VISUALROI_unknown: ! default: ! throw new GeneralException ("VisualROI::DrawROI : unknown region geometric type",__FILE__,__LINE__); } } + catch (BaseException *e) { + throw e->add(new GeneralException("Exception caught in VisualROI::VisualROI:",__FILE__,__LINE__)); + } } void VisualROI::Reset(int i_hsX, int i_hsY, int i_angle) { m_hsX = i_hsX; m_hsY = i_hsY; *************** *** 385,388 **** --- 303,453 ---- // Private routines // + void VisualROI::DrawRectangularRegion(IplImage *io_frame, const unsigned char *i_color) const + { + CvPoint ulc, lrc; + CvScalar color; + + if (io_frame->nChannels == 3) { + color = CV_RGB(i_color[0], i_color[1], i_color[2]); + } + else if (io_frame->nChannels == 1) { + color = cvRealScalar((double)(i_color[0])); + } + else { + throw new GeneralException ("VisualROI::DrawRectangularRegion : can only draw region with an image with 1 or 3 channel(s).",__FILE__,__LINE__); + } + + ulc.x = m_xCen - m_hsX; + ulc.y = m_yCen - m_hsY; + lrc.x = m_xCen + m_hsX; + lrc.y = m_yCen + m_hsY; + cvRectangle(io_frame, ulc, lrc, color, 1); + } + + void VisualROI::DrawEllipticalRegion(IplImage *io_frame, const unsigned char *i_color) const + { + if (!io_frame) { + throw new GeneralException ("VisualROI::DrawROI : invalid image reference.",__FILE__,__LINE__); + } + + if (!i_color) { + throw new GeneralException ("VisualROI::DrawROI : invalid color reference.",__FILE__,__LINE__); + } + + if (!m_perim) { + throw new GeneralException ("VisualROI::DrawROI : cannot draw ROI with uninitialized region data.",__FILE__,__LINE__); + } + + unsigned char *p_pixels = (unsigned char *)io_frame->imageData; + const short *p_perim = this->GetCstPerim(); + int imgWidth = io_frame->width; + int imgHeight = io_frame->height; + int numChannels = io_frame->nChannels; + int i, c, x, y; + short deltaX, deltaY; + bool broken = true; + + // Start at the top center of the region + x = m_xCen; + y = m_yCen; + p_pixels += numChannels*(y*imgWidth + x); + + // Overlay region of interest + for (i=m_perimLength; i>0; i--) { + deltaX = *p_perim++; + deltaY = *p_perim++; + x += deltaX; + y += deltaY; + + // Draw only if region is visible + if (y>0 && y<imgHeight && x>0 && x<imgWidth) { + if (!broken) { + // Relative position + p_pixels += numChannels*(deltaY*imgWidth + deltaX); + } + else { + // Absolute position + p_pixels = (unsigned char *)(io_frame->imageData + numChannels*(y*imgWidth + x)); + broken = false; + } + + for (c=0; c<numChannels; c++) { + *p_pixels++ = i_color[c]; + } + + p_pixels -= numChannels; + } + else { + broken = true; + } + } + } + + void VisualROI::DrawRectangularRegion(int i_width, int i_height, int i_numChannels, + unsigned char *io_pixels, const unsigned char *i_color) const + { + throw new GeneralException ("VisualROI::DrawRectangularRegion : method not yet implemented.",__FILE__,__LINE__); + } + + void VisualROI::DrawEllipticalRegion(int i_width, int i_height, int i_numChannels, + unsigned char *io_pixels, const unsigned char *i_color) const + { + if (!io_pixels) { + throw new GeneralException ("VisualROI::DrawROI : invalid pixels reference.",__FILE__,__LINE__); + } + + if (!i_color) { + throw new GeneralException ("VisualROI::DrawROI : invalid color reference.",__FILE__,__LINE__); + } + + if (!m_perim) { + throw new GeneralException ("VisualROI::DrawROI : cannot draw ROI with uninitialized region data.",__FILE__,__LINE__); + } + + unsigned char *p_pixels = io_pixels; + const short *p_perim = this->GetCstPerim(); + int imgWidth = i_width; + int imgHeight = i_height; + int numChannels = i_numChannels; + int i, c, x, y; + short deltaX, deltaY; + bool broken = true; + + // Start at the top center of the region + x = m_xCen; + y = m_yCen; + p_pixels += numChannels*(y*imgWidth + x); + + // Overlay region of interest + for (i=m_perimLength; i>0; i--) { + deltaX = *p_perim++; + deltaY = *p_perim++; + x += deltaX; + y += deltaY; + + // Draw only if region is visible + if (y>0 && y<imgHeight && x>0 && x<imgWidth) { + if (!broken) { + // Relative position + p_pixels += numChannels*(deltaY*imgWidth + deltaX); + } + else { + // Absolute position + p_pixels = (unsigned char *)(io_pixels + numChannels*(y*imgWidth + x)); + broken = false; + } + + for (c=0; c<numChannels; c++) { + *p_pixels++ = i_color[c]; + } + + p_pixels -= numChannels; + } + else { + broken = true; + } + } + } + void VisualROI::MakeEllipticalRegion() { *************** *** 396,399 **** --- 461,468 ---- int x, y, xOff, yOff, xAbs, yAbs; int curX, curY; + + delete [] m_perim; + delete [] m_normVects; + delete [] m_mask; // Number of iterations in loops below *************** *** 467,471 **** void VisualROI::MakeRectangularRegion() { ! throw new GeneralException ("VisualROI::MakeRectangularRegion : method not yet implemented.",__FILE__,__LINE__); } --- 536,542 ---- void VisualROI::MakeRectangularRegion() { ! if (m_angle != 0) { ! throw new GeneralException ("VisualROI::MakeRectangularRegion : method not yet implemented for angle different from 0.",__FILE__,__LINE__); ! } } Index: PFState2VisualROI.cc =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Vision/src/PFState2VisualROI.cc,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PFState2VisualROI.cc 26 May 2005 19:49:37 -0000 1.1 --- PFState2VisualROI.cc 2 Jun 2005 20:07:26 -0000 1.2 *************** *** 47,50 **** --- 47,55 ---- * @parameter_description Flag indicating to use the ROI rotation angle in the particle's state. * + * @parameter_name ROI_REGION_TYPE + * @parameter_type int + * @parameter_value 0 + * @parameter_description Geometric type for the ROI region (refer to enum e_VISUALROI_type in VisualROI.h). + * * @input_name IN_PARTICLE * @input_type PFGenericParticle *************** *** 69,72 **** --- 74,78 ---- m_useScale = dereference_cast<bool>(parameters.get("USE_SCALE")); m_useAngle = dereference_cast<bool>(parameters.get("USE_ROTATION_ANGLE")); + m_roiType = dereference_cast<int>(parameters.get("ROI_REGION_TYPE")); // First 2 elements of state is center position x,y *************** *** 85,89 **** // Allocate ROI m_curROI = RCPtr<VisualROI>(new VisualROI()); ! m_curROI->SetType(e_VISUALROI_elliptical); } --- 91,95 ---- // Allocate ROI m_curROI = RCPtr<VisualROI>(new VisualROI()); ! m_curROI->SetType(e_VISUALROI_type(m_roiType)); } *************** *** 141,144 **** --- 147,151 ---- bool m_useScale; bool m_useAngle; + int m_roiType; unsigned int m_stateSize; |