最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 正文

MATLAB图像采集

来源:动视网 责编:小OO 时间:2025-10-01 19:19:20
文档

MATLAB图像采集

进行的步骤如下:1.安装并配置图像采集设备2.获取在图像采集工具箱中能唯一标识此图像采集设备的信息,此信息在创建视频输入对象时要用到。这些信息包括:Adaptorname软件适配器名,DeviceID硬件设备的ID,Videoformat视频格式。imaqhwinfo用于检测适配器名,我的电脑安装了一个USB摄像头,所以检测到一个安装了的适配器'winvideo'。之后可以使用这个适配器名连接视频采集设备。复制内容到剪贴板代码:imaqhwinfoans=  InstalledAdaptors
推荐度:
导读进行的步骤如下:1.安装并配置图像采集设备2.获取在图像采集工具箱中能唯一标识此图像采集设备的信息,此信息在创建视频输入对象时要用到。这些信息包括:Adaptorname软件适配器名,DeviceID硬件设备的ID,Videoformat视频格式。imaqhwinfo用于检测适配器名,我的电脑安装了一个USB摄像头,所以检测到一个安装了的适配器'winvideo'。之后可以使用这个适配器名连接视频采集设备。复制内容到剪贴板代码:imaqhwinfoans=  InstalledAdaptors
进行的步骤如下:

1. 安装并配置图像采集设备

2. 获取在图像采集工具箱中能唯一标识此图像采集设备的信息,此信息在创建视频输入对象时要用到。这些信息包括:Adaptor name软件适配器名,Device ID硬件设备的ID,Video format视频格式。

imaqhwinfo用于检测适配器名,我的电脑安装了一个USB摄像头,所以检测到一个安装了的适配器'winvideo'。之后可以使用这个适配器名连接视频采集设备。 

复制内容到剪贴板代码:imaqhwinfo

ans = 

    InstalledAdaptors: {'winvideo'}

        MATLABVersion: '7.0 (R14)'

          ToolboxName: 'Image Acquisition Toolbox'

       ToolboxVersion: '1.5 (R14)'

要查看特定设备的设备ID,可使用如下命令: 

复制内容到剪贴板代码:info = imaqhwinfo('winvideo')

info = 

       AdaptorDllName: 'D:\\MATLAB7\oolbox\\imaq\\imaqadaptors\\win32\\mwwinvideoimaq.dll'

    AdaptorDllVersion: '1.5 (R14)'

          AdaptorName: 'winvideo'

            DeviceIDs: {[1]  [2]}

           DeviceInfo: [1x2 struct]

在上面的DeviceIDs可以看到两个数组,每一个代表一个设备,我的摄像头设备为:USB 视频设备 #2,这里可能就对应着[2],【对应的是1,哈哈】。

要继续获得更多有关设备的信息可以如下进行: 

复制内容到剪贴板代码:dev_info = imaqhwinfo('winvideo', 1)

复制内容到剪贴板代码:dev_info2 = imaqhwinfo('winvideo', 2)

我的电脑返回信息如下:

dev_info = 

          DefaultFormat: 'YUY2_0x480'

    DeviceFileSupported: 0

             DeviceName: 'USB 视频设备'

               DeviceID: 1

      ObjectConstructor: 'videoinput('winvideo', 1)'

       SupportedFormats: {'YUY2_0x480'  'YUY2_352x288'  'YUY2_320x240'  'YUY2_176x144'  'YUY2_160x120'}

(这个应该是我的战车摄像头)

dev_info2 = 

          DefaultFormat: 'RGB24_0x480'

    DeviceFileSupported: 0

             DeviceName: 'Vimisoft Camera'

               DeviceID: 2

      ObjectConstructor: 'videoinput('winvideo', 2)'

       SupportedFormats: {1x9 cell}

(这个应该是软件的什么东西?)

3. 创建视频输入对象

使用videoinput函数创建视频输入对象,此函数使用上步得到的适配器名、设备ID和设定的视频格式创建对象。这里只需要适配器名,videoinput函数使用默认的设备ID和视频格式。 

复制内容到剪贴板代码:vid = videoinput('winvideo')

Summary of Video Input Object Using 'USB 视频设备'.

   Acquisition Source(s):  input1 is available.

  Acquisition Parameters:  'input1' is the current selected source.

                           10 frames per trigger using the selected source.

                           'YUY2_0x480' video data to be logged upon START.

                           Grabbing first of every 1 frame(s).

                           Log data to 'memory' on trigger.

      Trigger Parameters:  1 'immediate' trigger(s) on START.

                  Status:  Waiting for START.

                           0 frames acquired since starting.

                           0 frames available for GETDATA.

4. 预览视频流

为了是视频符合你的要求,你可以先进行预览,然后根据需要调节摄像设备的位置、光照、对焦或其他调整。 

复制内容到剪贴板代码:preview(vid)

这时将弹出视频预览窗口,里面是实时监控图像。 

复制内容到剪贴板代码:closepreview(vid)

命令可以关闭预览窗口。

5. 配置视频对象的属性

一、图像采集对象的类型

工具箱使用两种类型对象来表示与视频设备的连接:

Video input objects 视频输入对象

Video source objects 视频源对象

Video input objects是Matlab与视频设备在高层次的连接,这一层次抽象了各个设备的差异,提供相同的属性支撑。使用videoinput创建此类对象。

当创建一个视频输入对象时,工具箱自动创建一个或多个Video source objects视频源对象与之关联。每个视频源对象代表一个或多个作为一个单独整体看待的物理数据源的集合。源对象的数量依赖于视频设备和设定的视频格式。同一时刻,只有一个视频源被激活用来获取数据。

二、查看对象属性

使用get函数查看视频输入对象的属性,如 

复制内容到剪贴板代码:get(vid)

我的电脑输出结果如下:

  General Settings:

    DeviceID = 1

    DiskLogger = []

    DiskLoggerFrameCount = 0

    EventLog = [1x0 struct]

    FrameGrabInterval = 1

    FramesAcquired = 0

    FramesAvailable = 0

    FramesPerTrigger = 10

    Logging = off

    LoggingMode = memory

    >    NumberOfBands = 3

    Previewing = off

    ReturnedColorSpace = YCbCr

    ROIPosition = [0 0 0 480]

    Running = off

    Tag = 

    Timeout = 10

    Type = videoinput

    UserData = []

    VideoFormat = YUY2_0x480

    VideoResolution = [0 480]

  Callback Function Settings:

    ErrorFcn = @imaqcallback

    FramesAcquiredFcn = []

    FramesAcquiredFcnCount = 0

    StartFcn = []

    StopFcn = []

    TimerFcn = []

    TimerPeriod = 1

    TriggerFcn = []

  Trigger Settings:

    InitialTriggerTime = []

    TriggerCondition = none

    TriggerFrameDelay = 0

    TriggerRepeat = 0

    TriggersExecuted = 0

    TriggerSource = none

    TriggerType = immediate

  Acquisition Sources:

    SelectedSourceName = input1

    Source = [1x1 videosource]

查看当前输入对象的源对象信息: 

复制内容到剪贴板代码:get(getselectedsource(vid))

General Settings:

    Parent = [1x1 videoinput]

    Selected = on

    SourceName = input1

    Tag = 

    Type = videosource

  Device Specific Properties:

    BacklightCompensation = on

    Brightness = 0

    Contrast = 11

    Exposure = -6

    ExposureMode = auto

    FrameRate = 30.0000

    Gain = 34

    Gamma = 150

    Saturation = 4

    Sharpness = 3

    WhiteBalance = 6500

    WhiteBalanceMode = auto

三、设置对象属性

设置方式如下代码: 

复制内容到剪贴板代码:% 设置输入对象属性方式

set(vid,'TriggerRepeat',Inf);

vid.FrameGrabInterval = 5;

% 设置源对象属性方式

vid_src = getselectedsource(vid);

set(vid_src,'Tag','motion detection setup');

6. 获取图像数据

获取了视频输入对象后就可以获取数据了。这是任何图像采集应用的核心,他包含以下步骤:

启动视频输入对象——使用start函数启动对象,为采集图像做准备。在下面的例子中,start启动视频输入对象,对象在采集到所需数量的帧后停止。因为例中指定了连续采集,你必须使用stop函数来停止对象。

触发采集——根据指定的触发类型,视频输入对象执行触发采集。例如,如果你设定了即时触发器,对象将在初始化采集后立即自动进行采集。本例中,TriggerType设为了'immediate'(默认),并且TriggerRepeat设为无穷,因此,输入对象自动开始执行触发器,并进行数据帧连续采集。

获取数据到matlab工作区——工具箱在内存缓冲或磁盘文件或二者存储数据,这由对象的LoggingMode决定。要使用数据,必须先读入到matlab的工作空间中,使用getdata函数。 

复制内容到剪贴板代码:figure; % Ensure smooth display

set(gcf,'doublebuffer','on'); % 用于是图像平滑

start(vid) % 启动对像

while(vid.FramesAcquired<=100)

    data = getdata(vid,2);  % 获取两帧图像数据

    diff_im = imabsdiff(data(:,:,:,1),data(:,:,:,2)); % 两帧相减

    imshow(diff_im);

end

stop(vid)

运动检测例,结果图如下:

7. 清除工作 

复制内容到剪贴板代码:delete(vid)

clear

close(gcf)

获取图像数据步骤

Step 1: Install and configure your image acquisition device

Step 2: Retrieve information that uniquely identifies your image

acquisition device to the Image Acquisition Toolbox software

Step 3: Create a video input object

Step 4: Preview the video stream (Optional)

Step 5: Configure image acquisition object properties (Optional)

Step 6: Acquire image data

Step 7: Clean up

Step1:

Installing the frame grabber board in your computer.

• Installing any software drivers required by the device. These are supplied

by the device vendor.

• Connecting a camera to a connector on the frame grabber board.

• Verifying that the camera is working properly by running the application

software that came with the camera and viewing a live video stream.

Generic Windows image acquisition devices, such as webcams and digital

video camcorders, typically do not require the installation of a frame grabber

board. You connect these devices directly to your computer via a USB or

FireWire port.

After installing and configuring your image acquisition hardware, start

MATLAB on your computer by double-clicking the icon on your desktop. You

do not need to perform any special configuration of MATLAB to perform

image acquisition.

1

文档

MATLAB图像采集

进行的步骤如下:1.安装并配置图像采集设备2.获取在图像采集工具箱中能唯一标识此图像采集设备的信息,此信息在创建视频输入对象时要用到。这些信息包括:Adaptorname软件适配器名,DeviceID硬件设备的ID,Videoformat视频格式。imaqhwinfo用于检测适配器名,我的电脑安装了一个USB摄像头,所以检测到一个安装了的适配器'winvideo'。之后可以使用这个适配器名连接视频采集设备。复制内容到剪贴板代码:imaqhwinfoans=  InstalledAdaptors
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top