ROS中的VISP - 无法显示摄像头馈送

时间:2014-05-27 17:37:33

标签: c++ opencv ros

我正在尝试将已经编写在ROS中的代码与一些基本的Visp行集成,以便使用Visp函数显示相机源。我是visp的初学者,因此我正在尝试一些基本的东西。我在这里附上相关的代码行

//Lots of lines of code above and blow this code block
cv::Mat src_gray;

cv::cvtColor(imageLeft, src_gray, CV_RGB2GRAY );//imageLeft is a colour image got from the camera through another node

vpImage<unsigned char> I;


vpImageConvert::convert(src_gray,I) ;
vpDisplayOpenCV display;

if(this->lt == false)//this if loop is to prevent from infinite windows coming out
{display.init(I, 100, 100, "Line tracking");
this->lt = true;}

vpDisplay::display(I);
vpDisplay::flush(I);

让我确保这段代码在回调中,因此它等同于infinte while循环,除非进程停止。

我无法在窗口中获取相机输出。当我运行节点时,窗口打开但没有图像。任何想法?

1 个答案:

答案 0 :(得分:1)

ViSP-ROS干扰最近发生了变化。虽然ViSP Bridge提供ROS和ViSP之间的低级接口,但Visp ROS是更好和更高级别的接口。从那里,您可以访问此tutorial,其中修改了常规ViSP代码以使用ROS。

ViSP代码与您的代码类似:

#include <visp/vp1394TwoGrabber.h>
#include <visp/vpDisplayX.h>
#include <visp/vpImage.h>

int main()
{
#ifdef VISP_HAVE_DC1394_2
  try {
    vpImage<unsigned char> I; // Create a gray level image container
    bool reset = true; // Enable bus reset during construction (default)
    vp1394TwoGrabber g(reset); // Create a grabber based on libdc1394-2.x third party     lib

    g.setVideoMode(vp1394TwoGrabber::vpVIDEO_MODE_640x480_MONO8);
    g.setFramerate(vp1394TwoGrabber::vpFRAMERATE_60);
    g.open(I);

    std::cout << "Image size: " << I.getWidth() << " " << I.getHeight() << std::endl;

#ifdef VISP_HAVE_X11
    vpDisplayX d(I);
#else
    std::cout << "No image viewer is available..." << std::endl;
#endif

    while(1) {
      g.acquire(I);
      vpDisplay::display(I);
      vpDisplay::flush(I);
      if (vpDisplay::getClick(I, false))
        break;
    }
  }
  catch(vpException e) {
    std::cout << "Catch an exception: " << e << std::endl;
  }
#endif
}

支持ROS的代码:

#include <visp/vpDisplayX.h>
#include <visp/vpImage.h>
#include <visp_ros/vpROSGrabber.h>

int main()
{
  try {
    //vpImage<unsigned char> I; // Create a gray level image container
    vpImage<vpRGBa> I; // Create a color image container
    vpROSGrabber g; // Create a grabber based on ROS

    g.setCameraInfoTopic("/camera/camera_info");
    g.setImageTopic("/camera/image_raw");
    g.setRectify(true);
    g.open(I);
    std::cout << "Image size: " << I.getWidth() << " " << I.getHeight() << std::endl;

#ifdef VISP_HAVE_X11
    vpDisplayX d(I);
#else
    std::cout << "No image viewer is available..." << std::endl;
#endif

    while(1) {
      g.acquire(I);
      vpDisplay::display(I);
      vpDisplay::flush(I);
      if (vpDisplay::getClick(I, false))
        break;
    }
  }
  catch(vpException e) {
    std::cout << "Catch an exception: " << e << std::endl;
  }
}

希望这有帮助!