linux 相机,linux下使用大恒相机实时运行ORB-SLAM
平台:Ubuntu 16.04
相机: MER-301-125U3M (大恒其他型号的USB相机亦可)
本文是在原有ORB-SLAM源码基础上增加大恒相机的运行示例,用大恒相机实时运行ORB-SLAM。
主要涉及两个地方得修改:
采图。之前的example是读本地图片传入ORB_SLAM2::System,现在改成用大恒相机实时采图传入
相机参数。之前的example是用数据集已有的参数,现在是换成自己相机的实际参数
1. 安装大恒的SDK
从大恒官网下载linux的安装包,名称如Galaxy_Linux-x86_Gige-U3_32bits-64bits_1.2.1911.9122.tar.gz
解压后进入Galaxy_Linux-x86_Gige-U3_32bits-64bits_1.2.1911.9122目录,
在终端中运行./Galaxy_camera.run,便会生成安装目录Galaxy_camera
大恒的头文件和库文件:
头文件: 在./Galaxy_camera/inc目录,有DxImageProc.h和GxIAPI.h两个文件
库文件: 在系统库目录下,/usr/lib/libgxiapi.so,所以cmake的时候可以直接去链接
2. 下载 ORB-SLAM2 源码
下载源码:
git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
以下所有操作的根目录为上述下载的路径ORB_SLAM2。
首先按照上面的库的github首页的编译操作,安装好依赖后,编译源码。
保证源码自身编译没有问题之后,再进行以下步骤。
3. 用大恒相机运行ORB-SLAM
是在原有的Example基础上,加一个用大恒相机运行ORB-SLAM的例子
3.1 涉及修改和新增的目录结构如下
.
├── CMakeLists.txt (修改)
├── DxImageProc.h (新增)
├── GxIAPI.h (新增)
└── Examples
└── Monocular
├── mono_daheng.cc (新增)
└── daheng.yaml (新增)
.为根目录ORB_SLAM2
GxIAPI.h和DxImageProc.h 为大恒的头文件,从大恒安装目录的inc目录里复制过来
mono_daheng.cc为新增的用大恒相机运行ORB-SLAM的源文件
daheng.yaml为新增的大恒相机的参数文件
3.2 修改根目录下的CMakeLists.txt
在原有的CMakeLists.txt的文件末尾加上如下内容
add_executable(mono_daheng
Examples/Monocular/mono_daheng.cc)
target_link_libraries(mono_daheng ${PROJECT_NAME} gxiapi)
3.3 daheng.yaml
在 ./Examples/Monocular/ 目录下 创建 daheng.yaml 文件,是大恒相机的参数文件,
录入内容如下,里面的相机参数可根据自己相机的情况录入。
关于相机的标定,可以自己写opencv标定程序来标定。
或者使用现有的标定程序来标定,比如ros里有个camera_calibration程序可用于标定。
%YAML:1.0
#--------------------------------------------------------------------------------------------
# Camera Parameters. Adjust them!
#--------------------------------------------------------------------------------------------
# Camera calibration and distortion parameters (OpenCV)
Camera.fx: 2360.89
Camera.fy: 2363.79
Camera.cx: 1029.18
Camera.cy: 821.37
Camera.k1: -0.095
Camera.k2: 0.353
Camera.p1: 0.0
Camera.p2: 0.0
# Camera frames per second
Camera.fps: 20.0
# Color order of the images (0: BGR, 1: RGB. It is ignored if images are grayscale)
Camera.RGB: 1
#--------------------------------------------------------------------------------------------
# ORB Parameters
#--------------------------------------------------------------------------------------------
# ORB Extractor: Number of features per image
ORBextractor.nFeatures: 1000
# ORB Extractor: Scale factor between levels in the scale pyramid
ORBextractor.scaleFactor: 1.2
# ORB Extractor: Number of levels in the scale pyramid
ORBextractor.nLevels: 8
# ORB Extractor: Fast threshold
# Image is divided in a grid. At each cell FAST are extracted imposing a minimum response.
# Firstly we impose iniThFAST. If no corners are detected we impose a lower value minThFAST
# You can lower these values if your images have low contrast
ORBextractor.iniThFAST: 20
ORBextractor.minThFAST: 7
#--------------------------------------------------------------------------------------------
# Viewer Parameters
#--------------------------------------------------------------------------------------------
Viewer.KeyFrameSize: 0.05
Viewer.KeyFrameLineWidth: 1
Viewer.GraphLineWidth: 0.9
Viewer.PointSize:2
Viewer.CameraSize: 0.08
Viewer.CameraLineWidth: 3
Viewer.ViewpointX: 0
Viewer.ViewpointY: -0.7
Viewer.ViewpointZ: -1.8
Viewer.ViewpointF: 500
3.4 mono_daheng.cc
在 ./Examples/Monocular/ 目录下 创建 mono_daheng.cc 文件,是用大恒相机运行ORB-SLAM的源文件,
录入内容如下:
#include
#include
#include
#include
#include
#include
#include
#include "GxIAPI.h"
#include "DxImageProc.h"
using namespace std;
//Show error message
#define GX_VERIFY(emStatus) \
if (emStatus != GX_STATUS_SUCCESS) \
{ \
GetErrorString(emStatus); \
return emStatus; \
}
//Show error message, close device and lib
#define GX_VERIFY_EXIT(emStatus) \
if (emStatus != GX_STATUS_SUCCESS) \
{ \
GetErrorString(emStatus); \
GXCloseDevice(hDevice); \
hDevice = NULL; \
GXCloseLib(); \
printf("\n"); \
return emStatus; \
}
//Get description of error
void GetErrorString(GX_STATUS);
int main(int argc, char **argv)
{
if(argc != 3)
{
cerr << endl << "Usage: ./mono_tum path_to_vocabulary path_to_settings" << endl;
return 1;
}
int nImages = 1500; // use 1500 images
// Create SLAM system. It initializes all system threads and gets ready to process frames.
ORB_SLAM2::System SLAM(argv[1],argv[2],ORB_SLAM2::System::MONOCULAR,true);
// Vector for tracking time statistics
vector vTimesTrack;
vTimesTrack.resize(nImages);
cout << endl << "-------" << endl;
cout << "Start processing sequence ..." << endl;
cout << "The number of images to be used: " << nImages << endl << endl;
// daheng
GX_STATUS status = GX_STATUS_SUCCESS;
GX_DEV_HANDLE hDevice = NULL;
uint32_t nDeviceNum = 0;
//Initialize libary
status = GXInitLib();
if (status != GX_STATUS_SUCCESS) {
GetErrorString(status);
GXCloseLib();
return 0;
}
//Get device enumerated number
status = GXUpdateDeviceList(&nDeviceNum, 1000);
if (status != GX_STATUS_SUCCESS) {
GetErrorString(status);
GXCloseLib();
return 0;
}
//If no device found, app exit
if(nDeviceNum <= 0) {
printf("\n");
GXCloseLib();
return 0;
}
//Open first device enumerated
status = GXOpenDeviceByIndex(1, &hDevice);
if (status != GX_STATUS_SUCCESS) {
GetErrorString(status);
GXCloseLib();
return 0;
}
//Set acquisition mode
status = GXSetEnum(hDevice, GX_ENUM_ACQUISITION_MODE, GX_ACQ_MODE_CONTINUOUS);
GX_VERIFY_EXIT(status);
//Set trigger mode
status = GXSetEnum(hDevice, GX_ENUM_TRIGGER_MODE, GX_TRIGGER_MODE_OFF);
GX_VERIFY_EXIT(status);
//Device start acquisition
status = GXStreamOn(hDevice);
if(status != GX_STATUS_SUCCESS) {
GX_VERIFY_EXIT(status);
}
PGX_FRAME_BUFFER pFrameBuffer = NULL;
// Main loop
cv::Mat im;
struct timeval tv;
for(int ni=0; ni
{
// Read image from file
// Get a frame from Queue
status = GXDQBuf(hDevice, &pFrameBuffer, 1000);
if(status != GX_STATUS_SUCCESS) {
if (status == GX_STATUS_TIMEOUT) {
continue;
}
else {
GetErrorString(status);
break;
}
}
if(pFrameBuffer->nStatus != GX_FRAME_STATUS_SUCCESS) {
printf("\n", pFrameBuffer->nStatus);
}
// image
int width = pFrameBuffer->nWidth;
int height = pFrameBuffer->nHeight;
// cout <
cv::Mat image(cv::Size(width, height), CV_8UC1, (void*)pFrameBuffer->pImgBuf, cv::Mat::AUTO_STEP);
im = image.clone();
gettimeofday(&tv, NULL);
double tframe = (double)(tv.tv_sec) + (tv.tv_usec*1.0)/1000000.0;
if(im.empty())
{
cerr << endl << "im is empty: " << endl;
continue;
}
#ifdef COMPILEDWITHC11
std::chrono::steady_clock::time_point t1 = std::chrono::steady_clock::now();
#else
std::chrono::monotonic_clock::time_point t1 = std::chrono::monotonic_clock::now();
#endif
// Pass the image to the SLAM system
SLAM.TrackMonocular(im,tframe);
#ifdef COMPILEDWITHC11
std::chrono::steady_clock::time_point t2 = std::chrono::steady_clock::now();
#else
std::chrono::monotonic_clock::time_point t2 = std::chrono::monotonic_clock::now();
#endif
double ttrack= std::chrono::duration_cast<:chrono::duration> >(t2 - t1).count();
vTimesTrack[ni]=ttrack;
// // Wait to load the next frame
// double T=0;
// if(ni
// T = vTimestamps[ni+1]-tframe;
// else if(ni>0)
// T = tframe-vTimestamps[ni-1];
// if(ttrack
// usleep((T-ttrack)*1e6);
// GXQBuf to continue grab image
status = GXQBuf(hDevice, pFrameBuffer);
if(status != GX_STATUS_SUCCESS) {
GetErrorString(status);
break;
}
}
//Device stop acquisition
status = GXStreamOff(hDevice);
if(status != GX_STATUS_SUCCESS) {
GX_VERIFY_EXIT(status);
}
//Close device
status = GXCloseDevice(hDevice);
if(status != GX_STATUS_SUCCESS) {
GetErrorString(status);
hDevice = NULL;
GXCloseLib();
return status;
}
//Release libary
status = GXCloseLib();
if(status != GX_STATUS_SUCCESS) {
GetErrorString(status);
return status;
}
// Stop all threads
SLAM.Shutdown();
// Tracking time statistics
sort(vTimesTrack.begin(),vTimesTrack.end());
float totaltime = 0;
for(int ni=0; ni
{
totaltime+=vTimesTrack[ni];
}
cout << "-------" << endl << endl;
cout << "median tracking time: " << vTimesTrack[nImages/2] << endl;
cout << "mean tracking time: " << totaltime/nImages << endl;
// Save camera trajectory
SLAM.SaveKeyFrameTrajectoryTUM("KeyFrameTrajectory.txt");
return 0;
}
//----------------------------------------------------------------------------------
/**
\brief Get description of input error code
\param emErrorStatus error code
\return void
*/
//----------------------------------------------------------------------------------
void GetErrorString(GX_STATUS emErrorStatus)
{
char *error_info = NULL;
size_t size = 0;
GX_STATUS emStatus = GX_STATUS_SUCCESS;
// Get length of error description
emStatus = GXGetLastError(&emErrorStatus, NULL, &size);
if(emStatus != GX_STATUS_SUCCESS)
{
printf("\n");
return;
}
// Alloc error resources
error_info = new char[size];
if (error_info == NULL)
{
printf("\n");
return ;
}
// Get error description
emStatus = GXGetLastError(&emErrorStatus, error_info, &size);
if (emStatus != GX_STATUS_SUCCESS)
{
printf("\n");
}
else
{
printf("%s\n", (char*)error_info);
}
// Realease error resources
if (error_info != NULL)
{
delete []error_info;
error_info = NULL;
}
}
3.5 编译运行
在根目录下执行如下脚本,重新编译修改后的源码
./build.sh
编译成功后会在./Examples/Monocular/目录下生成可执行程序mono_daheng,这个便是用大恒相机运行ORB-SLAM的可执行程序,
按照如下方式传参运行:
./Examples/Monocular/mono_daheng Vocabulary/ORBvoc.txt Examples/Monocular/daheng.yaml
运行时保证大恒相机已经连接上,否则不能采图。
4. 参考
关于大恒相机在linux的使用,可以参考之前的一篇博客:
linux下用大恒相机采图
https://www.jianshu.com/p/eb490fae2cf7
关于相机的标定,从网上找到一篇使用ros的camera_calibration包的博客,但是没有尝试过,大家可以尝试一下:
Ubuntu 16.04 ROS标定相机——无坑篇
https://blog.csdn.net/qq_36804363/article/details/89269776
linux 相机,linux下使用大恒相机实时运行ORB-SLAM相关推荐
- 用opencv使用大恒相机的痛苦经历
做毕业设计需要用到工业相机,之前的IDS需要还了,心想买个便宜点的(毕竟做完毕设就离开实验室了,太贵不好..),挑了个国产的相机,大恒的DH-HV3151UC 从到货那天开始经历了整整一周的折磨(不过 ...
- 使用大恒水星相机利用OpenCV+ Zbar 解QR码在ROS下定位的实现
使用大恒水星相机利用OpenCV+ Zbar 解QR码在ROS下定位的实现 本次的程序功能实现是在师兄原有程序的基础上,经我继续开发的.主要完成的功能是使用QR码定位,将位姿信息通过ROS中的tf变换 ...
- ubuntu下安装大恒相机驱动并调用程序采集图像
一.ubuntu下安装大恒相机驱动 1.大恒GigE摄像头Ubuntu环境下的配置 大恒GigE摄像头Ubuntu环境下的配置 - Tzbubble - 博客园 2.官方的Linux版SDK常见问题解 ...
- Ubuntu16.04使用大恒工业相机
Ubuntu16.04使用大恒工业相机 文章目录 Ubuntu16.04使用大恒工业相机 下载驱动 解压 安装 驱动安装完成 使用Python采集图片 下载驱动 驱动下载网址(需要注册登录):http ...
- 【相机硬触发】大恒相机硬触发说明文档
大恒相机硬触发说明文档 相机硬触发是区别于软触发,利用IO或者光耦等外部控制信号触发相机快门的技术. 大恒相机有IO触发和光耦触发两种硬触发方式,其中光耦触发隔离了光电回路,对于相机更加安全,但是由于 ...
- 防火墙阻止应用程序linux,win10系统下如何解除被防火墙阻止运行的应用程序
使用win10系统的用户都知道,它内置有防火墙功能,但是有时候防火墙会默认阻止运行一些应用程序导致无法使用,那么win10系统下如何解除被防火墙阻止运行的应用程序呢?具体步骤如下. 1.右键点击系统桌 ...
- linux在root下不能用gedit,root不能运行gedit
jassionrec 于 2010-11-21 23:47:38发表: 14# alick 14楼回帖一针见血啊,太强悍了 waweni 于 2010-11-08 12:15:41发表: 确实是这样 ...
- linux实用小工具,Linux系统小工具使用大用途---1
现在Linux平台下各种管理工具非常多,有的功能强大块头也不小,有的功能可以满足一般需求且块头很小,我自己一般比较喜欢后者.在这个系列文章中将给大家介绍一些我知道的Linux中的一些小工具,也欢迎大家 ...
- Linux下使Shell命令脱离终端运行
以前在开发中经常遇到这种情况, ssh到远程机器上, 执行一个很耗时的命令, 然后ssh链接,突然中断了, 或者在一个终端中执行一个耗时的任务, 不小心关闭了终端, 前面执行的任务, 就前功尽弃了, ...
最新文章
- Reconstructing complex regions of genomes using long-read sequencingtechnology
- iOS 多线程基础之 NSThread
- Linux 平台安装 Oracle Timesten
- “盛大文学”年终派对
- dropbox_如何在Java中将图像上传到DropBox
- 程序员必须知道的10大算法(转)
- 开源大数据周刊-第22期
- MySQL 8.0 新特性:哈希连接(Hash Join)
- 开源云真机平台-Sonic应用实践
- 回程静态路由及trunk简单链路
- yunos的工程模式
- 有没有讲python模块的书_python - 模块,包
- NEC3 L2 Thirteen equals one
- excel按照显示的计算机,同一EXCEL文件在不同计算机上显示分页不同
- SQLite管理软件 - SQLite Developer
- P1 | reference spur of SFB-PLL (JSSC-2013)
- python 生成一个周期的正弦数据
- 4月1日起执行的《建筑给水排水与节水通用规范》与旧规范有哪些不同?
- 操场运动场室外扩声系统方案与功能分析
- 计算机信息的编码教案,信息编码教案