2012-08-15 66 views
2

我有一個USB攝像頭(DCC1645),我試圖通過MATLAB進行接口。我已經成功它連接到它通過ActiveX:如何從MATLAB存儲的設備控制的存儲器中使用ActiveX控制的數據

cam = actxcontrol('uc480.uc480Ctrl.1'); 

,我可以在它上面運行等多種功能,我現在想知道如何獲取圖像數據;相關函數返回一個指針到圖像存儲:

GetImageMem() returns the pointer to the internal image memory where the image is stored. 

所以如果我運行

loc = cam.GetImageMem(); 

然後loc是代表內存位置的一些大數目。它得到了多少內存存儲的功能如下:

InquireImageMem(LONG* nWidth, LONG* nHeight, LONG*nBits, LONG* nPitch) 
reads the properties of the allocated image memory. The function returns 
the properties of the actual image buffer, as returned by GetImageMem 

nWidth  Receives the width of the allocated image memory. 
nHeight Receives the height of the allocated image memory. 
nBits  Receives the bits per pixel of the allocated image memory. 
nPitch  Receives the pitch of the allocated image memory. The pitch 
      is the number of bytes from the start of a line to the start 
      of the next line. 

所以我的問題是雙重的:

  1. 你如何給一個指針的內存和大小的實際數據?
  2. 如何傳遞函數的引用(例如LONG * nwidth)?有沒有像我應該使用libpointer的東西?

謝謝!

+0

我想出的答案爲第2部分: '[A,B,C,d] = cam.InquireImageMem(0,0,0,0);' – 2012-08-15 15:07:58

回答

1

1)簡短的答案是「否」,即使你知道它在哪裏以及它有多大,你也不能在MATLAB中將內存拉出內存。但是,此特定相機由Image Acquisition toolbox支持,並附有相關教程here

長的答案是,如果你用一些mex/c補充你的MATLAB代碼,你可以使它工作,雖然我沒有任何細節。

2)正如我在評論中寫道原來的問題,

[a,b,c,d] = cam.InquireImageMem(0,0,0,0); 

會工作。使用cam.methods('-full')可以獲得庫中所有可能方法的列表及其所需的輸入/輸出。

1

嘗試使用的uEye .NET用戶層 http://en.ids-imaging.com/manuals/uEye_SDK/EN/uEye_DotNET_Manual/index.html?ueyeinstallation.htm

下面是一些例子MATLAB代碼


clear all 

close all 

computer_type=computer; 

if strcmp (computer_type,'PCWIN64') 

NET.addAssembly('C:\Program Files\IDS\uEye\Develop\DotNet\x64\uEyeDotNetUserLayer.dll'); 

NET.addAssembly('C:\Program Files\IDS\uEye\Develop\DotNet\x64\uEyeDotNetApiLayer.dll'); 

elseif strcmp (computer_type,'PCWIN') 

NET.addAssembly('C:\Program Files\IDS\uEye\Develop\DotNet\x86\uEyeDotNetUserLayer.dll'); 

NET.addAssembly('C:\Program Files\IDS\uEye\Develop\DotNet\x86\uEyeDotNetApiLayer.dll'); 

end 

cam = uEye.Camera; 

cam.Exit(); 

CAM_ID=2; 

exposure_ms=2; 

cam.Init(CAM_ID); 

ColorMode=uEye.Defines.ColorMode.SENSOR_RAW8; 

cam.PixelFormat.Set(11); 

cam.Trigger.Set(uEye.Defines.TriggerMode.Software); 

[tmp, memId] = cam.Memory.Allocate(true); 

[tmp, imgWidth] = cam.Memory.GetWidth(memId); 

[tmp, imgHeight] = cam.Memory.GetHeight(memId); 

[tmp, imgBpp] = cam.Memory.GetBitsPerPixel(memId); 

imgBpp = imgBpp/8; 

imgSize = imgWidth * imgHeight * imgBpp; 

bufArr = NET.createArray('System.Byte', imgSize); 

soft = uEye.Software(CAM_ID); 

soft.SetEnableAutoWhiteBalance(false); 

soft.SetEnableAutoGain(false); 

soft.SetEnableAutoShutter(false); 

cam.Timing.Exposure.Set(exposure_ms); % msec 

cam.Acquisition.Freeze(1); 

[tmp, camMemPtr] = cam.Memory.ToIntPtr; 

System.Runtime.InteropServices.Marshal.Copy(camMemPtr, bufArr, 0, imgSize); 

img = uint8(bufArr); 

myImage=reshape(img, imgWidth, imgHeight)'; 
2

根據IDS的COM框架不再支持,所以你應該考慮切換到NET框架。我認爲lunarquaker的這篇文章指的是舊版本。這裏是一個代碼片段,如果複製並粘貼到Matlab應該沒有修改相機型號#UI-1220SE-M-GL(它對我來說)。您可以更改彩色相機的像素格式。

在Matlab 8.3.0.532(R2014a)測試,uEyeDotNet版本= 1.5.3.0和IDS /的uEye v4.40.0.0

注意 - 你必須嘗試再次初始化同一個鏡頭前 「退出」否則你會發現自己處於一個麻煩的世界。

% 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 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 
相關問題