I looked up to documantation and found a very convenient AVInputFormat's funciton get_device_list . But the problem is I can't use it.
Here's my short code snippet
#include <QDebug>
extern "C"
{
#include <libavformat/avformat.h>
#include <libavdevice/avdevice.h>
}
int main(int argc, char *argv[])
{
avdevice_register_all();
AVFormatContext *formatContext = avformat_alloc_context();
AVInputFormat *inputFormat = av_find_input_format("dshow");
AVDeviceInfoList devices;
inputFormat->get_device_list(formatContext, &devices);
qDebug() << devices.nb_devices;
avformat_free_context(formatContext);
return 0;
}
And that code CRASHES when I'm trying to print devices. How do I use that function properly? The official domentation has no examples using that function.
Related
Hello I am using Ubuntu 18.04 and I am very new to Ros. I was using ros kinetic. I have switched to the Ros melodic version and I am getting a compilation error in my cpp file. Below you can see my code and error I will be very happy if you could help.
this is my code:
#include <ros/ros.h>
#include <std_msgs/String.h>
#include <move_base_msgs/MoveBaseAction.h>
#include <actionlib/client/simple_action_client.h>
#include <iostream>
#include <string.h>
using namespace std;
/** Function Declarations **/
bool moveToGoal(double xGoal, double yGoal, double yaw);
void choose();
//code*****
void move(const std_msgs::String msg){
cout << "move Function activated" << endl;
//***code
}
int main(int argc, char** argv){
ros::init(argc, argv, "map_navigation4");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe ("server_messages", 1, move);
ros::spin();
return 0;
}
bool moveToGoal(double xGoal, double yGoal, double yaw){
//**code
}
and this error message:
enter image description here
It looks like you subscriber is not recognizing your move callback function. Below modification to your code should fix the issue-
int main(int argc, char** argv){
ros::init(argc, argv, "map_navigation4");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("server_messages", 1, moveCB);
ros::spin();
return 0;
}
And the callback function -
void moveCB(const std_msgs::String::ConstPtr &msg)
{
cout << "move Function activated" << endl;
const char *a = msg->data.c_str();
/**
* Your Code
*/
}
Reference
ROS code documentation
ROS Publisher and Subscriber Tutorial
I've successfully managed to modify a given input bitcode that
was read from a file as described in this SO post.
Now I want to save it to some output bitcode filename, with
something similar to saveIRFile(module,"myOutputBC.bc");.
Here is the main.cpp file I'm using, but I can't seem to find
the proper API to do the desired save.
/**********************/
/* LLVM INCLUDE FILES */
/**********************/
#include "llvm/IR/Module.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/IR/LLVMContext.h"
/**************/
/* NAMESPACES */
/**************/
using namespace std;
using namespace llvm;
int main(int argc, char **argv)
{
LLVMContext ctx;
SMDiagnostic Err;
unique_ptr<Module> M = parseIRFile(argv[1],Err,ctx);
if (M)
{
Module *module = M.get();
for (auto
func = module->begin();
func != module->end();
func++)
{
errs() << func->getName() << "\n";
// modify func's basic blocks ...
// and save with saveIRFile(module,"myOutputBC.bc");
}
}
return 0;
}
Any help is very much appreciated, thanks!
Something like this should do:
std::error_code ec;
ToolOutputFile result("myOutputBC.bc", ec, sys::fs::F_None);
WriteBitcodeToFile(*module, result.os());
result.keep();
Note that if you're using an old version of LLVM ToolOutputFile may be called tool_output_file.
This is main.h, I shared with you just in case there would be something wrong here. But I don't think so.
Then, there is main.cpp which is the entry point of my program.
If I generate it with Visual Studio 2017, it will compile and run without errors but it will not print anything on the console.
I can't figure out why.
main.h:
#pragma once
#include <thread>
#include "GabEngine/MainEngine.h"
#include "GraphicInterface/Console.h"
#include "GabEngine/Globals.h"
int m_ScreenWidth = 500, m_ScreenHeight = 500;
GabEngine::Wind m_RootWindow;
GabEngine::MainEngine m_MainEngine(&m_RootWindow);
Globals::NetworkStatus NetStatus;
Networking::MainNetwork m_MainNetwork(&NetStatus);
void TaskConsole();
void TaskNetwork();
main.cpp:
#include "GraphicInterface/main.h"
#include <iostream>
#undef main
void TaskConsole()
{
if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
{
GabEngine::FatalError("Failed to initialize SDL");
}
m_RootWindow.Create("Utryon", m_ScreenWidth, m_ScreenHeight, 2);
m_MainEngine.InitShaders();
m_MainEngine.InitCEGUI("C:/Users/Bob/Documents/Visual Studio 2017/Projects/Utryon/GabEngine/GUI");
m_MainEngine.LoadScheme("UtryonLook.scheme");
m_MainEngine.SetFont("DejaVuSans-10");
GraphicInterface::Console MainConsole(&m_MainEngine, &m_MainNetwork);
MainConsole.InitConsole();
MainConsole.Run();
}
void TaskNetwork()
{
m_MainNetwork.Run();
}
int main(int argc, char** argv)
{
std::cout << "Here 1" << std::endl; //It is supposed to print Here 1
thread ConsoleThread(TaskConsole);
thread NetworkThread(TaskNetwork);
ConsoleThread.join();
NetworkThread.join();
// End of program
return 0;
}
How to make a subscriber and publisher in ROS on C++ in one file? I tried this and publisher works but subscriber callback function is not called
#include <ros/ros.h>
#include <iostream>
#include <std_msgs/UInt16.h>
#include <math.h>
int error = 0;
void error_sub(const std_msgs::UInt16::ConstPtr& msg)
{
ROS_INFO("I heard: [%d]", msg->data);
error = msg->data;
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "lighter");
ros::NodeHandle nh;
ros::Publisher connected =nh.advertise<std_msgs::UInt16>("/robot/sonar/head_sonar/lights/set_lights",1);
ros::Subscriber sub = nh.subscribe("/plc/error", 1000, error_sub);
std_msgs::UInt16 msg;
while(ros::ok())
{
if(error >= 0)
{
msg.data = 36863;
connected.publish(msg);
}
ros::spinOnce();
}
}
I does not work because of the bad type of the message. It should be Int8 instead of UInt16 in callback function.
I am using win 8.1 and visual studio 2013 community. I download openCV3.0.0 from here. What I want to do is read a video. Following is my code
#include "stdafx.h"
#include "opencv2/opencv.hpp"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
cv::VideoCapture cap("bb.mp4");
if (!cap.isOpened()){
std::cout << "Cannot open video!\n";
return -1;
}
cv::Mat frame;
while (cap.read(frame)){
cv::imshow("frame", frame);
char key = cv::waitKey(1) & 0xFF;
}
return 0;
}
The problem is that cap.isOpened() always return false even I give an absolute path cv::VideoCapture cap("D:\\bb.mp4"). Following is another toy program that operates normally.
#include "stdafx.h"
#include "opencv2/opencv.hpp"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
cv::Mat img = cv::imread("aa.jpg");
cv::imshow("img", img);
char key = cv::waitKey(1) & 0xFF;
return 0;
}
The second program shows that I can compile a program included openCV library correctly and also the path to the file should be correct since the aa.jpg and bb.mp4 are placed in the same folder. Anyone knows how to solve the problem?