/*! Get the view of the virtual camera. Be careful, the image I is modified. The projected image is not added as an overlay! In this method you specify directly the image which is projected. \param I : The image used to store the result. \param Isrc : The image which is projected into \f$ I \f$. \param cam : The parameters of the virtual camera. */ void vpImageSimulator::getImage(vpImage<unsigned char> &I, vpImage<unsigned char> &Isrc, const vpCameraParameters &cam) { if (cleanPrevImage) { unsigned char col = (unsigned char)(0.2126 * bgColor.R + 0.7152 * bgColor.G + 0.0722 * bgColor.B); for (unsigned int i = 0; i < I.getHeight(); i++) { for (unsigned int j = 0; j < I.getWidth(); j++) { I[i][j] = col; } } } if(visible) { if(!needClipping) getRoi(I.getWidth(),I.getHeight(),cam,pt,rect); else getRoi(I.getWidth(),I.getHeight(),cam,ptClipped,rect); double top = rect.getTop(); double bottom = rect.getBottom(); double left = rect.getLeft(); double right= rect.getRight(); unsigned char *bitmap = I.bitmap; unsigned int width = I.getWidth(); vpImagePoint ip; int nb_point_dessine = 0; for (unsigned int i = (unsigned int)top; i < (unsigned int)bottom; i++) { for (unsigned int j = (unsigned int)left; j < (unsigned int)right; j++) { double x=0,y=0; ip.set_ij(i,j); vpPixelMeterConversion::convertPoint(cam,ip, x,y); ip.set_ij(y,x); unsigned char Ipixelplan = 0; if(getPixel(Isrc,ip,Ipixelplan)) { *(bitmap+i*width+j)=Ipixelplan; nb_point_dessine++; } } } } }
/*! Get the view of the virtual camera. Be carefull, the image I is modified. The projected image is not added as an overlay! \param I : The image used to store the result. \param cam : The parameters of the virtual camera. */ void vpImageSimulator::getImage(vpImage<unsigned char> &I, const vpCameraParameters cam) { int nb_point_dessine = 0; if (cleanPrevImage) { unsigned char col = (unsigned char)(0.2126 * bgColor.R + 0.7152 * bgColor.G + 0.0722 * bgColor.B); for (int i = (int)rect.getTop(); i < (int)rect.getBottom(); i++) { for (int j = (int)rect.getLeft(); j < (int)rect.getRight(); j++) { I[i][j] = col; } } } if(visible) { getRoi(I.getWidth(),I.getHeight(),cam,pt,rect); double top = rect.getTop(); double bottom = rect.getBottom(); double left = rect.getLeft(); double right= rect.getRight(); unsigned char *bitmap = I.bitmap; unsigned int width = I.getWidth(); vpImagePoint ip; for (int i = (int)top; i < (int)bottom; i++) { for (int j = (int)left; j < (int)right; j++) { double x=0,y=0; ip.set_ij(i,j); vpPixelMeterConversion::convertPoint(cam,ip, x,y); ip.set_ij(y,x); if (colorI == GRAY_SCALED) { unsigned char Ipixelplan = 0; if(getPixel(ip,Ipixelplan)) { *(bitmap+i*width+j)=Ipixelplan; nb_point_dessine++; } } else if (colorI == COLORED) { vpRGBa Ipixelplan; if(getPixel(ip,Ipixelplan)) { unsigned char pixelgrey = (unsigned char)(0.2126 * Ipixelplan.R + 0.7152 * Ipixelplan.G + 0.0722 * Ipixelplan.B); *(bitmap+i*width+j)=pixelgrey; nb_point_dessine++; } } } } } }
/*! Get the view of the virtual camera. Be carefull, the image I is modified. The projected image is not added as an overlay! In this method you specify directly the image which is projected. \param I : The image used to store the result. \param Isrc : The image which is projected into \f$ I \f$. \param cam : The parameters of the virtual camera. */ void vpImageSimulator::getImage(vpImage<vpRGBa> &I, vpImage<vpRGBa> &Isrc, const vpCameraParameters cam) { int nb_point_dessine = 0; if (cleanPrevImage) { for (int i = (int)rect.getTop(); i < (int)rect.getBottom(); i++) { for (int j = (int)rect.getLeft(); j < (int)rect.getRight(); j++) { I[i][j] = bgColor; } } } if(visible) { getRoi(I.getWidth(),I.getHeight(),cam,pt,rect); double top = rect.getTop(); double bottom = rect.getBottom(); double left = rect.getLeft(); double right= rect.getRight(); vpRGBa *bitmap = I.bitmap; unsigned int width = I.getWidth(); vpImagePoint ip; for (int i = (int)top; i < (int)bottom; i++) { for (int j = (int)left; j < (int)right; j++) { double x=0,y=0; ip.set_ij(i,j); vpPixelMeterConversion::convertPoint(cam,ip, x,y); ip.set_ij(y,x); vpRGBa Ipixelplan; if(getPixel(Isrc,ip,Ipixelplan)) { *(bitmap+i*width+j) = Ipixelplan; nb_point_dessine++; } } } } }
/*! Get the view of the virtual camera. Be carefull, the image I is modified. The projected image is not added as an overlay! To take into account the projection of several images, a matrix \f$ zBuffer \f$ is given as argument. This matrix contains the z coordinates of all the pixel of the image \f$ I \f$ in the camera frame. During the projection, the pixels are updated if there is no other plan between the camera and the projected image. The matrix \f$ zBuffer \f$ is updated in this case. \param I : The image used to store the result. \param cam : The parameters of the virtual camera. \param zBuffer : A matrix containing the z coordinates of the pixels of the image \f$ I \f$ */ void vpImageSimulator::getImage(vpImage<vpRGBa> &I, const vpCameraParameters cam, vpMatrix &zBuffer) { if (I.getWidth() != (unsigned int)zBuffer.getCols() || I.getHeight() != (unsigned int)zBuffer.getRows()) throw (vpMatrixException(vpMatrixException::incorrectMatrixSizeError, " zBuffer must have the same size as the image I ! ")); int nb_point_dessine = 0; if (cleanPrevImage) { for (int i = (int)rect.getTop(); i < (int)rect.getBottom(); i++) { for (int j = (int)rect.getLeft(); j < (int)rect.getRight(); j++) { I[i][j] = bgColor; } } } if(visible) { getRoi(I.getWidth(),I.getHeight(),cam,pt,rect); double top = rect.getTop(); double bottom = rect.getBottom(); double left = rect.getLeft(); double right= rect.getRight(); vpRGBa *bitmap = I.bitmap; unsigned int width = I.getWidth(); vpImagePoint ip; for (int i = (int)top; i < (int)bottom; i++) { for (int j = (int)left; j < (int)right; j++) { double x=0,y=0; ip.set_ij(i,j); vpPixelMeterConversion::convertPoint(cam,ip, x,y); ip.set_ij(y,x); if (colorI == GRAY_SCALED) { unsigned char Ipixelplan; if(getPixel(ip,Ipixelplan)) { if (Xinter_optim[2] < zBuffer[i][j] || zBuffer[i][j] < 0) { vpRGBa pixelcolor; pixelcolor.R = Ipixelplan; pixelcolor.G = Ipixelplan; pixelcolor.B = Ipixelplan; *(bitmap+i*width+j) = pixelcolor; nb_point_dessine++; zBuffer[i][j] = Xinter_optim[2]; } } } else if (colorI == COLORED) { vpRGBa Ipixelplan; if(getPixel(ip,Ipixelplan)) { if (Xinter_optim[2] < zBuffer[i][j] || zBuffer[i][j] < 0) { *(bitmap+i*width+j) = Ipixelplan; nb_point_dessine++; zBuffer[i][j] = Xinter_optim[2]; } } } } } } }
/*! Get the view of the virtual camera. Be careful, the image I is modified. The projected image is not added as an overlay! \param I : The image used to store the result. \param cam : The parameters of the virtual camera. */ void vpImageSimulator::getImage(vpImage<vpRGBa> &I, const vpCameraParameters &cam) { if (cleanPrevImage) { for (unsigned int i = 0; i < I.getHeight(); i++) { for (unsigned int j = 0; j < I.getWidth(); j++) { I[i][j] = bgColor; } } } if(visible) { if(!needClipping) getRoi(I.getWidth(),I.getHeight(),cam,pt,rect); else getRoi(I.getWidth(),I.getHeight(),cam,ptClipped,rect); double top = rect.getTop(); double bottom = rect.getBottom(); double left = rect.getLeft(); double right= rect.getRight(); vpRGBa *bitmap = I.bitmap; unsigned int width = I.getWidth(); vpImagePoint ip; int nb_point_dessine = 0; for (unsigned int i = (unsigned int)top; i < (unsigned int)bottom; i++) { for (unsigned int j = (unsigned int)left; j < (unsigned int)right; j++) { double x=0,y=0; ip.set_ij(i,j); vpPixelMeterConversion::convertPoint(cam,ip, x,y); ip.set_ij(y,x); if (colorI == GRAY_SCALED) { unsigned char Ipixelplan; if(getPixel(ip,Ipixelplan)) { vpRGBa pixelcolor; pixelcolor.R = Ipixelplan; pixelcolor.G = Ipixelplan; pixelcolor.B = Ipixelplan; *(bitmap+i*width+j) = pixelcolor; nb_point_dessine++; } } else if (colorI == COLORED) { vpRGBa Ipixelplan; if(getPixel(ip,Ipixelplan)) { *(bitmap+i*width+j) = Ipixelplan; nb_point_dessine++; } } } } } }
/*! Get the region of interest in the image. \param cam : camera parameters. \param cMo : pose. \return Image point corresponding to the region of interest. */ std::vector<vpImagePoint> vpPolygon3D::getRoi(const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo) { changeFrame(cMo); return getRoi(cam); }