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 (图像采集工具箱)
请发表评论