Detection only occurring on the left side
1 view (last 30 days)
Show older comments
Why is detectiong only occuring on the left side? Is it because it has not finished "processing" while going through the frames? How can it git me all the results?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1381044/image.png)
Here is the code:
subplot(1,3,1);
videoFrame1 = imread("videoShot.png");
imshow(videoFrame1);
vidReader = vision.VideoFileReader("shortZebraVideo.mp4");
vidReader.VideoOutputDataType = 'double';
diskElem = strel('diamond',1);
hBlobAn = vision.BlobAnalysis('MinimumBlobArea',1,... ...
'CentroidOutputPort', true);
vidPlayer = vision.VideoPlayer;
while ~isDone(vidReader)
vidFrame = step(vidReader)
% Convert RGB image to chosen color space
Ihsv = rgb2hsv(vidFrame);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.004;
channel1Max = 0.002;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.000;
channel2Max = 1.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.000;
channel3Max = 0.312;
% Create mask based on chosen histogram thresholds
sliderBW = ( (Ihsv(:,:,1) >= channel1Min) | (Ihsv(:,:,1) <= channel1Max) ) & ...
(Ihsv(:,:,2) >= channel2Min ) & (Ihsv(:,:,2) <= channel2Max) & ...
(Ihsv(:,:,3) >= channel3Min ) & (Ihsv(:,:,3) <= channel3Max);
Ibw = sliderBW;
Ivbwopen = imopen(Ibw, diskElem);
[areaOut, centroidOut, bboxout] = step(hBlobAn,Ivbwopen);
frameMarkers = insertMarker(vidFrame, centroidOut);
vidPlayer.step(frameMarkers);
end
0 Comments
Accepted Answer
Rohit
on 16 Jun 2023
Hi Jessy,
I understand that you are trying to detect blobs in a video by applying thresholding and morphological operations. However, it is difficult to determine the exact cause of the issue you are facing without data files.
Based on your description that detection is only occurring on the left side, it is possible that the threshold value you have chosen are not appropriate for the entire video sequence, or that the camera position or lighting conditions may be affecting the detection on one side. If the blob detection is sensitive to lighting conditions, you may need to consider pre-processing the images to improve the image quality or using adaptive thresholding methods to address this issue.
Regarding your question about not getting all the results, it is possible that the detection is only being performed on a subset of frames, rather than the entire video sequence. You should verify that the "isDone(vidReader)" condition is correctly set up to read all the frames in the video file.
One way to debug the code is to add print statements to observe the values of the different variables at each iteration of the loop. This will help you identify any issues with the thresholds or morphological operations that may be causing the left-side detection problem and verify that the detection is being performed on all frames in the video.
Hope this helps!
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!