I'm trying count faces in the picture with jviolajones library. I want to do this in pure Java with no extra dependencies so OpenCV is not an option. My code is like:
detector.getFaces("filePath", 1.2f,1.1f,.05f, 2,true);
I've tried haarcascade_frontalface_alt and haarcascade_frontalface_default from OpenCV. But results are bad about 5 pictures recognized good for 30 tested.
I've tried adjust parameters but it didn't help. Any suggestion for better results, or maybe another library. I was wondering, maybe I have to prepare pictures before detecting faces?
This works:
detector.getFaces("filePath", 1.2f,1.1f,.05f, 2,true);
But I had to scaled my photos to 640x480 and transform them to gray, this works with haarcascade_frontalface_default.xml classifier from OpenCV.
Related
I am new to computer vision but I am trying to code an android app which does the following:
Get the live camera preview and try to detect one logo in that (i have the logo in my resources). In real-time. Draw a rect around the logo if found. If there is no match, dont draw the rectangle.
I already tried a couple of things including template-matching and feature detection using ORB.
Why that didnt work:
Template-matching:
Issues with scaling and rotation. I tried a multi scale variant of it but a) the performance was really bad and b) the rectangle was of course always shown trying to search for the image. There was no way to actually confirm in the code if the logo was found or not.
ORB feature detection:
Also pretty slow (5-6 fps) but it worked ok-ish. The other problem was that also i never could be sure if the logo was in the picture or not. ORB found random matches even if the logo was not in the picture.
Like I said, I am very new to this. I would appreciate the help on what would be the best way to achieve:
Confirm if a picture A (around 200x200 pixels) is in ROI of camera picture (around 600x600 pixels).
This shouldnt take longer than 50ms per frame. I dont know if thats even possible though. So if a correct way to do this would take a bit longer than that, I would just do the work in a seperate thread and only analyze like every fifth camera frame or so.
Would appreciate any hints or code examples on how to achieve that. Thank you!
With logo detection, I would highly recommend using OpenCV HaarClassifier. It is easy to generate training samples from a collection of images of the logo, or one logo image with many distortions.
If you can use a few rules like the minimum and maximum size of the logo to be detected, and possible regions on the image where it can appear, you can run the detector at a speed better than you mention with ORB.
This is my image:
I want to remove the the noise(little black unrelated pixels) from my image.
I tried gaussian, cvtColor and adaptiveThreshold but none did the job.
Ideas? If you have a code in java that will help.
Noise removal could be tricky depending on the application. for your image a simple morphology operation like closing/Opening could solve the problem. Opening operation helps to remove the noises in your image. Closing will help to fill the existing holes.
Since OpenCV c++ APIs are like Java you can use the following:
cv::Mat Kernel = cv::Mat(cv::Size(Maximum_Width_of_Noise,Maximum_Height_of_noise),CV_8UC1,cv::Scalar(255));
cv::morphologyEx(Input_Image,temp,cv::MORPH_OPEN,Kernel);
cv::morphologyEx(temp,Output_Image,cv::MORPH_CLOSE,Kernel);
There are many methods but there's a trade off between accuracy/speed here.
The result of above operation is:
I installed the OpenCV 2.4.8 Java API to play with the face detection example that is given in the tutorial.
In the example, lbpcascade_frontalface.xml -which is a CascadeClassifier- works OK in detecting the female face image (lena.png) that they provide. However, when I tried it on this random image from the web, the classifier produced the following image, missing 4 obvious(!) faces:
I am quite disappointed because I expected this (with the clear contrasts) to be a very easy image for detecting faces.
1) Coding in Java, is it possible to improve this classifier to detect all faces in this picture? Or do I need C++ for this?
2) I looked at OpenCV's CascadeClassification web page and saw taht it is possible to train your own classifier. But the instructions are in C++. Has anyone done this using Java or is it only doable in C++?
The training is not related to any programming language.
http://docs.opencv.org/doc/user_guide/ug_traincascade.html
You need only to use two already written programs included in the opencv library: createsamples and traincascade. You can use Haar and LBP features too, but the Haar features are slightly better for face detection. (And by the way: don't use haartraining).
I have saved your image and this c++ code finds the missing 4 faces as well as all the others (note the different Haar cascade and the minimum size):
Mat im1 = imread("JuVIA.png", CV_LOAD_IMAGE_COLOR);
vector<Rect> faces;
CascadeClassifier cascade( "C:/local/opencv249/sources/data/haarcascades/haarcascade_frontalface_alt2.xml" );
cascade.detectMultiScale( im1, faces, 1.1, 2, 0| CV_HAAR_SCALE_IMAGE, Size(30, 30) );
for( vector<Rect>::const_iterator r = faces.begin(); r != faces.end(); r++ )
cv::rectangle( im1, *r, CV_RGB(255,0,0) );
imshow("in", im1);
imwrite( "miss4.png", im1);
waitKey();
It is because the faceDetector the tutorial chose to use is lbpcascade_frontalface.xml which is not good enough, at least couldn't detect all the faces in the picture you used.
You may change to use haarcascade_frontalface_alt.xml under opencv-2.4.8\sources\data\haarcascades folder. Then all faces would be detected.
Here following is the result:, more details please refer to:http://www.pkuaas.org/?uid-1140-action-viewspace-itemid-3224
I have an image with 400x400 image to identify different components from it. But when I try to identify components using that most of time it doesn't provide correct answers. So I need to know whether there are some kind of methods in javacv or opencv to improve the quality of the image or increase the size of the image without effecting to its quality ?
This is the sample image that I use. (This is the maximum size that I can get and I can't use any photo editing softwares in the project, because it's dynamically generated image.)
In my image processing I need to identify squares and rectangles that connects those squares. And specially I need to get the width and height of those using pixel values.
You can scale it to any size, if you can vectorize it... and in your case vestorization is quite simple as you have some simple geometrical objects in image.
So, in my view your approach should be like this:
detect edges in the image with a high threshold (as you have very distinct objects)
vectorize them
scale them to any size
You should also look at the following link: Increasing camera capture resolution in OpenCV.
If you stick to image processing the easiest way to do it is to apply an equalizeHist(). This will increase contrast and will improve subsequent steps.
But, and this is a biiiig 'but', why are you doing it? Just reading this post, I saw another solution, and a quick google proved me I am right:
Kabeja is a Java library for parsing, processing and converting
Autodesk's DXF format. You can use Kabeja from the CommandLine or
embed into your application. All parsed data are accessible with the
DOM-like API.
That means you can extract directly all the data you want from that image in a text format. Probably something like "at position x, y there is a transistor, or whatever." So why would you render that file into an image, then analyse that image to extract the components?
If you do it for school (I know that many school projects are like this) I would recommend you to find a real problem to solve, and propose it to your teacher. You will be happier to do something that is not complete nonsense.
vectorizing the image is best option I guess as suggested by mocap.
you can also use enhancement tools like sharpening, saturating etc.
I want to automatically select area of the page to crop later.
I thought edge detection might be useful and used canny edge detection to find edges of the image. Now I have this image! but I've no clear idea to select area of the page as a rectangle. Can anyone suggest a method or implementation for this problem?
What I really want to do is this selecting the area of the page as follows.
Is there any other method to do this? I have also seen boundary detection in the book of introduction to digital image processing using matlab. But I'm not familiar with that. Can I use that for this purpose?
I assume that you have "Canny-ed" image. Now you can use
Imgproc.findCountours, to find and store edges (you need List<MatOfPoint>for that). Before using findContours i would play with Imgproc.dilate, which might help finding contours(it "fattens" lines so we are sure that findContours wont miss your target). Then you need only to use Imgproc.boudningRect to get your ROI. Then just crop image using this ROI.