[英]VISP in ROS - Not able to display camera feed
I am trying to integrate a code already written in ROS with some basic Visp lines so as to display a camera feed using Visp functions. 我正在尝试将已经用ROS编写的代码与一些基本的Visp行集成在一起,以便使用Visp功能显示摄像机供稿。 I am a beginner in visp and hence I am trying something basic.I am attaching the relevant code lines here
我是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);
Let me ensure you that this piece of code is in a callback and hence it is equivalent to an infinte while loop unless the process is stopped. 让我确保您这段代码在回调中,因此,除非进程停止,否则它等效于infinte while循环。
I am not able to get the camera output in the window.When I run the node the window opens but no image.Any ideas? 我无法在窗口中获取相机输出。运行节点时,窗口打开但没有图像。有什么想法吗?
The ViSP-ROS interfece has been changing recently. ViSP-ROS接口最近发生了变化。 While ViSP Bridge provides low level interface between ROS and ViSP, Visp ROS is a better and higher level interface.
虽然ViSP Bridge在ROS和ViSP之间提供了低级接口,但Visp ROS是更好的高级接口。 From there you can reach to this tutorial where a regular ViSP code is modified to use ROS.
从那里可以到达本教程 ,其中将常规的ViSP代码修改为使用ROS。
The ViSP code similar to yours: 类似于您的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
}
And the ROS enabled code: 以及启用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;
}
}
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.