Running IDS uEye camera at mono12 format using .NET Interface

조회 수: 5 (최근 30일)
elad
elad 2019년 3월 16일
댓글: Jun 2023년 3월 10일
Hi
I am trying to run IDS uEye camera at mono 12 format using .NET Interface, but I am having troubles.
it seems that it can take the picture from the camera (cam.Acquisition.Freeze(true) gives success) but it fails to copy the image from the RAM (cam.Memory.CopyToArray(img.ID) gives INVALID_PARAMETER). In mono8/raw8 it works just fine.
In addition, it seems that the cam.Acquisition.Freeze(true) command is working intermittently.
Does anybody know how to fix it?
This is the simple code I tried:
try char(cam.Exit)
catch
disp('Could not close camera');
end
clear all
close all
% 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
if ~exist('cam', 'var') || isempty(cam)
cam = uEye.Camera();
end
% Open 1st available camera
% Returns if unsuccessful
if ~cam.Device.IsOpened
if ~isequal(cam.Init(), uEye.Defines.Status.Success)
error('Could not initialize camera');
end
end
% Set colormode to 12-bit RAW
if ~isequal(cam.PixelFormat.Set(uEye.Defines.ColorMode.Mono12), ...
uEye.Defines.Status.Success)
error('Could not set pixel format');
end
% set camera pixel clock to match mono12 format
if ~isequal(cam.Timing.PixelClock.Set(80), ...
uEye.Defines.Status.Success)
error('Could not set pixel clock');
end
% Set trigger mode to software (single image acquisition)
if ~isequal(cam.Trigger.Set(uEye.Defines.TriggerMode.Software), ...
uEye.Defines.Status.Success)
error('Could not set trigger format');
end
% Allocate image memory
[ErrChk, img.ID] = cam.Memory.Allocate(true);
if ~isequal(ErrChk, uEye.Defines.Status.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 ~isequal(ErrChk, uEye.Defines.Status.Success)
error('Could not get image information');
end
% Acquire image
if ~isequal(cam.Acquisition.Freeze(true), ...
uEye.Defines.Status.Success)
error('Could not acquire image');
end
% Extract image
[ErrChk, tmp] = cam.Memory.CopyToArray(img.ID);
if ~isequal(ErrChk, uEye.Defines.Status.Success)
error('Could not obtain image data');
end
% Reshape image
img.Data = reshape(uint16(tmp), [img.Width, img.Height, img.Bits/8]);
% Draw image
% himg = imshow(img.Data, 'Border', 'tight');
himg = imagesc(img.Data);
% Acquire & draw 100 times
if ~exist('N', 'var') || isempty(N)
N = 20;
end
for n=1:N
% Acquire image
if ~isequal(cam.Acquisition.Freeze(true), ...
uEye.Defines.Status.Success)
warning('Could not acquire image');
end
% Extract image
[ErrChk, tmp] = cam.Memory.CopyToArray(img.ID);
if ~isequal(ErrChk, uEye.Defines.Status.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 exist('NoExit', 'var') && ~isempty(NoExit) && NoExit
return;
end
if ~isequal(cam.Exit, uEye.Defines.Status.Success)
error('Could not close camera');
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Support Package for USB Webcams에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by