raspberry pi live video capturing for car detection
    조회 수: 3 (최근 30일)
  
       이전 댓글 표시
    
clear classes;
net = squeezenet(); 
net.Layers 
plot(net) 
mypi = raspi;
mycam = cameraboard(mypi,'Resolution','1280x720');
for ii = 1:500
img = snapshot(mycam);
    imagesc(img);                                  
    drawnow
end
mycam.Rotation = 180;
 v = VideoReader('myvideo.mpeg');
 frames = readframe(v,[01 Inf]);
 stop(mycam);
 stop(v);
getFile(mypi,'myvideo.mpeg','C:\Users\cyberlab\Documents\MATLAB');
 %% Create Video Player
videoPlayer = vision.VideoPlayer;
fgPlayer = vision.VideoPlayer;
%% Create Foreground Detector  (Background Subtraction)
foregroundDetector = vision.ForegroundDetector('NumGaussians', 3,'NumTrainingFrames', 50);
%% Run on first 75 frames to learn background
for i = 1:75
    videoFrame = step(videoReader);
    foreground = step(foregroundDetector,videoFrame);
end
 pictures = dir('C:\Users\cyberlab\Documents\MATLAB\automobile/*.jpg');
numFiles = length(pictures); 
for i_pics = 1:numFiles
bild = imread(pictures(i_pics).name);
image{i_pics} = double(bild)/255;
end
%% Perform morphology to clean up foreground 
cleanForeground = imopen(foreground, strel('Disk',1));
%% Create blob analysis object 
%Blob analysis object further filters the detected foreground by rejecting blobs which contain fewer
% than 150 pixels.
blobAnalysis = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
    'AreaOutputPort', false, 'CentroidOutputPort', false, ...
    'MinimumBlobArea', 500);
%% Loop through video
while  ~isDone(videoReader)
    %Get the next frame
    videoFrame = step(videoReader);
    %Detect foreground pixels
    foreground = step(foregroundDetector,videoFrame);
    % Perform morphological filtering
    cleanForeground = imopen(foreground, strel('Disk',1));
    % Detect the connected components with the specified minimum area, and
    % compute their bounding boxes
    bbox = step(blobAnalysis, cleanForeground);
    % Draw bounding boxes around the detected cars
    result = insertShape(videoFrame, 'Rectangle', bbox, 'Color', 'red');
    % Display the number of cars found in the video frame
    numCars = size(bbox, 1);
    text = sprintf('Detected Vehicles = %d',numCars);
    result = insertText(result, [320 320], numCars, 'BoxOpacity', 1, ...
        'FontSize', 14);
    % Display output 
     step(videoPlayer, result);
     disp('numCars');
     disp(numCars)
   % find total number of cars in whole frame
   for ii=1:length(videoFrame)%numof frames
   totalcount(ii)=videoFrame(ii);
   end
   totcars=sum(totalcount)/5;
end
disp('Total number of cars in entire video')
disp(round(totcars));
%% release video reader and writer
release(videoPlayer);
release(videoReader);
release(fgPlayer);
delete(videoPlayer); % delete will cause the viewer to close
delete(fgPlayer);

댓글 수: 1
  Bhaskar Vundurthy
    
 2020년 1월 8일
				While 'myvideo.mpeg' is being called (line 13), there does not exist a file with such a name in the current MATLAB path. 
Modify the filename to retreive appropriate file or consider calling the video file 'vid.mp4' that is present in the current MATLAB path. 
It looks like the question is duplicate to https://in.mathworks.com/matlabcentral/answers/481821-live-object-detection-using-raspberry-pi-cam
답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 MATLAB Support Package for Raspberry Pi Hardware에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

