コード例 #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")) ;
  }
}
コード例 #2
0
ファイル: vpImagePoint.cpp プロジェクト: 976717326/visp
/*!

  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());
}
コード例 #3
0
/*!
  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;
}
コード例 #4
0
ファイル: vpDisplayGTK.cpp プロジェクト: ricsp/visp
/*!
  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")) ;
  }
}
コード例 #5
0
/*!
  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;
}
コード例 #6
0
/*!
  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;
}
コード例 #7
0
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;
}
コード例 #8
0
/*!
  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()));
}
コード例 #9
0
ファイル: vpKeyPointSurf.cpp プロジェクト: 976717326/visp
/*!

  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()));
}
コード例 #10
0
ファイル: vpDisplayWin32.cpp プロジェクト: CaptainTrunks/visp
/*!
  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);
}