【问题标题】:how to transfer matlab code to simulink matlab function如何将matlab代码传输到simulink matlab函数
【发布时间】:2014-08-11 16:34:16
【问题描述】:

我期待获得支持来解决我关于将 matlab 代码传输到 simulink matlab 函数的问题,我需要尽快获得帮助。

matlab 代码是:

%a = imaqhwinfo;
%[camera_name, camera_id, format] = getCameraInfo(a);


% Capture the video frames using the videoinput function
% You have to replace the resolution & your installed adaptor name.
vid = videoinput('winvideo',1);

% Set the properties of the video object
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb')
vid.FrameGrabInterval = 5;

%start the video aquisition here
start(vid)

% Set a loop that stop after 100 frames of aquisition
while(vid.FramesAcquired<=100)

    % Get the snapshot of the current frame
    data = getsnapshot(vid);

    % Now to track red objects in real time
    % we have to subtract the red component 
    % from the grayscale image to extract the red components in the image.
    diff_im = imsubtract(data(:,:,1), rgb2gray(data));
    %Use a median filter to filter out noise
    diff_im = medfilt2(diff_im, [3 3]);
    % Convert the resulting grayscale image into a binary image.
    diff_im = im2bw(diff_im,0.18);

    % Remove all those pixels less than 300px
    diff_im = bwareaopen(diff_im,300);

    % Label all the connected components in the image.
    bw = bwlabel(diff_im, 8);

    % Here we do the image blob analysis.
    % We get a set of properties for each labeled region.
    stats = regionprops(bw, 'BoundingBox', 'Centroid');

    % Display the image
    imshow(data)

    hold on

    %This is a loop to bound the red objects in a rectangular box.
    for object = 1:length(stats)
        bb = stats(object).BoundingBox;
        bc = stats(object).Centroid;
        rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
        plot(bc(1),bc(2), '-m+')
        a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), '    Y: ', num2str(round(bc(2)))));
        set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow');
    end

    hold off
end
% Both the loops end here.

% Stop the video aquisition.
stop(vid);

% Flush all the image data stored in the memory buffer.
flushdata(vid);

% Clear all variables
clear all
sprintf('%s','That was all about Image tracking, Guess that was pretty easy :) ')

当我将它传输到 simulink 时,出现以下错误:

“videoinput”类不支持代码生成。

函数 'videoinput' (#24.234.244),第 8 行,第 7 列: “视频输入” 启动诊断报告。

等待您的即时回复...

问候

【问题讨论】:

  • 错误很明显。 videoinput 类不支持代码生成。这意味着当您想尝试创建 Simulink 模块版本时,不能在 Simulink 中使用 videoinput。我的建议可能是从您的网络摄像头预先录制视频,然后使用 VideoReader 类首先读取帧。我相信VideoReader 支持代码生成。祝你好运!

标签: matlab video image-processing simulink


【解决方案1】:

正如 cmets 中已经提到的,您不能在 Simulink 中使用 videoinput 函数,因为它不支持代码生成。相反,请使用 From Video Device 块。您应该能够将实际的图像处理算法放入一个 MATLAB Function 块中,并进行一些小的调整。

【讨论】:

  • 不错!不知道这个。来自我的 +1。
猜你喜欢
  • 2013-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-28
  • 2017-07-06
  • 2014-01-02
  • 2022-09-29
  • 2022-11-04
相关资源
最近更新 更多