필터 지우기
필터 지우기

Counting and measuring size of particles flowing in a video

조회 수: 29 (최근 30일)
Kelechi Ndukwe-Ajala
Kelechi Ndukwe-Ajala 2023년 10월 20일
답변: Image Analyst 2023년 12월 5일
I have mp4 videos of square/rectangular particles moving in and out of the video space and would like to count and measure their size through out the duration of the video. Please could you suggest how to do this?
  댓글 수: 1
Kelechi Ndukwe-Ajala
Kelechi Ndukwe-Ajala 2023년 12월 4일
편집: Kelechi Ndukwe-Ajala 2023년 12월 4일
I have attached an example video and my code thus far that is able to detect objects in the video but not particularly only crystals in focus.
I have a few aims to achieve:
1) How to detect only crystals within plane of focus?
2) How to differentiate between touching crystals during detection?
3) How to average bounding box data across multiple frames for a detected crystal?
4) How to combine bounding box data from each individual frame into one matrix as an output? Final output needed is the total crystal count and their individual sizes
clear;
clc;
filename = 'Trimmed video.mp4'; % To read the video into MATLAB
implay(filename); % Display the video
videoSource = VideoReader(filename);
% create a detector object
detector = vision.ForegroundDetector('NumTrainingFrames',1000);
% Perform blob analysis
blob = vision.BlobAnalysis('AreaOutputPort',false,'CentroidOutputPort',false,'BoundingBoxOutputPort',true,'MinimumBlobArea',200);
% Insert a border
shapeInserter = vision.ShapeInserter('BorderColor','White');
% Play results. Draw bounding boxes around moving crystals
videoPlayer = vision.VideoPlayer();
framecount=1;
while hasFrame(videoSource)
frame = readFrame(videoSource);
fgMask = detector(frame);
bbox = blob(fgMask);
out = shapeInserter(frame,bbox);
videoPlayer(out);
framecount=framecount+1;
end
release(videoPlayer);

댓글을 달려면 로그인하십시오.

답변 (2개)

Pratik
Pratik 2023년 11월 2일
Hi Kelechi,
In my understanding, you want to count and measure the size of square/rectangle particles in a video. To do the same you will have to first read the frames of the video and then process each frame using image processing technique to identify the squares/rectangles and measure their size.
  • To read the frame, you can use “VideoReader” function to get a videoreader object and then can use “readFrame” to read each frame of the video. Refer to the code snippet below for an example
v = VideoReader("video_path"); % path of the video
while hasFrame(v)
frame = readFrame(v);
end
  • Now for each frame you need to use the function “regionprops” which can measure properties such as area, centroid and bounding box, for each object (connected component) in the frame.
  • To count the number of squares/rectangles total number of centroids can be counted and to measure the size “BoundingBox” property can be used. It returns position and size of the smallest box containing the region, returned as a 1-by-(2*Q) vector, where Q is the image dimensionality.
Please refer to the following “VideoReader” documentation for more information about reading frames from video: https://in.mathworks.com/help/matlab/ref/videoreader.html
Please refer to the following “regionprops” documentation for more information about measuring properties of image regions: https://in.mathworks.com/help/images/ref/regionprops.html
Hope this helps!
  댓글 수: 1
Kelechi Ndukwe-Ajala
Kelechi Ndukwe-Ajala 2023년 12월 4일
편집: Kelechi Ndukwe-Ajala 2023년 12월 4일
Hello Pratik,
Your suggestions greatly helped to get me started. Please see my updated questions in the post

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2023년 12월 5일
The Computer Vision Toolbox has motion tracking capabilities.

카테고리

Help CenterFile Exchange에서 Tracking and Motion Estimation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by