我有以下代码:
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);
vid = VideoReader('C:\VHDL Project\VHDL Course\Logtel\Image processing\Sacramento Kings vs Golden State Warriors.mp4')
% 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<=200)
% 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 :) ')
我尝试读取MP4文件,运行它并找到红色对象。 不幸的是,该工具会弹出以下错误:
使用VideoReader / set
时出错名称&#39; FramesPerTrigger&#39;不是类&#39; VideoReader&#39;的实例的可访问属性。
RedObjectTracking错误(第11行)
设置(vid,&#39; FramesPerTrigger&#39;,Inf);
如果有人可以告诉我我的错误
,我会很高兴感谢您的帮助。
答案 0 :(得分:0)
如果您查看the documentation for VideoReader,您会看到(如您的错误所示)FramesPerTrigger
未列为有效财产。基于FramesPerTrigger
FramesPerTrigger
,它是一个仅用于图像采集工具箱中的视频设备的属性(类似于之前在线上注释的more of the documentation。所以当您仅使用通过VideoReader
输入的视频文件时,您尝试设置VideoReader
值的行不应该存在。
这也是有道理的,因为您的图像采集系统将具有触发器,并且MATLAB知道每个触发器要抓取多少帧是很重要的。另一方面,视频文件(VideoReader
打算处理)没有触发器,并且文件本身可以随时获得帧信息。
根据您的代码,您认为只是将videoinput
替换为function add_copyright_text() {
if (is_single()) { ?>
<script type='text/javascript'>
function addLink() {
if (
window.getSelection().containsNode(
document.getElementsByClassName('post')[0], true)) {
var body_element = document.getElementsByTagName('body')[0];
var selection;
selection = window.getSelection();
var oldselection = selection;
var pagelink = "<br /><br /> Read full forex article here: <?php the_title(); ?> <a href='<?php echo get_permalink(get_the_ID()); ?>'><?php echo get_permalink(get_the_ID()); ?></a>"; //Change this if you like
var copy_text = selection + pagelink;
var new_div = document.createElement('div');
new_div.style.left='-99999px';
new_div.style.position='absolute';
body_element.appendChild(new_div );
new_div.innerHTML = copy_text ;
selection.selectAllChildren(new_div );
window.setTimeout(function() {
body_element.removeChild(new_div );
},0);
}
}
document.oncopy = addLink;
</script>
<?php
}
}
add_action( 'wp_head', 'add_copyright_text');
,但这不起作用,因此您的代码中有很多点会导致错误。