├── .gitattributes ├── .gitignore ├── Flying_object.avi ├── README.md ├── Tracking the Object.m ├── bird_feature_vector.mat ├── cnn_for_uav_bird.m ├── finalclassifyusingKNN.m ├── finalclassifyusingRF.m ├── finalclassifyusingSVM.m └── uav_feature_vector.mat /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /Flying_object.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mukeshmodi/Computer-Vision-Assisted-UAV-detection-and-tracking/da7f5cdd3ed7d744728812b725df9aef782d107e/Flying_object.avi -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Computer-Vision-Assisted-UAV-detection-and-tracking 2 | This System track the Flaying object and Detect the object using various Machine learning algoritm like Support vector maching,KNN,Random forest and convoluted Neural network. 3 | 4 | details of the project 5 | 1. we have used Kalman filter to detect and track the Object 6 | 2.then the system crope the object image. 7 | 3.classify the oject using various Maching learning classifiers 8 | 4.wehave used Random forest,KNN,SVM,Nureal network. 9 | 5.project work with 87% accuracy using CNN. 10 | 11 | Thank You 12 | -------------------------------------------------------------------------------- /Tracking the Object.m: -------------------------------------------------------------------------------- 1 | obj=VideoReader('Flying_object.avi'); 2 | videoplayer=vision.VideoFileReader(); 3 | vidFrames=read(obj); 4 | numFrames=get(obj,'numberOfFrames');% 5 | [c r t n]=size(vidFrames); 6 | bw=zeros(c,r); 7 | kalmanFilter = []; isTrackInitialized = false; 8 | blobAnalyzer = vision.BlobAnalysis('AreaOutputPort',false,'MinimumBlobArea',20); 9 | 10 | for k=1:100 11 | im=vidFrames(:,:,:,k); 12 | 13 | k 14 | for i=1:c %loop to read all pixels 15 | for j=1:r 16 | 17 | if(im(i,j,1)>160 && im(i,j,2)>190 && im(i,j,3)>170) 18 | bw(i,j)=1; 19 | end 20 | end 21 | if k==2 22 | imwrite(im,'im.bmp'); 23 | end 24 | 25 | end 26 | bw=bwareaopen(bw,90);% removing noise 27 | cc=bwconncomp(bw); 28 | 29 | 30 | img=logical(bw); 31 | detectedLocation= step(blobAnalyzer,img); 32 | 33 | isObjectDetected = size(detectedLocation, 1) > 0; 34 | if ~isTrackInitialized 35 | if isObjectDetected 36 | kalmanFilter = configureKalmanFilter('ConstantAcceleration',detectedLocation(1,:), [1 1 1]*1e5, [25, 10, 10], 25); 37 | isTrackInitialized = true; 38 | end 39 | label = ''; circle = zeros(0,500); 40 | else 41 | if isObjectDetected 42 | predict(kalmanFilter); 43 | trackedLocation = correct(kalmanFilter, detectedLocation(1,:)); 44 | label = 'Corrected'; 45 | 46 | end 47 | circle = [trackedLocation, 5]; 48 | end 49 | 50 | 51 | mask = imopen(img, strel('rectangle', [3,3])); 52 | 53 | mask = imclose(mask, strel('rectangle', [15, 15])); 54 | mask = imfill(mask, 'holes'); 55 | 56 | [ centroids, bboxes] = step(blobAnalyzer,mask); 57 | 58 | 59 | 60 | 61 | bboxes 62 | 63 | 64 | frame = insertObjectAnnotation(im, 'rectangle', ... 65 | bboxes, 'UAV Detected'); 66 | imshow(frame); 67 | 68 | bw =zeros(c,r); 69 | pause(0.05); 70 | 71 | end 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /bird_feature_vector.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mukeshmodi/Computer-Vision-Assisted-UAV-detection-and-tracking/da7f5cdd3ed7d744728812b725df9aef782d107e/bird_feature_vector.mat -------------------------------------------------------------------------------- /cnn_for_uav_bird.m: -------------------------------------------------------------------------------- 1 | load uav_data; 2 | tr_x=[training_uav,train_birds]; 3 | te_x=[test_uav,test_birds]; 4 | 5 | 6 | tra_x=reshape(tr_x,[64,64,7000]); 7 | test_x=reshape(te_x,[64,64,1000]); 8 | 9 | tra_y = zeros(7000,2); 10 | test_y = zeros(1000,2); 11 | 12 | tra_y(1:3500,1)=1; 13 | tra_y(3501:end,2)=1; 14 | 15 | train_y=zeros(7000,2); 16 | 17 | test_y(1:500,1)=1; 18 | test_y(501:end,2)=1; 19 | 20 | v=randperm(7000); 21 | train_x=zeros(64,64,7000); 22 | for k=1:7000 23 | ind=v(k); 24 | train_x(:,:,k)=tra_x(:,:,ind); 25 | train_y(k,:)=tra_y(ind,:); 26 | end 27 | 28 | 29 | 30 | 31 | 32 | 33 | %% ex1 Train a 6c-2s-12c-2s Convolutional neural network 34 | %will run 1 epoch in about 200 second and get around 11% error. 35 | %With 100 epochs you'll get around 1.2% error 36 | 37 | rand('state',0) 38 | 39 | cnn.layers = { 40 | struct('type', 'i') %input layer 41 | struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer 42 | struct('type', 's', 'scale', 2) %sub sampling layer 43 | struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer 44 | struct('type', 's', 'scale', 2) %subsampling layer 45 | }; 46 | 47 | 48 | opts.alpha = 1; 49 | opts.batchsize = 100; 50 | opts.numepochs = 100; 51 | 52 | cnn = cnnsetup(cnn, train_x, train_y'); 53 | cnn = cnntrain(cnn, train_x, train_y', opts); 54 | 55 | [er, bad] = cnntest(cnn, test_x, test_y'); 56 | 57 | %plot mean squared error 58 | figure; plot(cnn.rL); 59 | assert(er<0.12, 'Too big error'); 60 | 61 | -------------------------------------------------------------------------------- /finalclassifyusingKNN.m: -------------------------------------------------------------------------------- 1 | clear all 2 | load('bird_feature_vector.mat'); 3 | load('uav_feature_vector.mat'); 4 | [r1,c1]=size(feature_vector); 5 | [r2,c2]=size(uav_feature_vector); 6 | training_data =[feature_vector(:,1:3500),uav_feature_vector(:,1:3500)]; 7 | test_data=[feature_vector(:,3501:end),uav_feature_vector(:,3501:end)]; 8 | training_label=[zeros(3500,1);ones(3500,1)]; 9 | test_label=[zeros(497,1);ones(500,1)]; 10 | 11 | out=knnclassify(test_data',training_data',training_label,3,'euclidean'); 12 | 13 | count=0; 14 | length(out); 15 | 16 | for k=1:997 17 | if(out(k)==test_label(k)) 18 | count=count+1; 19 | %disp('3'); 20 | end 21 | end 22 | acc=count/length(test_label); -------------------------------------------------------------------------------- /finalclassifyusingRF.m: -------------------------------------------------------------------------------- 1 | clear all 2 | load('bird_feature_vector.mat'); 3 | load('uav_feature_vector.mat'); 4 | [r1,c1]=size(feature_vector); 5 | [r2,c2]=size(uav_feature_vector); 6 | training_data =[feature_vector(:,1:3500),uav_feature_vector(:,1:3500)]; 7 | test_data=[feature_vector(:,3501:end),uav_feature_vector(:,3501:end)]; 8 | training_label=[zeros(3500,1);ones(3500,1)]; 9 | test_label=[zeros(497,1);ones(500,1)]; 10 | rf_smile=fitensemble(training_data',training_label,'Bag',3500,'tree','type','classification'); 11 | out=rf_smile.predict(test_data'); 12 | count=0; 13 | for k=1:497 14 | if(out(k)==test_label(k)) 15 | count=count+1; 16 | end 17 | end 18 | acc=count/length(test_label); -------------------------------------------------------------------------------- /finalclassifyusingSVM.m: -------------------------------------------------------------------------------- 1 | clear all 2 | clc 3 | load('bird_feature_vector.mat'); 4 | load('uav_feature_vector.mat'); 5 | training_data =[feature_vector(:,1:3500),uav_feature_vector(:,1:3500)]; 6 | test_data=[feature_vector(:,3501:end),uav_feature_vector(:,3501:end)]; 7 | training_label=[zeros(3500,1);ones(3500,1)]; 8 | test_label=[zeros(497,1);ones(500,1)]; 9 | test_data=test_data'; 10 | sv=svmtrain(training_data,training_label','kernel_function','rbf'); 11 | %svm_rbf=svmtrain(training_data,training_label,'kernel_function','rbf'); 12 | % svm_quad=svmtrain(total_feature,label_matrix,'kernel_function','quad'); 13 | out=[]; 14 | 15 | for i=1:497 16 | ou=svmclassify(sv,test_data(i,:)); 17 | out=[out,ou]; 18 | end 19 | count=1; 20 | for k=1:length(out) 21 | if(out(k)==test_label(k)) 22 | count=count+1; 23 | end 24 | end 25 | acc=count/length(test_label); -------------------------------------------------------------------------------- /uav_feature_vector.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mukeshmodi/Computer-Vision-Assisted-UAV-detection-and-tracking/da7f5cdd3ed7d744728812b725df9aef782d107e/uav_feature_vector.mat --------------------------------------------------------------------------------