Can't process image using cv_bridge
I'm using a library called 'tpofinder' to recognize textured objects,but it can only work using opencv's videocapture() function,and it's very slow,about 1 fps or less. I'm using CMake to build it,in the same project,the one using videocapture can process image,but the other one using cv_bridge can't process,it just return the origin image.
The one using videocapture
//Include headers for OpenCV Image processing
#include <opencv2/imgproc/imgproc.hpp>
//Include headers for OpenCV GUI handling
#include <opencv2/highgui/highgui.hpp>
#include <boost/foreach.hpp>
#include <boost/format.hpp>
#include <iostream>
#include "tpofinder/configure.h"
#include "tpofinder/detect.h"
#include "tpofinder/visualize.h"
using namespace cv;
using namespace tpofinder;
using namespace std;
VideoCapture *capture = NULL;
bool verbose = true;
Mat image;
Detector detector;
void openCamera() {
capture = new VideoCapture(0);
if (!capture->isOpened()) {
cerr << "Could not open default camera." << endl;
exit(-1);
}
}
void loadModel(Modelbase& modelbase, const string& path) {
if (verbose) {
cout << boost::format("Loading object %-20s ... ") % path;
}
modelbase.add(path);
if (verbose) {
cout << "[DONE]" << endl;
}
}
void processImage(Detector& detector) {
if (!image.empty()) {
cout << "Detecting objects on image ... ";
Scene scene = detector.describe(image);
vector<Detection> detections = detector.detect(scene);
cout << "[DONE]" << endl;
BOOST_FOREACH(Detection d, detections) {
cout << "Drawing ...";
drawDetection(image, d);
cout << "[Done]" << endl;
}
}
}
void nextImage()
{
if (verbose) {
cout << "Reading from webcam ... ";
}
*capture >> image;
if (verbose) {
cout << "[DONE]" << endl;
}
}
/**
* This tutorial demonstrates simple image conversion between ROS image message and OpenCV formats and image processing
*/
int main(int argc, char **argv)
{
// TODO: adapt to OpenCV 2.4.
// TODO: remove duplication
// TODO: support SIFT
Ptr<FeatureDetector> fd = new OrbFeatureDetector(1000, 1.2, 8);
Ptr<FeatureDetector> trainFd = new OrbFeatureDetector(250, 1.2, 8);
Ptr<DescriptorExtractor> de = new OrbDescriptorExtractor(1000, 1.2, 8);
Ptr<flann::IndexParams> indexParams = new flann::LshIndexParams(15, 12, 2);
Ptr<DescriptorMatcher> dm = new FlannBasedMatcher(indexParams);
Feature trainFeature(trainFd, de, dm);
Modelbase modelbase(trainFeature);
loadModel(modelbase, PROJECT_BINARY_DIR + "/data/adapter");
loadModel(modelbase, PROJECT_BINARY_DIR + "/data/blokus");
loadModel(modelbase, PROJECT_BINARY_DIR + "/data/book1");
loadModel(modelbase, PROJECT_BINARY_DIR + "/data/book2");
loadModel(modelbase, PROJECT_BINARY_DIR + "/data/book3");
loadModel(modelbase, PROJECT_BINARY_DIR + "/data/coffee");
Feature feature(fd, de, dm);
Ptr<DetectionFilter> filter = new AndFilter(
Ptr<DetectionFilter> (new EigenvalueFilter(-1, 4.0)),
Ptr<DetectionFilter> (new InliersRatioFilter(0.30)));
Detector detector(modelbase, feature, filter);
openCamera();
while (true) {
nextImage();
processImage(detector);
//Display the image using OpenCV
cv::imshow("image processed", image);
//Add some delay in miliseconds. The function only works if there is at least one HighGUI window created and the window is active. If there are several HighGUI windows, any of them can be active.
cv::waitKey(3);
}
//OpenCV HighGUI call to destroy a display window on shut-down.
cv::destroyWindow("image processed");
}
The one using cv_bridge
//Includes all the headers necessary to use the most common public pieces of the ROS system.
#include <ros/ros.h>
//Use image_transport for publishing and subscribing to images in ROS
#include <image_transport/image_transport.h>
//Use cv_bridge to convert between ROS and OpenCV Image formats
#include <cv_bridge/cv_bridge.h>
//Include some useful constants for image encoding. Refer to: http://www ...