Specifying object properties to be detected

Hello everyone. I am currently working on a project to count the number of vehicles on a road from video using video processing by blob detection. The code I have can only detect cars. But I need to detect other types of vehicle as well. I want to how to specify a particular object's properties such as a van or truck to be detected in matlab. Please guide me. Thanks in advance. Regards

13 Commenti

Does that mean that what I am trying to do is not possible?
Define "vehicle".
Are roller skates a vehicle?
How about a Segway?
A hoverboard?
Would Iron Man's armor count as a vehicle? [You may scoff at the idea, but look at the first picture on this Wikipedia page. It may not be able to fly, but it's also not fictional. The caption card with it states "The Exoskeleton is a Personal Combat Vehicle ..."]
All i am trying to say is I want to detect a truck like the way i detected the cars.
I believe my answer below should work. What happened when you tried it? Share your code.
% Project
% Victor Vargas - U01251248
% vv16417n@pace.edu
%disp('Loading, it may take a moment')
%disp('-----Finish Solving Problem -----');
%pause;
close all;
clear all;
matlab.video.read.UseHardwareAcceleration('on')
fileName = 'video blob detection.mp4';
VideoInfo = get(VideoReader(fileName));
NumTrainingFrames = int64(VideoInfo.FrameRate*(VideoInfo.Duration/4));
NumGaussians = 3;
%STEP 1 - Import Video and Initialize Foreground Detector
%Initialize the Gaussian mixture model with the first 50 frames
foregroundDetector = vision.ForegroundDetector('NumGaussians', NumGaussians, 'NumTrainingFrames', NumTrainingFrames);
videoReader = vision.VideoFileReader(fileName);
for i = 1:NumTrainingFrames*NumGaussians
frame = step(videoReader); % read the next video frame
foreground = step(foregroundDetector, frame); % extract foreground
end
figure; imshow(frame); title('Video Frame');
figure; imshow(foreground); title('Foreground');
%STEP 2 - Detect Cars in an Initial Video Frame
%Morphological opening to remove the noise and to fill gaps in the detected objects
seSize = round(VideoInfo.Width*0.01);
se = strel('square',seSize); % 1% of video's with
filteredForeground = imopen(foreground, se);
figure; imshow(filteredForeground); title('Clean Foreground');
MinimumBlobArea = int64(VideoInfo.Width*0.10*VideoInfo.Height*0.10); % 8% of video's with
blobAnalysis = vision.BlobAnalysis('BoundingBoxOutputPort', true, 'AreaOutputPort', false, 'CentroidOutputPort', false, 'MinimumBlobArea', MinimumBlobArea);
bbox = step(blobAnalysis, filteredForeground);
%green boxes around detected cars
result = insertShape(frame, 'Rectangle', bbox, 'Color', 'green');
numCars = size(bbox, 1);
result = insertText(result, [10 10], numCars, 'BoxOpacity', 1, 'FontSize', 14);
figure; imshow(result); title('Detected Cars');
%Step 3 - Process the Rest of Video Frames
videoPlayer = vision.VideoPlayer('Name', 'Detected Cars');
se = strel('square', seSize); % morphological filter for noise removal
%Play video. Every call to the step method reads another frame.
while ~isDone(videoReader)
frame = step(videoReader); % read the next video frame
% Detect the foreground in the current video frame
foreground = step(foregroundDetector, frame);
% Use morphological opening to remove noise in the foreground
filteredForeground = imopen(foreground, se);
% Detect the connected components with the specified minimum area, and
% compute their bounding boxes
bbox = step(blobAnalysis, filteredForeground);
% Draw bounding boxes around the detected cars
result = insertShape(frame, 'Rectangle', bbox, 'Color', 'green');
% Display the number of cars found in the video frame
numCars = size(bbox, 1);
result = insertText(result, [10 10], numCars, 'BoxOpacity', 1,'FontSize', 14);
step(videoPlayer, result); % display the results
end
release(videoReader); % close the video file
here's the code.
I don't see anything there that would keep cars and throw out trucks. But attach 'video blob detection.mp4' and we'll see what happens.
"Does that mean that what I am trying to do is not possible?"
Exactly. And Image Analyst's solution does not achieve your stated task. Deep learning is unlikely to solve your stated task either.
For example, there are places where a Honda CRV with two wheel drive is legally defined as an automobile, but the same vehicle with four wheel drive is legally defined as a truck.
The difference between car and truck is a legal definition, and legal definitions vary from place to place.
Some of the vehicles that most people would not hesitate to classify as automobile are in fact legally trucks, with the manufacturer having widened the wheel base just slightly to meet truck definitions -- because it is common for "trucks" to have laxer fuel and pollution standards. Similarly, items such as (urban) mail trucks or (urban) windows/doors delivery/installation trucks common in the UK would potentially meet size standards to be legally considered automobiles in USA.
Some manufacturers made SUVs and vans as far as truck-like as they could while legally staying within the local limits on automobiles so that their highly urban customers would not have to get a truck driver's license and insurance would not charge the higher truck price.
Sure, some things are obvious, like an "18 wheeler" is unlikely to be legally an automobile anywhere in the world, but you need to understand that manufacturers deliberately pushed the legal boundaries on both sides, either just below or just above the boundaries, so you would need to know the location and a copy of all of the relevant regulations and a good tape measure and possibly specialized tools (for example, some jurisdiction might differentiate based upon maximum engine compression, but a given engine might be capable of exceeding the limit, or not, depending upon it's current firmware.)
Shahrin Islam
Shahrin Islam il 13 Set 2018
Modificato: Shahrin Islam il 13 Set 2018
Image analysist , it does not throw out the truck but through out the rickshaw, motorcycles, bicycle etc. Also I want seperate count of all types not a total count. That's why I think I need to provide specifications of all types of vehicles.
You need to go back to the first link I posted for you that demonstrates that you cannot differentiate between bicycle and motorcycle and car through image alone.
While I was researching I encountered a story about a fellow who built custom four wheel bicycles to drive around his handicapped relative. Municipal police gave him a ticket for operating an illegal vehicle because local law defined bicycle as having at most three wheels. The same laws defined motorcycle and car as being motor vehicle but he had no motor so he could not qualify for those. He was in a legal position of being unable to license the bicycle in any category, and thus was legally restricted to using the bicycles only on private property.
What he did was convince the local government to change their definition of bicycle, with considerable support from his neighbours who were proud of the way he was helping his handicapped relative.
Before his campaign, his device was legally nothing. Afterwards it was legally a bicycle. The exact same device and the exact same jurisdiction.
And therefore you cannot determine categories by image alone. Categories are legal more than they are technical.
See i understand what you are saying. I am using it for simple research purpose and only for the road of my country where tge vehicle types are clearly defined. The practical implication is not a case here. I hope you understand.
I am not aware of any country where the vehicle types are clearly defined. Especially not countries where rickshaws are common enough to be worth mentioning: in those countries there is typically a lot of personal innovation that blurs the lines badly.

Accedi per commentare.

 Risposta accettata

Image Analyst
Image Analyst il 12 Set 2018
You can use other code or relax the discrimination criteria. The usual way is to
  1. detect everything that moves (that's what it sounds like you want), and then to
  2. examine each moving blob to determine which are cars and which are not, then
  3. just keep the cars and throw out everything else.
It sounds like your code does all three steps because you said "The code I have can only detect cars." You need to modify it so that it does not do steps 2 and 3.

6 Commenti

Thank you so much for the information. But I want to count the number of vehicles distinctly like number of cars and number of tracks in a traffic. If I do what you say then I will only get the total count for things that move. I want to have seperate count. I hope you understand my problem. Looking forward for your help.
I would think you could judge it based on size. Trucks and cars will be large. Chickens, rabbits, and bicyclists will be small.
Otherwise you might want to look into deep learning where they have successfully classified all kinds of moving things in the image.
Okay. It could be a solution for that. Thank you for your time and consideration.
I would be grateful if you could please give me some links where I can learn deep learning to solve my problem.
It's all over the Mathworks's home page right now: https://www.mathworks.com/ You can't miss it.
thank you so much.. it's so kind of you.

Accedi per commentare.

Più risposte (1)

Shahrin Islam
Shahrin Islam il 16 Set 2018
image analyst i wanted to show you the video i am working on. But this site doesn't suport uploading a mp4 file. Can you have any other access? Thanks in advance.

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by