loading rosbag duration using cpp - c++

I am interested to load contents of rosbag into databse using sqlite and c++.
while including rosbag/view.h and rosbag/bag.h header file in my cpp file in visual studio code I am facing error of no such file or directory
code: ref http://wiki.ros.org/rosbag/Cookbook#C.2B-.2B-
#include <ros/ros.h>
#include <rosbag/bag.h>
#include <rosbag/view.h>
int main(int argc, char **argv)
{
rosbag::Bag bag;
bag.open("input.bag", rosbag::bagmode::Read);
rosbag::View view(bag);
ros::Time bag_begin_time = view.getBeginTime();
ros::Time bag_end_time = view.getEndTime();
std::cout << "ROS bag time: " << (bag_end_time-
bag_begin_time).toSec() << "(s)" << std::endl;
bag.close();
return 0;
}
error:
main.cpp:2:10: fatal error: rosbag/bag.h: No such file or directory
2 | #include <rosbag/bag.h>
| ^~~~~~~~~~~~~~

Issue is resolved by including ros package, directories and libraries in the CmakeLists.txt and executing the code with cmake and make respectively now able to see the rosbag duration.
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(esw2 VERSION 0.0.1 LANGUAGES CXX)
find_package(rosbag REQUIRED)
add_executable(folder_name
file.cpp
)
target_include_directories(bag_reader
PUBLIC
include
${rosbag_INCLUDE_DIRS}
)
target_link_libraries(bag_reader
PRIVATE
${rosbag_LIBRARIES}
stdc++fs
)

Related

Undefined references for aruco::MarkerDetector

I'm trying to get the marker position in an image, but when I compile the program, during linking, I receive several errors indicating undefined reference to Aruco (Marker.cpp:(.text+0x1643): undefined reference to 'aruco::MarkerDetector::detect(cv::Mat const&, std::vector<aruco::Marker, std::allocator<aruco::Marker> >&, cv::Mat, cv::Mat, float, bool)'), I've looked for solutions regarding linking the library but none of them seem to work. This is my CMakeList.txt:
# cmake needs this line
cmake_minimum_required(VERSION 2.8)
# Define project name
project(Pruebas_alg_new)
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV REQUIRED)
find_package(aruco)
# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " config: ${OpenCV_DIR}")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(Marker Marker.cpp)
target_link_libraries(Marker PRIVATE ${OpenCV_LIBS})
And here is the code I'm trying to compile:
#include <iostream>
#include <stdio.h>
#include <opencv2/highgui.hpp>
#include <cv_bridge/cv_bridge.h>
#include <opencv2/imgcodecs.hpp>
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/calib3d.hpp"
#include "opencv2/xfeatures2d.hpp"
#include "Euler.hpp"
#include <aruco/aruco.h>
#include <aruco/markerdetector.h>
#include <aruco/marker.h>
int main(int argc, char **argv)
{
Mat img_scene = imread("/home/javier/pruebas/MasPruebas/Imagenes/Scene.jpg", IMREAD_GRAYSCALE );
if( /*!img_object.data ||*/ !img_scene.data )
{ std::cout<< " --(!) Error reading images " << std::endl;}
Mat CameraMatrix = (Mat_<double>(3,3) << 374.67,0,320.5,0,374.67,180.5,0,0,1);
aruco::MarkerDetector MDetector;
vector<aruco::Marker> Markers;
//DetectorParameters::create()
MDetector.detect(img_scene,Markers);
std::cout<< Markers.size() << std::endl;
// if at least one marker detected
for (unsigned int i = 0; i<Markers.size(); i++)
{Markers[i].draw(img_scene,cv::Scalar(0,0,255),2);}
cv::imshow("out", img_scene);
cv::waitKey(0);
return 0;
}

Problems with setting up SDL2 for Xcode

I am using Xcode 11.4 on MacOS Catalina 10.15.3
I use HomeBrew to install SDL2 by Terminal:
brew install sdl2
and then, I open Xcode, create new project named SDL2Tutorial to test the library.
I changed the header search path to
/usr/local/include
and added /usr/local/cellar/sdl2/2.0.12_1/lib/libSDL2-2.0.0.dylib to Link Binary With Library
In main.cpp I wrote code like this
#include <iostream>
#include <SDL2/SDL.h>
int main(int argc, char * argv[]) {
// insert code here...
if (SDL_Init( SDL_INIT_EVERYTHING ) < 0)
{
std::cout << "Error: " << SDL_GetError() << std::endl;
}
return EXIT_SUCCESS;
}
and there are a lot of errors appeared including:
2020-04-02 17:03:41.767966+0700 SDL2Tutorial[829:23149] Metal API Validation Enable
2020-04-02 17:03:41.799979+0700 SDL2Tutorial[829:23443] flock failed to lock maps file: errno = 35
2020-04-02 17:03:41.800445+0700 SDL2Tutorial[829:23443] flock failed to lock maps file: errno = 35
2020-04-02 17:03:41.848181+0700 SDL2Tutorial[829:23149] [plugin] AddInstanceForFactory: No factory registered for id F8BB1C28-BAE8-11D6-9C31-00039315CD46
2020-04-02 17:03:41.875838+0700 SDL2Tutorial[829:23149] HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine
2020-04-02 17:03:41.876282+0700 SDL2Tutorial[829:23149] HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine
Did I miss any step of setting up the library and how can I solve all of the errors?

Problems when installing cppflow

I am trying to use the c++ wrapper for tensorflow api from https://github.com/serizba/cppflow.
I have copied the git repository. Downloaded the tensorflow api files (copied them into the cppflow folder), when I build the project in the folder, and then tries to run it from the project file created I get 37 errors, all related to Model.obj and Tensor.obj.
LNK2019 unresolved external symbol __imp_TF_NewStatus referenced in function "public: __cdecl Model::Model(class std::basic_string,class std::allocator > const &)" (??0Model##QEAA#AEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) example *\cppflow\examples\load_model\build\Model.obj 1
I am running it on Windows 10, with a c++ 17 compiler.
The CMakeFiles contain the following lines:
cmake_minimum_required(VERSION 3.10)
project(example)
set(CMAKE_CXX_STANDARD 17)
add_executable(example main.cpp ../../src/Model.cpp ../../src/Tensor.cpp)
target_include_directories(example PRIVATE ../../include)
target_link_libraries (example -ltensorflow)
I am trying to run a example from the github repo.
#include "../../include/Model.h"
#include "../../include/Tensor.h"
#include <numeric>
#include <iomanip>
int main() {
Model model("../model.pb");
model.init();
auto input_a = new Tensor(model, "input_a");
auto input_b = new Tensor(model, "input_b");
auto output = new Tensor(model, "result");
std::vector<float> data(100);
std::iota(data.begin(), data.end(), 0);
input_a->set_data(data);
input_b->set_data(data);
model.run({input_a, input_b}, output);
for (float f : output->get_data<float>()) {
std::cout << f << " ";
}
std::cout << std::endl;
}
Does anybody have any suggestions?
"Downloaded the tensorflow api files (copied them into the cppflow folder), "
Try downloading tensorflow_c_api into separate folder. No need to place inside cppflow directory.

Problems with building OpenCv with Xcode. Cannot find opencv2/opencv.hpp file

I have installed OpenCv with Homebrew on my MacOs. I have added libopencv 4.0.1.dylib in Xcode. When I try to build, Xcode cannot find the files. Any suggestions?
I changed my path but still have problems.
Main code:
#include <iostream>
#include <opencv4/opencv2/opencv.hpp>
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
Build settings including path:
Error messages:

Failling Qt application on Ubuntu

I have Ubuntu 10.04 and have the Qt library install. When I run the code
#include <QDir>
#include <QFileInfo>
#include <QtDebug>
int main( int argc, char **argv )
{
foreach( QFileInfo drive, QDir::drives() )
{
qDebug() << "Drive: " << drive.absolutePath();
QDir dir = drive.dir();
dir.setFilter( QDir::Dirs );
foreach( QFileInfo rootDirs, dir.entryInfoList() )
qDebug() << " " << rootDirs.fileName();
}
return 0;
}
I get the following errors.
g++ qt.cpp -o test
qt.cpp:1:16: error: QDir: No such file or directory
qt.cpp:2:21: error: QFileInfo: No such file or directory
qt.cpp:4:19: error: QtDebug: No such file or directory
qt.cpp: In function ‘int main(int, char**)’:
qt.cpp:8: error: ‘QFileInfo’ was not declared in this scope
qt.cpp:8: error: ‘QDir’ has not been declared
qt.cpp:8: error: ‘foreach’ was not declared in this scope
qt.cpp:9: error: expected ‘;’ before ‘{’ token
How do I fix this problem?
g++ seems to not find Qt includes files.
You should add an include directory when compiling. and linked with the Qt library.