Perform Instance Segmentation Using Mask R-CNN - matlab

i just following 'Perform Instance Segmentation Using Mask R-CNN' example
URL : "https://kr.mathworks.com/help/vision/ug/example-InstanceSegmentationUsingMaskRCNNDeepLearningExample.html"
I have download the file(instances_train2014.json, cocoapi-master, unpackAnnotations.m(was in helper file) )
but i don't know how to compling gason.
enter image description here
so i get a error, matlab can not read coco annotation file
enter image description here
i just copy the example code and change the file path
matlab 2022b
%download traindata
imageFolder = fullfile(dataFolder,"images");
captionsFolder = fullfile(dataFolder,"annotations");
if ~exist(imageFolder,"dir")
mkdir(imageFolder)
mkdir(captionsFolder)
end
annotationFile = fullfile(captionsFolder,"instances_train2014.json");
str = fileread(annotationFile);
%read and process training data
trainClassNames = ["person","car"];
numClasses = length(trainClassNames);
imageSizeTrain = [800 800 3];
cocoAPIDir = fullfile(dataFolder,"cocoapi-master","MatlabAPI");
addpath(cocoAPIDir);
unpackAnnotationDir = fullfile(dataFolder,"annotations_unpacked","matFiles");
if ~exist(unpackAnnotationDir,'dir')
mkdir(unpackAnnotationDir)
end
helper.unpackAnnotations(trainClassNames,annotationFile,imageFolder,unpackAnnotationDir);
%create data
i want to train coco dataset but i don't know c++ compling
what is the gason complie..?
how can i get complied annodation data with gason..?

Related

How to save detected objects using YOLO as images in separate folder in matlab?

I have trained yoloV2 detector in matlab. Since I'm still new to matlab I need help with writing the code for saving the output image ("pic" variable in code) in the separate folder every time object is detected. Code for detecting objects over webcam is shown below.
while true
img = snapshot(cam);
[bboxes,scores,labels] = detect(YoloV2detector,img,'Threshold',0.3,'SelectStrongest',false);
[selectedBboxes,selectedScores,selectedLabels,index] = selectStrongestBboxMulticlass(bboxes,scores,labels,...
'RatioType','Min','OverlapThreshold',0.3);
annotations = string(selectedLabels) + ": " + string(selectedScores);
pic = insertObjectAnnotation(img,'rectangle',selectedBboxes,cellstr(annotations),'Color','red',...
'LineWidth',2,'TextBoxOpacity',0.9,'FontSize',16);
imshow(pic);
end

Loading saved cv.DescriptorMatcher in MATLAB (mexopencv)

I have recently started working in mexopencv and I am new to it. However, I have made a database of keypoints and features of images for ORB and SURF and saved it in a .mat file along with the trained matchers.
Matcher used:
FLANN based matcher (for SURF points)
BruteForce - Hamming (for ORB points)
It works fine if I train the data in the same script and try to find the image from the databse. However, when I try to find the image from the database in another script by loading the keypoints data and the matcher, it fails.
The code for making database is:
%% OPTIONS
SURF_Threshold = 40000;
%% SETUP
SURF = cv.SURF('HessianThreshold', SURF_Threshold);
ORB = cv.ORB;
opts = {'KDTree', 'Trees',5}; %Dictionary required for FLANN
matcherFLANN = cv.DescriptorMatcher('FlannBasedMatcher', 'Index',opts);
matcherBF = cv.DescriptorMatcher('BruteForce-Hamming');
foldername = uigetdir;
oldFolder = cd(foldername);
files = [dir('*.jpg');dir('*.png')]; %Look for jpg files in the directory.
N = size(files,1); %numel the files
%Create empty training sets
trainDataORB = struct('name', cell(N,1), 'pts',cell(N,1), 'feat',cell(N,1));
trainDataSURF = struct('name', cell(N,1), 'pts',cell(N,1), 'feat',cell(N,1));
%% TRAINING
for i=1:N
% read image
img = imread((files(i).name));
%Extracting keypoints and descriptors (features) for both
[trainDataSURF(i).pts, trainDataSURF(i).feat] = SURF.detectAndCompute(img);
[trainDataORB(i).pts, trainDataORB(i).feat] = SURF.detectAndCompute(img);
trainDataSURF(i).name = files(i).name;
trainDataORB(i).name = files(i).name;
% add to training set to match against for each of descriptor
matcherFLANN.add(trainDataSURF(i).feat);
matcherBF.add(trainDataORB(i).feat);
end
% build index
matcherFLANN.train();
matcherBF.train();
%% SAVING DATA
%Navigate back to old folder
cd(oldFolder);
save('training_data.mat', 'matcherFLANN', 'matcherBF', 'trainDataSURF','trainDataORB');
The matcher objects are then loaded with in another scrip (with cleared workspace):
load('training_data.mat');
Which returns the error:
Error using DescriptorMatcher_ Object not found id=109
Error in cv.DescriptorMatcher/match (line 461)
matches = DescriptorMatcher_(this.id, 'match', queryDescriptors, varargin{:});
Error in detection_Test (line 27)
matches = matcherFLANN.match(feat);
Any help would be gladly welcomed.

How to provide input to BagOfFeatures() function in MATLAB in the form of imageSet or imageDataStore?

I want to use bagOfFeatures() function of MATLAB. But it requires input in the form of imageSet or imageDataStore. The code I want to run is given below:
Dataset = 'D:\dsktop\kinect_leap_dataset\acquisitions';
thresh1 = 0;
thresh2 = 20;
k = dir(fullfile(Dataset,'\P*\G*\*_depth.png'));
kf = {k(~[k.isdir]).folder};
kn = {k(~[k.isdir]).name};
for j=1:length(k)
% Applying thresholding to the original image
full_name = horzcat(kf{j},filesep,kn{j});
image = imread(full_name);
image_bin1 = (image < thresh2);
image_bin2 = (thresh1 < image);
image_bin = abs(image_bin2- image_bin1);
sequence{i} = image_bin;
end
% Bag of Features
bag = bagOfFeatures(sequence);
But the "sequence" is a cell class and so bagOfFeatures() is giving me errors. So I tried this:
Dataset = 'D:\dsktop\kinect_leap_dataset\acquisitions';
imgFolder = fullfile(Dataset);
imgSets = imageSet(imgFolder, 'recursive');
imgSets.Description
But now the problem is how to do the processing (thresholding) on images saved in imgSets. Also, after processing how to save all the "image_bin" images in imageSet class so that I can give them as input to the BagOfFeatures() function.
I solved this problem myself. To give input as an imageSet or imageStrore to BagOfFeatures(), we have to store all the "image_bin" images in a folder in PC.
For that, we have to create that folder in the desired location as
mkdir D:\.............\cropped
Then, we have to save the "image_bin" in that folder in a loop as
file_name = sprintf('D:/............/cropped/image_bin_%d.png',j);
imwrite(image_bin, file_name);
Then, the data from above folder is read in MATLAB memory as
imds = imageDatastore('D:/.............../cropped', 'Labels', label);
% label is an array of labels made by the user
[trainingSet, validationSet] = splitEachLabel(imds, 0.3, 'randomize');
% Bag of Features
bag = bagOfFeatures(trainingSet);
And It's done.

How to reduce running time of matlab code used for face recognition(PCA based)? [duplicate]

I am having 2900 images in this path G:\newdatabase\ It is taking too much time to read images.For dot product also it is taking too much time.
Questions:
1.Is there any alternative for imread command which increases performance?
2.Is there any alternative for dot command which increases performance?
Source code i tried:
srcFiles = dir('G:\newdatabase\*.jpg'); % the folder in which ur images exists
for b = 1 : length(srcFiles)
filename = strcat('G:\newdatabase\',srcFiles(b).name);
Imgdata = imread(filename);
Source code i tried:
for i = 1:aa
pare = dot(NormImage,u(:,i));
p = [p; pare];
end

pattern recognition using neural network in matlab

I am doing a project in character recognition of a local language. I created the dataset. But I am not sure how to feed it using neural network?
In this stage, I can only select one image as input rather than whole set of same character. How to proceed?
Pls help
As far as I know these neurons don't understand 2d input, so you need to make a 1d array from image:
image1flat = image1(:);
image2flat = image2(:);
Then put them into a 2d trainning set array (note that "Samples are:" option on your picture)
%samples are columns now
trainningSet = [image1flat image2flat];
Automated code:
%change this to folder where the files are
cd('/path/to/files');
%change this to your file format
files = dir('*.png');
result = [];
for i = 1:length(files)
A{i} = imread(files(i).name);
Aflat{i} = A{i}(:);
result = [result Aflat{i}];
end
%put the result into nprtool