视觉伺服控制工具Visual Servoing Platform---VISP(3)----平面图像投影

本教程的目的是解释如何使用vpImageSimulator类在给定摄影机位置投影平面场景的图像。例如,该功能可在视觉伺服模拟过程中使用,如教程:基于图像的视觉伺服中所述,以引入图像处理。

给定平面20cm×20cm正方形目标的图像作为下一幅图像中显示的图像,我们将在这里演示如何在给定相机位置投影该图像,以及如何获得结果图像。
在这里插入图片描述

#include <visp/vpDisplayX.h>
#include <visp/vpDisplayGDI.h>
#include <visp/vpImageIo.h>
#include <visp/vpImageSimulator.h>
int main()
{
  try {
    vpImage<unsigned char> target;
    vpImageIo::read(target, "./target_square.pgm");
    vpColVector X[4];
    for (int i = 0; i < 4; i++) X[i].resize(3);
    // Top left     Top right       Bottom right   Bottom left
    X[0][0] = -0.1; X[1][0] =  0.1; X[2][0] = 0.1; X[3][0] = -0.1;
    X[0][1] = -0.1; X[1][1] = -0.1; X[2][1] = 0.1; X[3][1] =  0.1;
    X[0][2] =  0;   X[1][2] =  0;   X[2][2] = 0;   X[3][2] =  0;
    vpImage<unsigned char> I(480, 640);
    vpCameraParameters cam(840, 840, I.getWidth()/2, I.getHeight()/2);
    vpHomogeneousMatrix cMo(0, 0, 0.35, 0, vpMath::rad(30), vpMath::rad(15));
    vpImageSimulator sim;
    sim.setInterpolationType(vpImageSimulator::BILINEAR_INTERPOLATION);
    sim.init(target, X);
    // Get the new image of the projected planar image target
    sim.setCleanPreviousImage(true);
    sim.setCameraPosition(cMo);
    sim.getImage(I, cam);
    try {
      vpImageIo::write(I, "./rendered_image.jpg");
    }
    catch(...) {
      std::cout << "Unsupported image format" << std::endl;
    }
#if defined(VISP_HAVE_X11)
    vpDisplayX d(I);
#elif defined(VISP_HAVE_GDI)
    vpDisplayGDI d(I);
#else
    std::cout << "No image viewer is available..." << std::endl;
#endif
    vpDisplay::setTitle(I, "Planar image projection");
    vpDisplay::display(I);
    vpDisplay::flush(I);
    std::cout << "A click to quit..." << std::endl;
    vpDisplay::getClick(I);
  }
  catch(vpException e) {
    std::cout << "Catch an exception: " << e << std::endl;
  }
}

该程序的结果显示在下图中。
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值