Qt doesnt find the environement variable set in bash - bash

I have a camera which I'm connecting to it thought its own APIs. To get a working code the camera manual has suggested to add these environment variables into the system.
I've set the following in the /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
when I run my qt code from terminal the code runs without any error. but When I run it from the Qtcreator it gives me the following error and terminate the program !
Environment Variable 'GENICAM_ROOT_V2_3' not found
I've added the environment variables code to /etc/profile too but the result were the same. why Qtcreator doesn't find my variables ?
.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 ....
}
}
there are other cpp files but they run after camera initialization. I fixed this error once six month ago by adding GENICAM_ROOT_V2_3 PATH location to a system file in ubuntu like .bashrc or .profile but I don't remeber the file name right now !! :((
P.S
Don't forget that this code runs in terminal and works fine ... the only problem is that Qt doesn't find the specified variable location !!!
Thanks

I'm using Qt with a similar cam. I've set "Run settings" like you can see in this image.

Related

Can't make OpenGL, glew, and SDL2 work together

// SDL 2.0.6, glew 2.1.0
SDL_Init(SDL_INIT_EVENTS | SDL_INIT_VIDEO);
SDL_Window *w = SDL_CreateWindow("Open GL", 0, 0, 1000, 1000, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
SDL_GLContext ctx = SDL_GL_CreateContext(w);
// values returned by SDL_GL_GetAttribute are commented
SDL_GL_SetAttribute(SDL_GLattr::SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); // doesn't help
SDL_GL_SetAttribute(SDL_GLattr::SDL_GL_CONTEXT_MAJOR_VERSION, 4); // 4
SDL_GL_SetAttribute(SDL_GLattr::SDL_GL_CONTEXT_MINOR_VERSION, 5); // 5, these two accept even 10.10 without error actually, I also tried not calling them and had 2.1 in return
SDL_GL_SetAttribute(SDL_GLattr::SDL_GL_DOUBLEBUFFER, 1); // 1
SDL_GL_SetAttribute(SDL_GLattr::SDL_GL_RED_SIZE, 8); // 8
SDL_GL_SetAttribute(SDL_GLattr::SDL_GL_GREEN_SIZE, 8); // 8
SDL_GL_SetAttribute(SDL_GLattr::SDL_GL_BLUE_SIZE, 8); // 8
SDL_GL_SetAttribute(SDL_GLattr::SDL_GL_DEPTH_SIZE, 24); // 16
SDL_GL_SetAttribute(SDL_GLattr::SDL_GL_STENCIL_SIZE, 8); // 0
//SDL_GLContext ctx = SDL_GL_CreateContext(w); // nothing gets rendered if this is called here instead
//SDL_GL_MakeCurrent(w, ctx); // doesn't help
if (ctx == 0){ // never fails
cout << "context creation error" << endl;
}
glewExperimental = true;
GLenum e = GLEW_OK;
e = glewInit();
if (e != GLEW_OK){ // never fails
cout << "glew error" << endl;
}
My stencil buffer wasn't working so I came to this in my investigation. All SDL_GL_SetAttribute functions return 0. The same code (excluding glew) was tested on a laptop with Ubuntu and returns 24/8 for depth/stencil. What am I doing wrong?
The documentation of SDL_GL_SetAttribute states
Use this function to set an OpenGL window attribute before window creation.
This functions do not have any effect if called after the window has been created.
You cannot change the attributes of an existing context. SDL_GL_SetAttribute will set the attributes that SDL will use the next time a GL context is created.
Now you actually tried to create the context later:
//SDL_GLContext ctx = SDL_GL_CreateContext(w); // nothing gets rendered if this is called here instead
The most likely explanation is that the
SDL_GL_SetAttribute(SDL_GLattr::SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); // doesn't help
actually does work, and your code is just not comatible with a core profile.

Running an opencd function (VideoWriter) in Debug mode and Release mode

I was trying to build and run the code below (Visual Studio 2013). Building is fine, but the code runs only in Debug mode, but fails in Release mode. I can see that the code stops when it tries to call the VideoWriter function, and I assume that it might be related to the file permission. But, why is it okay in Debug mode? It's a bit confusing.. Can somebody tell what's happening here or what I can further try to nail down the problem?
Thanks.
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
VideoCapture cap(0);
// Get size of frames
Size S = Size((int)cap.get(CV_CAP_PROP_FRAME_WIDTH), (int)
cap.get(CV_CAP_PROP_FRAME_HEIGHT));
// Make a video writer object and initialize it at 30 FPS
VideoWriter put("output.mpg", CV_FOURCC('M', 'P', 'E', 'G'), 30, S);
if (!put.isOpened())
{
cout << "File could not be created for writing. Check permissions" << endl;
return -1;
}
namedWindow("Video");
// Play the video in a loop till it ends
while (char(waitKey(1)) != 'q' && cap.isOpened())
{
Mat frame;
cap >> frame;
// Check if the video is over
if (frame.empty())
{
cout << "Video over" << endl;
break;
}
imshow("Video", frame);
put << frame;
}
return 0;
}

How to enable Box2d debug draw with Coco2d-x 3.0 beta 2

How I should enable debug draw with Cocos2d-x 3.0? There are some codes that do that with cocos2d-x 2.0 but they don't even compile on Cocos2d-x. Unfortunately I am new to both cocos2d-x and Box2d and I don't know how to port them. That would be great if you would share the method how you draw shapes.
EDIT:
I have found this:
http://blog.csdn.net/tian2kong/article/details/20386213
I have overridden the draw method of my applications main Layer like this:
void HelloWorld::draw()
{
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION);
kmGLPushMatrix();
m_world->drawDebugData();
kmGLPopMatrix();
}
And also have done this:
GLESDebugDraw *debugDraw = new GLESDebugDraw(PTM_RATIO);
m_world.SetDebugDraw(debugDraw);
uint32 flags = 0;
flags += b2Draw::e_shapeBit;
/*
flags += b2Draw::e_jointBit;
flags += b2Draw::e_centerOfMassBit;
flags += b2Draw::e_aabbBit;
flags += b2Draw::e_pairBit;
*/
debugDraw->SetFlags(flags);
And it worked! But when I addChild a sprite, the shapes stay blow my sprites. How to bring them front?
Open spotlight and search for GLES-Render.cpp. This file will be there in a path in the cocos2dx folder. Open the enclosing folder and drag the files GLES-Render.h and GLES-Render.cpp to the project.
Then add the following code in the init method
b2Draw *m_debugDraw = new GLESDebugDraw(PTM_RATIO);
uint32 flags = 0;
flags += b2Draw::e_shapeBit;
flags += b2Draw::e_jointBit;
flags += b2Draw::e_aabbBit;
flags += b2Draw::e_pairBit;
flags += b2Draw::e_centerOfMassBit;
m_debugDraw->SetFlags(flags);
H_world->SetDebugDraw(m_debugDraw);
Then add the draw method.
void HelloWorld::draw()
{
kmGLPushMatrix();
H_world->DrawDebugData();
kmGLPopMatrix();
}
Don't forget to include GLES-Render.h
You CANNOT bring bodies to front. if you want to see your bodies behind your sprites you can set their opacity as sprite->setOpacity(100).
i use the following code to draw
void GameLayer:: setPhysics() {
b2Vec2 gravity = b2Vec2(0.0f,0.0f);// Initializing World
world = new b2World(gravity);
m_debugDraw = new GLESDebugDraw( PTM_RATIO );
world->SetDebugDraw(m_debugDraw);
world->SetAllowSleeping(false);
uint32 flags = 0;
flags += b2Draw::e_shapeBit;
// flags += b2Draw::e_jointBit;
// flags += b2Draw::e_aabbBit;
// flags += b2Draw::e_pairBit;
// flags += b2Draw::e_centerOfMassBit;
m_debugDraw->SetFlags(flags);
contactListener = new MyContactListener(this);
world->SetContactListener(contactListener);
}
which is same as yours.... can you please xplain your problem a bit more
For Debug Draw You Need Two File
File Download Link
After that
Inclue that file
and create a Vaiable in .h file
GLESDebugDraw *debugDraw;
and in .ccp file
b2Vec2 gravity;
gravity.Set(0.0f, -9.8f);
this->world = new b2World(gravity);
this->debugDraw = new GLESDebugDraw(PTM_RATIO);
this->world->SetDebugDraw(debugDraw);
uint32 flags = 0 ;
flags += b2Draw::e_shapeBit ;
flags += b2Draw::e_jointBit;
// flags + = b2Draw :: e_aabbBit;
// flags + = b2Draw :: e_pairBit;
flags += b2Draw::e_centerOfMassBit;
this->debugDraw->SetFlags (flags);
in . h file
void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags);
in .cpp
void HelloWorld::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
Layer::draw(renderer, transform, flags);
Director* director = Director::getInstance();
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION );
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
world->DrawDebugData();
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
NOW Enjoy Debug draw
You could simply add another layer above your current layer.
And you can add the code you post here in the up layer then everything should be working.

OpenCV, Qt, imread, namedWindow, imshow does not work

In the .pro file:
QT += core
QT -= gui
TARGET = latihan_2
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += E:\OpenCV\OpenCV\opencv\build\include
LIBS += E:\OpenCV\OpenCV\opencv\build\x86\mingw\lib\libopencv_core246.dll.a
LIBS += E:\OpenCV\OpenCV\opencv\build\x86\mingw\lib\libopencv_highgui246.dll.a
LIBS += E:\OpenCV\OpenCV\opencv\build\x86\mingw\lib\libopencv_imgproc246.dll.a
LIBS += E:\OpenCV\OpenCV\opencv\build\x86\mingw\lib\libopencv_features2d246.dll.a
LIBS += E:\OpenCV\OpenCV\opencv\build\x86\mingw\lib\libopencv_calib3d246.dll.a
In main.cpp:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(){
//read image
Mat image = imread("img.jpg", 1);
//create image window named "My image"
namedWindow("My Image", CV_WINDOW_AUTOSIZE);
//show the image on window
imshow("My image", image);
//wait key for 5000ms
waitKey(5000);
return 1;
}
When I hit run, there is no error, but it only shows a black window named qtcreator_process_stub.exe.
Why the "My image" window doesn't come out and shows the img.jpg?
I use Qt creator 2.8.1, based on Qt 5.1.1, and openCV-2.4.6.0.
You could also display a cv::Mat on a Qt window. I demonstrate how to do that on cvImage. The code below is adapted from cvImage::_open():
std::string filename = ...
cv::Mat mat = cv::imread(filename);
// Since OpenCV uses BGR order, we need to convert it to RGB
// NOTE: OpenCV 2.x uses CV_BGR2RGB, OpenCV 3.x uses cv::COLOR_BGR2RGB
cv::cvtColor(mat, mat, cv::COLOR_BGR2RGB)
// image is created according to Mat dimensions
QImage image(mat.size().width, mat.size().height, QImage::Format_RGB888);
// Copy cv::Mat to QImage
memcpy(image.scanLine(0), mat.data, static_cast<size_t>(image.width() * image.height() * mat.channels()));
// Display the QImage in a QLabel
QLabel label;
label.setPixmap(QPixmap::fromImage(image));
label.show();
First guess is that the image is in the wrong path, so first test should be to specify the full path to the image.
Also check the return value of your program (make sure the it doesn't return some crash error code - be consistent and return 0 for success and other values for fail).
And a little bit of coding that tells you where the code fails doesn't hurt, so check image.data or you can also use image.empty():
if(! image.data )
{
std::cout << "No image to display";
//can be any other method to display the error: qDebug, a messagebox...
//you can also
return 1;
}
else
{
//use the image
//if nothing goes wrong:
//return 0;
}
Check Projects->Run Settings ->Run in Terminal checkbox. If it is disabled, enable it.
I faced same problem and I solved it by fixing path environment variable. In my path environment variable I added some opencv folders wrongly, then I deleted them and add only bin folder for opencv DLLs and then the problem was solved.

How do I poke the flag in a win32 PE that controls console window display

I have an executable which is part of a batch process. This one executable opens a console window, which is annoying since it's useless to the end user and steals focus away from their active task.
We can't compile a new version from of this EXE from source (easily). Is there an easy way to twiddle this setting in the PE?
Found it.
editbin.exe /subsystem:windows foo.exe
editbin.exe is part of MSVC
I have wrote it with python based on the PE specification
http://msdn.microsoft.com/en-us/library/windows/hardware/gg463119.aspx
I'm not sure that Windows EXE binaries with console|windows subsystem have same
Entry Point Format (with same arguments), but it seem that it is so.
Python Code:
import sys
import struct
if len(sys.argv) < 4:
print "Change Exe Run Mode Application by burlachenkok#gmail.com\nNot sufficient parametrs. 'exe_src_name.exe' 'exe_dest_name.exe' 'to_console' or 'to_windows'"
sys.exit(-1)
source = open(sys.argv[1], "rb")
dest = open(sys.argv[2], "w+b")
dest.write(source.read())
dest.seek(0x3c)
(PeHeaderOffset,)=struct.unpack("H", dest.read(2))
dest.seek(PeHeaderOffset)
(PeSignature,)=struct.unpack("I", dest.read(4))
if PeSignature != 0x4550:
print "Error in Find PE header"
dest.seek(PeHeaderOffset + 0x5C)
if sys.argv[3].strip() == "to_console":
# console mode
dest.write(struct.pack("H", 0x03))
elif sys.argv[3].strip() == "to_windows":
# window mode
dest.write(struct.pack("H", 0x02))
else:
print "Wrong Format: '" + sys.argv[3] + "'"
source.close()
dest.close()
print "Completed succesfully.."
Here is a node version of the Python code :)
const fs = require('fs');
const bufferpack = require('bufferpack');
if(process.argv.length < 4) {
console.log("Change Exe Run Mode Application \nNot sufficient parameters. 'exe_src_name.exe' 'exe_dest_name.exe' 'to_console' or 'to_windows'");
process.exit(-1);
}
function read(f, size, offset) {
if(typeof size == 'undefined') size = 1;
if(typeof offset == 'undefined') offset = -1;
const buffer = Buffer.alloc(size);
fs.readSync(f, buffer, 0, size, offset);
return buffer;
}
const source = fs.openSync(process.argv[2], "r");
const dest = fs.openSync(process.argv[3], "w+");
fs.writeSync(dest, read(source, fs.statSync(process.argv[2]).size, 0));
const PeHeaderOffset = bufferpack.unpack('<H', read(dest, 2, 0x3c)).pop();
const PeSignature = bufferpack.unpack('<I', read(dest, 4, PeHeaderOffset)).pop();
if(PeSignature != 0x4550) {
console.log("Error in Find PE header");
process.exit(-1);
}
if(process.argv[4] == "to_console") {
// console mode
fs.writeSync(dest, bufferpack.pack('<H', [0x03]), 0, 1, PeHeaderOffset + 0x5C);
} else if(process.argv[4] == "to_windows") {
// window mode
fs.writeSync(dest, bufferpack.pack('<H', [0x02]), 0, 1, PeHeaderOffset + 0x5C);
} else {
console.log("Wrong Format: '" + process.argv[4] + "'");
}
fs.closeSync(source);
fs.closeSync(dest);
console.log("Completed succesfully.");

Resources