Example #1
0
void
vpImageSimulator::getRoi(const unsigned int Iwidth, const unsigned int Iheight, const vpCameraParameters cam, vpPoint* point, vpRect &rectangle)
{
  double top = Iheight+1;
  double bottom = -1;
  double right = -1;
  double left= Iwidth+1;
  for( int i = 0; i < 4; i++)
  {
    double u=0,v=0;
    vpMeterPixelConversion::convertPoint(cam,point[i].get_x(),point[i].get_y(),u,v);
    if (v < top) top = v;
    if (v > bottom) bottom = v;
    if (u < left) left = u;
    if (u > right) right = u;
  }
  if (top < 0) top = 0;
  if(top >= Iheight) top = Iheight-1;
  if (bottom < 0) bottom = 0;
  if(bottom >= Iheight) bottom = Iheight-1;
  if(left < 0) left = 0;
  if(left >= Iwidth) left = Iwidth-1;
  if(right < 0) right = 0;
  if(right >= Iwidth) right = Iwidth-1;
    
  rectangle.setTop(top);
  rectangle.setBottom(bottom);
  rectangle.setLeft(left);
  rectangle.setRight(right);
}
Example #2
0
/*!

  Check if an image point belongs to a rectangle.
  
  \param rect : the rectangle.
  
  \return Returns true if the point belongs to the rectangle.

*/
bool vpImagePoint::inRectangle( const vpRect &rect ) const
{
  return ( this->i <= rect.getBottom() && 
	   this->i >= rect.getTop() &&
	   this->j <= rect.getRight() &&
	   this->j >= rect.getLeft());
}
list VISPConverter::convertToBoost(const vpRect &from) {
  list l;

  l.append(from.getTop());
  l.append(from.getLeft());
  l.append(from.getWidth());
  l.append(from.getHeight());

  return l;
}
Example #4
0
/*!

  Computes the SURF points in only a part of the current image I and
  try to matched them with the points in the reference list. The part
  of the image is a rectangle. The parameters of this rectangle must
  be given in pixel. Only the matched points are stored.

  \param I : The gray scaled image where the points are computed.

  \param rectangle : The rectangle which defines the interesting part
  of the image.

  \return the number of point which have been matched.
*/
unsigned int vpKeyPointSurf::matchPoint(const vpImage<unsigned char> &I,
			       const vpRect& rectangle)
{
  vpImagePoint iP;
  iP.set_i(rectangle.getTop());
  iP.set_j(rectangle.getLeft());
  return (this->matchPoint(I, iP,
			   (unsigned int)rectangle.getHeight(),
			   (unsigned int)rectangle.getWidth()));
}
/*!
  Compute the points of interest in the specified region of the current image 
  and try to recognise them using the trained classifier. The matched pairs can 
  be found with the getMatchedPointByRef function. The homography between the 
  two planar surfaces is also computed.
  
  \param I : The gray scaled image where the points are computed.
  \param rectangle : The rectangle defining the ROI.
  
  \return True if the surface has been found.
*/
bool 
vpPlanarObjectDetector::matchPoint(const vpImage<unsigned char> &I, const vpRect rectangle)
{
  vpImagePoint iP;
  iP.set_i(rectangle.getTop());
  iP.set_j(rectangle.getLeft());
  return (this->matchPoint(I, iP,
			   (unsigned int)rectangle.getHeight(),
			   (unsigned int)rectangle.getWidth()));
}
Example #6
0
/*!
  Display a rectangle.

  \param rectangle : Rectangle characteristics.
  \param color : Rectangle color.
  \param fill : When set to true fill the rectangle.
  \param thickness : Thickness of the four lines used to display the
  rectangle.

  \warning The thickness can not be set if the display uses the d3d library.
*/
void vpDisplayWin32::displayRectangle( const vpRect &rectangle,
                                       const vpColor &color, bool fill,
			                                 unsigned int thickness )
{
  //wait if the window is not initialized
  waitForInit();
  vpImagePoint topLeft;
  topLeft.set_i(rectangle.getTop());
  topLeft.set_j(rectangle.getLeft());
  window.renderer->drawRect(topLeft,
                            static_cast<unsigned int>( rectangle.getWidth() ),
                            static_cast<unsigned int>( rectangle.getHeight() ),
			                      color, fill, thickness);
}
/*!
  Train the classifier on a region of the entire image. The region is a 
  rectangle. The parameters of this rectangle must be given in pixel. It also 
  includes the training of the fern classifier.
  
  \param _I : The image use to train the classifier.
  \param _rectangle : The rectangle defining the region of interest (ROI).
  
  \return The number of reference points.
*/
unsigned int 
vpPlanarObjectDetector::buildReference(const vpImage<unsigned char> &_I,
		       const vpRect _rectangle)
{
  unsigned int res = fern.buildReference(_I, _rectangle);
  
  vpImagePoint iP = _rectangle.getTopLeft();
  
  modelROI.x = (int)iP.get_u();
  modelROI.y = (int)iP.get_v();
  modelROI.width = (int)_rectangle.getWidth();
  modelROI.height = (int)_rectangle.getHeight(); 

  initialiseRefCorners(modelROI);  
  
  return res;
}
/*!
  Return the average intensity in the region.

  \param I: Grayscale image.
  \param rect: Bounding box corresponding to the desired region.
  \return The average intensity in the region or -1.0 if the region is outside of the image.
*/
double vpCascadeClassifier::getMeanIntensity(const vpImage<unsigned char> &I, const vpRect &rect) {
  bool is_inside = (rect.getLeft() >= 0 && rect.getTop() >= 0
      && rect.getRight() < I.getWidth() && rect.getBottom() < I.getHeight());

  unsigned int total = 0;
  if(is_inside) {
    for(unsigned int i = (unsigned int) rect.getTop(); i < (unsigned int) rect.getBottom(); i++) {
      for(unsigned int j = (unsigned int) rect.getLeft(); j < (unsigned int) rect.getRight(); j++) {
        total += I[i][j];
      }
    }

    return total / ((double) rect.getWidth()*rect.getHeight());
  }

  return -1.0;
}
Example #9
0
/*!
  Display a rectangle.

  \param rectangle : Rectangle characteristics.
  \param color : Rectangle color.
  \param fill : When set to true fill the rectangle.

  \param thickness : Thickness of the four lines used to display the
  rectangle. This parameter is only useful when \e fill is set to
  false.

*/
void
vpDisplayGTK::displayRectangle ( const vpRect &rectangle,
				 const vpColor &color, bool fill,
				 unsigned int thickness )
{
  if (displayHasBeenInitialized)
  {
    if (color.id < vpColor::id_unknown)
      gdk_gc_set_foreground(gc, col[color.id]);
    else {
      gdkcolor.red   = 256 * color.R;
      gdkcolor.green = 256 * color.G;
      gdkcolor.blue  = 256 * color.B;
      gdk_colormap_alloc_color(colormap,&gdkcolor,FALSE,TRUE);
      gdk_gc_set_foreground(gc, &gdkcolor);     
    }

    if ( thickness == 1 ) thickness = 0;

    gdk_gc_set_line_attributes(gc, (gint)thickness, GDK_LINE_SOLID, GDK_CAP_BUTT,
			       GDK_JOIN_BEVEL) ;

    if (fill == false)
      gdk_draw_rectangle(background, gc, FALSE,
                       vpMath::round( rectangle.getLeft() ), 
		       vpMath::round( rectangle.getTop() ),
		       vpMath::round( rectangle.getWidth()-1 ), 
		       vpMath::round( rectangle.getHeight()-1 ) );

    else
      gdk_draw_rectangle(background, gc, TRUE,
                       vpMath::round( rectangle.getLeft() ), 
		       vpMath::round( rectangle.getTop() ),
		       vpMath::round( rectangle.getWidth()-1 ), 
		       vpMath::round( rectangle.getHeight()-1 ) );

    if (thickness > 1)
      gdk_gc_set_line_attributes(gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT,
                                 GDK_JOIN_BEVEL) ;
  }
  else
  {
    vpERROR_TRACE("GTK not initialized " ) ;
    throw(vpDisplayException(vpDisplayException::notInitializedError,
                             "GTK not initialized")) ;
  }
}
/*!
  Return the percentage of overlapping for two rectangles.

  \param r1: First rectangle.
  \param r2: Second rectangle.
  \return The percentage of overlapping or -1.0 if they don't overlap.
*/
double vpCascadeClassifier::getPercentageOfOverlap(const vpRect &r1, const vpRect &r2) {
  double left = (std::max)(r1.getLeft(), r2.getLeft());
  double right = (std::min)(r1.getRight(), r2.getRight());
  double bottom = (std::min)(r1.getBottom(), r2.getBottom());
  double top = (std::max)(r1.getTop(), r2.getTop());

  if(left < right && bottom > top) {
    double overlap_area = (right-left)*(bottom-top);
    double r1_area = r1.getWidth()*r1.getHeight();
    double r2_area = r2.getWidth()*r2.getHeight();
    double percentage = overlap_area / (r1_area + r2_area - overlap_area) * 100.0;
    return percentage;
  }

  return -1;
}
/*!
  Return the median intensitie in the region.

  \param I: Grayscale image.
  \param rect: Bounding box corresponding to the desired region.
  \return The median intensitie in the region or -1.0 if the region is outside of the image.
*/
double vpCascadeClassifier::getMedianIntensity(const vpImage<unsigned char> &I, const vpRect &rect) {
  bool is_inside = (rect.getLeft() >= 0 && rect.getTop() >= 0
      && rect.getRight() < I.getWidth() && rect.getBottom() < I.getHeight());

  if(is_inside) {
    std::vector<double> v((size_t) (rect.getWidth() * rect.getHeight()));
    for(unsigned int i = (unsigned int) rect.getTop(); i < (unsigned int) rect.getBottom(); i++) {
      for(unsigned int j = (unsigned int) rect.getLeft(); j < (unsigned int) rect.getRight(); j++) {
        size_t index = (size_t) ( (i-rect.getTop())*rect.getWidth() + (j-rect.getLeft()) );
        v[index] = I[i][j];
      }
    }

    return getMedian(v);
  }

  return -1.0;
}
/*!
  Display a rectangle.

  \param rectangle : Rectangle characteristics.
  \param color : Rectangle color.
  \param fill : When set to true fill the rectangle.

  \param thickness : Thickness of the four lines used to display the
  rectangle. This parameter is only useful when \e fill is set to
  false.

*/
void
vpDisplayOpenCV::displayRectangle(const vpRect &rectangle,
                                  const vpColor &color, bool fill,
                                  unsigned int thickness)
{
  if (displayHasBeenInitialized)
  {
    if (fill == false) {
      if (color.id < vpColor::id_unknown) {
	cvRectangle( background,
		     cvPoint( vpMath::round( rectangle.getLeft() ),
			      vpMath::round( rectangle.getBottom() ) ),
		     cvPoint( vpMath::round( rectangle.getRight() ),
			      vpMath::round( rectangle.getTop() ) ),
		     col[color.id], (int)thickness);
      }
      else {
	cvcolor = CV_RGB(color.R, color.G, color.B) ;
	cvRectangle( background,
		     cvPoint( vpMath::round( rectangle.getLeft() ),
			      vpMath::round( rectangle.getBottom() ) ),
		     cvPoint( vpMath::round( rectangle.getRight() ),
			      vpMath::round( rectangle.getTop() ) ),
		     cvcolor, (int)thickness);

      }
    }
    else {
      if (color.id < vpColor::id_unknown) {
	cvRectangle( background,
		     cvPoint( vpMath::round( rectangle.getLeft() ),
			      vpMath::round( rectangle.getBottom() ) ),
		     cvPoint( vpMath::round( rectangle.getRight() ),
			      vpMath::round( rectangle.getTop() ) ),
		     col[color.id], CV_FILLED);
      }
      else {
	cvcolor = CV_RGB(color.R, color.G, color.B) ;
	cvRectangle( background,
		     cvPoint( vpMath::round( rectangle.getLeft() ),
			      vpMath::round( rectangle.getBottom() ) ),
		     cvPoint( vpMath::round( rectangle.getRight() ),
			      vpMath::round( rectangle.getTop() ) ),
		     cvcolor, CV_FILLED);
      }
    }
  }
  else
  {
    vpERROR_TRACE("OpenCV not initialized " ) ;
    throw(vpDisplayException(vpDisplayException::notInitializedError,
                             "OpenCV not initialized")) ;
  }
}