필터 지우기
필터 지우기

uEye USB camera in Matlab?

조회 수: 47 (최근 30일)
Serena
Serena 2011년 9월 14일
댓글: Will Reeves 2022년 5월 23일
Hi,
I have a uEye camera that I want to use in matlab but the imaqtool doesn't seem to recognise the camera. The camera works fine in its own software so I don't think there's a problem on that end of things. Does anyone know how to get Matlab to recognise the camera?
Thanks,
Serena
  댓글 수: 1
Adam Wyatt
Adam Wyatt 2015년 6월 4일
편집: Adam Wyatt 2016년 12월 7일
Have a look at my blog for information on how to do this:
  1. .NET interface
  2. mex interface

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Wyatt
Adam Wyatt 2014년 12월 9일
There are a couple of methods:
  1. Write a dll C-wrapper that can interface between Matlab and the uEye SDK and then use the loadlibrary functions (see documentation "Call C Shared Libraries").
  2. Similar to above, but write a mex-wrapper and compile into a mex code (see documentation "MEX-File Creation API").
  3. Connect to the .NET library (see documentation "Cell .NET Libraries").
I had previously used the first two methods, but this makes it difficult to maintain, and requires reproducing every feature you want. I am now using the latter method, which provides direct support to all features of the .NET assembly (use the uEye .NET SDK manual for further information and functions).
Using the .NET assembly is not quite as straightforward as with C# because Matlab does not directly support pointers, but there is a workaround as pointed out below.
Remember to "EXIT" your camera before trying to re-initialise the same camera
% Add NET assembly if it does not exist
% May need to change specific location of library
asm = System.AppDomain.CurrentDomain.GetAssemblies;
if ~any(arrayfun(@(n) strncmpi(char(asm.Get(n-1).FullName), ...
'uEyeDotNet', length('uEyeDotNet')), 1:asm.Length))
NET.addAssembly(...
'C:\Program Files\IDS\uEye\Develop\DotNet\signed\uEyeDotNet.dll');
end
% Create camera object handle
cam = uEye.Camera;
% Open 1st available camera
% Returns if unsuccessful
if ~strcmp(char(cam.Init), 'SUCCESS')
error('Could not initialize camera');
end
% Set display mode to bitmap (DiB)
if ~strcmp(char(cam.Display.Mode.Set(uEye.Defines.DisplayMode.DiB)), ...
'SUCCESS')
error('Could not set display mode');
end
% Set colormode to 8-bit RAW
if ~strcmp(char(cam.PixelFormat.Set(uEye.Defines.ColorMode.SensorRaw8)), ...
'SUCCESS')
error('Could not set pixel format');
end
% Set trigger mode to software (single image acquisition)
if ~strcmp(char(cam.Trigger.Set(uEye.Defines.TriggerMode.Software)), 'SUCCESS')
error('Could not set trigger format');
end
% Allocate image memory
[ErrChk, img.ID] = cam.Memory.Allocate(true);
if ~strcmp(char(ErrChk), 'SUCCESS')
error('Could not allocate memory');
end
% Obtain image information
[ErrChk, img.Width, img.Height, img.Bits, img.Pitch] ...
= cam.Memory.Inquire(img.ID);
if ~strcmp(char(ErrChk), 'SUCCESS')
error('Could not get image information');
end
% Acquire image
if ~strcmp(char(cam.Acquisition.Freeze(true)), 'SUCCESS')
error('Could not acquire image');
end
% Extract image
[ErrChk, tmp] = cam.Memory.CopyToArray(img.ID);
if ~strcmp(char(ErrChk), 'SUCCESS')
error('Could not obtain image data');
end
% Reshape image
img.Data = reshape(uint8(tmp), [img.Width, img.Height, img.Bits/8]);
% Draw image
himg = imshow(img.Data, 'Border', 'tight');
% Acquire & draw 100 times
for n=1:100
% Acquire image
if ~strcmp(char(cam.Acquisition.Freeze(true)), 'SUCCESS')
error('Could not acquire image');
end
% Extract image
[ErrChk, tmp] = cam.Memory.CopyToArray(img.ID);
if ~strcmp(char(ErrChk), 'SUCCESS')
error('Could not obtain image data');
end
% Reshape image
img.Data = reshape(uint8(tmp), [img.Width, img.Height, img.Bits/8]);
% Draw image
set(himg, 'CData', img.Data);
drawnow;
end
% Close camera
if ~strcmp(char(cam.Exit), 'SUCCESS')
error('Could not close camera');
end

추가 답변 (3개)

Robert Style
Robert Style 2016년 2월 8일
Hey, I had this problem too. I installed all the drivers for the camera that came with the instructions, and tried all the code above (which was a bit tricky for me as a newbie). Eventually I got it to work by just installing the winvideo driver:
After that, imaqtool seemed to work perfectly.. worth trying out if you haven't got it already installed.
  댓글 수: 2
MD SAZZATH HOSSAIN
MD SAZZATH HOSSAIN 2020년 12월 13일
Where Can I get the drivers ?
Will Reeves
Will Reeves 2022년 5월 23일
I tired this and it worked well, but you loose all access to key settings. Exposure time for instance.

댓글을 달려면 로그인하십시오.


Jaromir
Jaromir 2012년 1월 4일
Hi,
I have the same problem. How did you solve it?
Thanks,
Jaromir

Wolfgang
Wolfgang 2014년 8월 4일
Hi Serena and Jaromir, did you manage to control the camera? I'm having similar problems at the moment... Thank you for your help!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by