Video processing of many bottles to mark the error in the cap and the level of the liquid
1 次查看(过去 30 天)
显示 更早的评论
In the video appears many bottle like in a industry and I want to mark the error like in a rectangle to detect if the cap or the level of liquid is not the same but in my programm doesnt properly detect the object to track to mark the error and also how do I make the video run smooth since I run it but it goes too slow.
So what change I have to do?
link of the video:https://files.fm/u/qczqqcf5e
vid=VideoReader('OBDA.mp4'); %To read the video into the matlab.
nframes = get(vid,'NumFrames');
%%
for i=1:nframes
frame= read(vid,i); %reading the frame no. i
img=rgb2gray(frame); %converting the frame from"RGB"to"Gray Scale"
img=medfilt2(img); %Apllying Median Filter.
img=im2bw(img); %Converting the frame into Binary Image.
img=imcomplement(img); %Complementing the frame.
img=imfill(img,'holes'); %fills the holes in the binary image BW.
%Obtaining Some Properties about the frame(no. of objects detected,
%Centroid.
bw=bwlabel(img);
props=regionprops(bw,'BoundingBox','Centroid');
imshow(frame) %Displaying the frame
hold on %Fixing the frame
%This is a loop to bound the blue objects in a rectangular box.
for object = 1:length(props)
bb = props(object).BoundingBox;
bc = props(object).Centroid;
rectangle('Position',bb,'EdgeColor','b','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
0 个评论
回答(1 个)
Rahul
2025-6-16
I understand that you wish to make the video run smooth while annotating the bounding boxes of the detected bottle cap and liquid levels shown in the video.
I noticed that in the code shared, you would expect the video to be displayed as the loop is running and as 'imshow' function is being called. However, you can use the 'drawnow' function below the 'imshow' to enable a live preview of the objvct detection as the loop is running.
Additionally, instead of just using 'bwlabel' and 'regionprops', consider using other image processing functions like 'imbinarize', 'bwareaopen' etc. for a more robust tracking.
I would also suggest referring this this documentation:
The following MathWorks documentations can be referred to know more"
Thanks.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!