我有一台相机,我正在连接它,认为它自己的API。为了获得有效的代码,相机手册建议将这些环境变量添加到系统中。
我在/etc/bash.bashrc
中设置了以下内容 export PYLON_ROOT=/opt/pylon3
export GENICAM_ROOT_V2_3=${PYLON_ROOT}/genicam
mkdir -p $HOME/genicam_xml_cache
export GENICAM_CACHE_V2_3=$HOME/genicam_xml_cache
export LD_LIBRARY_PATH=${PYLON_ROOT}/lib64:${GENICAM_ROOT_V2_3}/bin/Linux64_x64:${GENICAM_ROOT_V2_3}/bin/Linux64_x64/GenApi/Generic:$LD_LIBRARY_PATH
当我从终端运行我的qt代码时,代码运行没有任何错误。但是当我从Qtcreator运行它时,它会给我以下错误并终止程序!
Environment Variable 'GENICAM_ROOT_V2_3' not found
我已经将环境变量代码添加到/ etc / profile中,但结果是相同的。为什么Qtcreator找不到我的变量?
的.pro
QT += core
QT += gui
INCLUDEPATH += /opt/pylon3/include \
/opt/pylon3/genicam/library/CPP/include
LIBS += -L/opt/pylon3/lib64 \
-L/opt/GenICam_v2_3/bin/Linux64_x64 \
-L/opt/GenICam_v2_3/bin/Linux64_x64/GenApi/Generic \
-lgxapi \
-lpylonbase \
-lpylonbase-3.2.0 \
-lpylongigesupp \
-lpylonutility \
-lGCBase_gcc40_v2_3 \
-lGenApi_gcc40_v2_3 \
-llog4cpp_gcc40_v2_3 \
-lLog_gcc40_v2_3 \
-lMathParser_gcc40_v2_3 \
-lXerces-C_gcc40_v2_7 \
-lXMLLoader_gcc40_v2_3
TARGET = VLPR
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
CONFIG += link_pkgconfig
PKGCONFIG += opencv
Mainwindow.cpp
MainWindow::MainWindow(QObject *parent) :QObject(parent)
{
Initialize_Cam();
}
void MainWindow::Initialize_Cam()
{
MonoCamThr = new MonoCamThread(this);
MonoCamThr->Stop_Disp = true;
MonoCamThr->start();
MonoCamThr->Stop_Disp = false;
}
Monocam.cpp
MonoCamThread::MonoCamThread(QObject *parent) :
QThread(parent)
{
try
{
// List of cameras
DeviceInfoList_t m_Devices; // Still empty
// Create the unique transport layer factory object
// ... create the transport layer object
// ... create and initialise Cameras
CTlFactory& TlFactory = CTlFactory::GetInstance();
ITransportLayer *pTl = TlFactory.CreateTl( Camera_t::DeviceClass() );
if ( ! pTl )
{
throw GenericException(
"Failed to create transport layer!", __FILE__, __LINE__);
}
// Get all attached cameras and exit if no camera is found
m_Devices.clear();
if ( 0 == pTl->EnumerateDevices( m_Devices ) )
{
throw GenericException(
"No camera present!", __FILE__, __LINE__);
}
if(m_Devices.size()<2)
{
while(1)
{
qDebug() << "Number of Cameras are less than 2 .... \n" ;
}
}
qDebug() << "Number of Cameras are: "<<m_Devices.size()<<" \n" ;
// Restrict number of used camera
size_t nCameras = 2;
// Create all camera devices and set up the grab threads
if(pTl->CreateDevice( m_Devices[0])->GetDeviceInfo().GetModelName())
MonoCamera = new Camera_t( pTl->CreateDevice( m_Devices[1]) );
MonoCamera->Open();
MonoCamera->PixelFormat.SetValue( PixelFormat_Mono8 );
MonoCamera->OffsetX.SetValue( 0 );
MonoCamera->OffsetY.SetValue( 0 );
MonoCamera->Width.SetValue( MonoCamera->Width.GetMax() );
MonoCamera->Height.SetValue( MonoCamera->Height.GetMax() );
}
catch( GenericException &e )
{
qDebug() << "**** An exception occurred! Desription is: " << "\n"<< " " << e.GetDescription() << "\n";
}
}
void MonoCamThread::run()
{
while(!Stop_Disp)
{
//since this part of code never runs I didn' put the code for it ....
}
}
还有其他cpp文件,但它们在相机初始化后运行。我在六个月前修改了这个错误,将GENICAM_ROOT_V2_3 PATH位置添加到ubuntu中的系统文件,如.bashrc或.profile,但我现在不记得文件名! :((
P.S 不要忘记这个代码在终端运行并且运行正常...唯一的问题是Qt找不到指定的变量位置!!!
由于
答案 0 :(得分:1)
我正在使用带有类似凸轮的Qt。我已经设置了“运行设置”,就像你在这张图片中看到的那样。