Face detection using matlab - matlab

tried this code
A=imread('1.jpg');
FaceDetector=vision.CascadeObjectDetector();
BBOX=step(FaceDetector,A);
B=insertObjectAnnotation(A,'rectangle',BBOX,'Face');
imshow(B),title('Detected Faces');
n=size(BBOX,1);
str_n=num2str(n);
str=strcat('number of detected faces are ',str_n);
disp(str);
this error show with me
Undefined function 'insertObjectAnnotation' for input arguments of type 'uint8'.
Error in Detected_faces (line 9)
B=insertObjectAnnotation(A,'rectangle',BBOX,'Face');

You just need to change the type of your image.
A type must be uint8 and the "insertObjectAnnotation" function only takes different inputs.
Please try:
A=imread('1.jpg');
FaceDetector=vision.CascadeObjectDetector();
BBOX=step(FaceDetector,A);
B=insertObjectAnnotation(rgb2gray(A),'rectangle',BBOX,'Face');
Actually, I tried this:
I = imread('coins.png');
FaceDetector=vision.CascadeObjectDetector();
BBOX=step(FaceDetector,I);
B=insertObjectAnnotation(I,'rectangle',BBOX,'Face');
And I is uint8, and it worked.
Using your dataset, it worked just fine. See Image output.

Related

Adaptive thresholding Matlab-Opencv

I wanted to apply cv.adaptiveThreshold (opencv) through matlab on 8-bit single-channel uint8 image but I am always getting error. I have tried following code from this website: https://kyamagu.github.io/mexopencv/matlab/adaptiveThreshold.html
th = cv.adaptiveThreshold(img,255,'Method',mean,'Type',binary,3,2);
and it gives me the error of Not enough input argument.
when I am running like this:
th = cv.adaptiveThreshold(img);
it is working properly but this is not what I want. I don't want to apply default methods and criteria.
Thanks for the help.
Read the documentation. You are not following the function argument list
cv.adaptiveThreshold(img,'MaxValue',255,'Method','Mean','Type','Binary','BlockSize',3,'C',2);
should work

How do I use imhistmatch in Matlab?

I'm trying to implement with the matlab function imhistmatch.
So I use following commends.
A= imread('example1.jpg')
B= imread('example2.jpg')
C= imhistmatch(A,B)
But there is problem like this.
?? Undefined functionor method 'imhistmatch' for input arguments of type 'uint8'
So What am I suppose to do for solve?
I am not sure about your question. Are you trying to implement imhistmatch?
Then probably your function is in the wrong folder or you have a typo in the functions name.
use
addpath('Pathto/imhistmatch')
to ensure that matlab can find your implemented function.
But maybe you want to use the function imhistmatch provided by the image processing toolbox. Then, I guess you don't have the image processing toolbox.
Try
ver
and check the output. You should find these lines:
MATLAB Version X.X (XXXXX)
Image Processing Toolbox Version X.X (XXXXX)
If not, then you may want to buy the image processing toolbox, get a evaluation version or maybe try octave.
On my computer the following works:
imhistmatch(ones(10),ones(10))
imhistmatch(ones(10,'uint8'),ones(10,'uint8'))
but when I type
imhistmatch(ones(10,'int8'),ones(10,'int8'))
I get an error:
Error using imhistmatch
Expected input number 1, A, to be one of these types:
uint8, uint16, double, int16, single
Instead its type was int8.
...
So, if it would be a type problem you would see another error.
Your error is the result of not having the proper function imhistmatch.

Error in MATLAB.Undefined function 'det' for input arguments of type 'embedded.fi'

I have already seen the link Error using fzero in Matlab: Undefined function or method 'det' for input arguments of type 'function_handle'
But I am unable to solye my problem with this link.I am working with fi object in MATLAB. I have one matrix T_1 (2 cross 2) which is conevrted into the fi(T_1,1,32,26,fimath), i.e 32 signed binary number and 26 is the positon of binary point. Now when I try to excute the follwing code
T = mat_G/(mat_sqrt_D)
T_1=fi(T./mat_E,1,32,26,fimath);
multiplier=1/(2*sqrt(det(var_oldS))*abs(det(T_1)));
follwing error appears
Undefined function 'det' for input arguments of type 'embedded.fi'.
So can anyone tell me how can i fix it.
P.S variable var_oldS, mat_G,mat_E, mat_qrt_D has the same fi object properties i.e fi(variable_name,1,32,26,fimath)
If you check the documentation for det, it says that the input must be single or double. Fixed point is probably not supported. As your matrix is of fixed size 4, it's simple to replace the function:
det2=#(M)M(1)*M(4)-M(2)*M(3)
Then use det2 instead of det.

MSER features detection not working in matlab

Why is that whenever I try to use detectSURFFeatures(img) with a binary image in matlab gives me proper points but whenever I use detectMSERFeatures(img) with the same binary image gives me error instead of pointing some valid regions?
ERROR:
Error using detectMSERFeatures
Expected input number 1, I, to be one of these types:
uint8, int16, uint16, single, double
Instead its type was logical.
Error in detectMSERFeatures>parseInputs (line 75)
validateattributes(I,{'uint8', 'int16', 'uint16', ...
Error in detectMSERFeatures (line 64)
[Iu8, params] = parseInputs(I,varargin{:});
Try this:
make image 2 double first by using img=im2double(img);
then feed it to MSER
detectMSERFeatures(img)
detectMSERFeatures does not accept logical inputs, as stated in the documentation and in the error you are receiving. detectSURFFeatures does. I don't know if there's a specific reason why, as I'm not familiar with the limitations of the different algorithms.
You could simply convert your binary image to one of the types listed, and run MSER on it:
detectMSERFeatures(double(img));

How to use dct2() in matlab?

I am trying to pass a matrix to dct2 function but it is showing error. I am using matlab version R2012a. I have a matrix B which just used as argument like below
B = dct2(A);
disp(B);
Error is showing like this
Undefined function 'dct2' for input arguments of type 'uint8'.
Error in image_dct (line 24)
B = dct2(A);
You have to have the image processing toolkit in order to use that. Assuming you have that, then it should be just as simple as you listed.