matlab使用usb和gige 網口相機


 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

                                        辛苦原創所得,轉載請注明出處   

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 

~matlab 使用普通usb攝像頭

需要先安裝支持包, 在matlab命令行中輸入supportPackageInstaller, 之后選擇 usb webcam 和 OS Generic Video Interface 安裝包,這時候需要登錄賬號,需要自己去

https://cn.mathworks.com/mwaccount/register?uri=https%3A%2F%2Fcn.mathworks.com%2Fmatlabcentral%2Ffileexchange%2F45182-matlab-support-package-for-usb-webcams

注冊一個賬號.然后就可以安裝了,這里需要一個不錯的網絡,有些網絡會出現安裝失敗的情況.

之后可以用如下語句進行測試

clc; clear all; close all;
vid = videoinput('winvideo',1); %'YUY2_160x120'    'YUY2_176x144'    'YUY2_320x240'    'YUY2_352x288'    'YUY2_640x480'
vid2 = videoinput('winvideo',2);
% preview(vid);
% preview(vid2);

 具體參考網頁如下,matlab2017版本以下網頁方法更好

https://cn.mathworks.com/help/imaq/acquire-images-from-gige-vision-cameras.html

屬性配置參照如下網頁

http://cn.mathworks.com/help/imaq/set-properties-for-gige-acquisition.html

matlab 使用gige網口相機

~ matlab環境配置和系統配置

首先在matlab窗口輸入supportPackageInstaller安裝gige vision toolbox, 這里如果網絡不好需要多試幾次. 之后可以輸入obj = videoinput('gige',1)來查看gige設備信息.也可以在程序窗口輸入 這條命令來定義接口.

 

gige為千兆網口,所以要求連接的網卡也要達到千兆.網卡的配置如下

1.網卡的jumbo pocket/巨型幀要變為9014

2.receive buffers要設置為2048

3.gige adapter 屬性要設置如下(有的機器可能沒有這個選項)

4.關閉防火牆對其的限制,比如我的機器驅動默認安裝在如下位置

C:\Program Files (x86)\SVS-VISTEK GmbH\SVS GigE SDK\SVS GigE FilterDriver

找到如下標志程序

令防火牆不對其限制.

 具體配置可以參看如下網頁

https://www.mathworks.com/matlabcentral/answers/uploaded_files/41167/GigEVisionQuickStart.pdf

 

~ 錯誤:Block/frame 23 is being dropped because a lost packet is unable to be resent.There are several possible causes for packets being lost. See the troubleshooting information in the "Configuring GigE Vision Devices" section of the Image Acquisition Toolbox documentation.

參看網頁

https://cn.mathworks.com/matlabcentral/answers/91834-how-do-i-calculate-the-packet-delay-for-a-gige-vision-camera-to-prevent-dropped-frames

 

~ matlab讀取圖像時候可能出現有相機能夠順利讀取,另一個相機不能順利讀取

程序中按照如下語句定義的vid2,用完后一定要使用delete刪除,語句如下

vid2 = videoinput('gige',1);

delete(vid2);

 

-------------------------------------------------------------------------------------------------------------------------------------------------------

下面是程序,還沒有調的很好

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 利用網口打開攝像機
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clc; close all;
gigecamlist
g1 = gigecam('192.168.1.1')
g2 = gigecam('10.141.242.1')

% pause(30);
g1.ExposureTime = 250000; %設置屬性,如曝光度
% g1.Timeout  = 30;
g2.ExposureTime = 250000; %設置屬性,如曝光度
% g2.Timeout  = 30;
% closePreview(g)
preview(g1);
preview(g2);

while(1)
    tic;

    img1 = snapshot(g1);
    img2 = snapshot(g2);
    %
    % figure(1), imshow(img1);
    % figure(2), imshow(img2);
    
    % %
    
    % Rectify the images using the 'valid' output view
%     [J1_valid,J2_valid] = rectifyStereoImages(img1,img2,stereoParams,'OutputView','full');
    
    
    % %
    % Display the result.
    % figure(1);
    % imshowpair(J1_valid,J2_valid,'falsecolor','ColorChannels','red-cyan');
    
%     figure(3), imshow(J1_valid);
%     figure(4), imshow(J2_valid);
% imwrite(J1_valid,'save.jpg');
    
    toc
    
end
clear g1;
clear g2


% vid1 = videoinput('gige',1);
% preview(vid1);

% vid2 = videoinput('gige',2);
% preview(vid2);

% vid2 = videoinput('winvideo',2);
% preview(vid);



% preview(vid2);
% h2 = preview(vid2);

% pause(30);
% h11 = figure(1);
% h22 = figure(2);

% while(ishandle(h1) && ishandle(h2))
image1 = getsnapshot(vid1);
figure(1), imshow(image1);
figure(2), imshow(image2);
% imwrite(image1, 'left.bmp');

% image2 = getsnapshot(vid2);
% imwrite(image2, 'right.bmp');

figure(3);
% image2 = getsnapshot(vid2);
%
% pause(5);
%
% figure(1),imshow(image1);
% figure(2),imshow(image2);


% figure(2),imshow(image2);
% drawnow;
% % figure(2),imshow(image2);
% end

% clc;clear all;
% cam = webcam(1);
% preview(cam);


delete(vid1);
% delete(vid2);

 

~ matlab常用的視覺圖像工具箱有下面三個

  Image Processing Toolbox (圖像處理工具箱)
  Computer Vision System Toolbox (計算機視覺工具箱)
  Image Acquisition Toolbox (圖像采集工具箱)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM