What could alter the behavior of a c++ library in a mex function ?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I am trying to interface a camera to matlab in a context of development of a microscope. The idea is to control it (change parameters like exposure time/frame rate/etc and of course acquire images) directly from the Matlab environnement.
The camera comes with a developement kit in c++ that works perfectly. I would like to wrap those c++ functions in a mex function that I could call from matlab in order to control the camera directly from Matlab where I intend to manipulate the images/instrument more or less in real time.
So I first wrote some code in c++ using the dedicated camera provider library and exempled functions, compiled it, and tested it. And it works great! For exemple the following code asks the camera on how many bites are coded each pixel of the images the camera stream. The answer is suppose to be 8 or 12 bites/pixel) and indeed when compiling/calling this function I can read "PixelFormat: Mono8,Mono12,Mono12Packed" in the terminal.
#include <EmergentCameraAPIs.h>
#include <iostream>
#define SUCCESS 0
#define MAX_CAMERAS 1
void Camera_connection_routine(Emergent::CEmergentCamera* camera);
int main(int argc, char *argv[])
{
// Camera connection
Emergent::CEmergentCamera camera;
Camera_connection_routine(&camera);
// Using a function from the library to do something with the camera
const unsigned long enumBufferSize = 1000;
char enumBuffer[enumBufferSize];
unsigned long enumBufferSizeReturn = 0;
Emergent::EVT_CameraGetEnumParamRange(&camera, "PixelFormat", enumBuffer, enumBufferSize, &enumBufferSizeReturn);
std::cout << "PixelFormat: " << enumBuffer << "\n";
};
But if I put this code in mex format and compile it in Matlab I get another answer : not "PixelFormat: Mono8,Mono12,Mono12Packed"" as I should but "PixelFormat: Mono8,Mono10,Mono10Packed," !
More generally the majority of functions from the library work as they should in the matlab environnement but some do not work as expected sending different results then the one I get with the cpp function compiled with g++ in the terminal.
What could be the cause of this discrepancy ? What can I be doing that alters the way the library works/is called ?
How I compile the mex function (no error or warnign message during compilation) :
header_path = ['-I' '/private/interface_camera/include'];
lib_path = ['-L' '/stillprivate/interface_camera/lib'];
mex(header_path,lib_path,'-lEmergentCamera','mex_exemple4matlab_community.cpp')
How I wrap in a mex :
#include "mex.hpp"
#include "mexAdapter.hpp"
#include <EmergentCameraAPIs.h>
#define SUCCESS 0
#define MAX_CAMERAS 1
void Camera_connection_routine(Emergent::CEmergentCamera* camera);
class MexFunction : public matlab::mex::Function {
public:
void operator()(matlab::mex::ArgumentList outputs, matlab::mex::ArgumentList inputs) {
// Camera connection
Emergent::CEmergentCamera camera;
Camera_connection_routine(&camera);
// Using a function from the library to do something with the camera
const unsigned long enumBufferSize = 1000;
char enumBuffer[enumBufferSize];
unsigned long enumBufferSizeReturn = 0;
Emergent::EVT_CameraGetEnumParamRange(&camera, "PixelFormat", enumBuffer, enumBufferSize, &enumBufferSizeReturn);
std::cout << "PixelFormat: " << enumBuffer << "\n";
}
};
Thank you very much !
9 comentarios
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre GigE Vision Hardware en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!