How to make xml file for side faces in face detection - java

I have been working on face detection and i am able to detect frontal faces like all other people using the haarcascade xml files. My next task is to detect a side face (Non-Frontal). I am working in opencv. The profileface xml is not able to detect the side faces with accuracy. So i feel only option left is to make my own xml file which can detect side faces. Can anyone help me out?
Thanks

Did you try to combine the frontal and profile face recognition?
I was working with this as well, and the result was pretty good actually.
You also need to specify the min and max framesize as accurate as possible.
Unfortunately I did not find a side face haarcascade, so it looks like, you need to train your own one.
if you just want to test this out, you don't actually need so many pictures of faces.
You need a lot of negatives. Because opencv provides a function to generate positive pictures based on a single image of the face and a bunch of negative pictures.
To find the negative pictures you could simply take a video of the backgrounds where you want to detect the faces, and then just extract all the images form the video file. From only 3 minutes you get over 2000 images.
For the training I would recommend you to keep the size of all pictures very small, because otherwise it will take like forever to train the cascade file.

maybe you can see opencv Cascade Classifier Training for a reference. I didn't try it, but offer you for a reference.
website: http://docs.opencv.org/2.4/doc/user_guide/ug_traincascade.html
and there are some Q&A for training.
website: http://www.computer-vision-software.com/blog/2009/11/faq-opencv-haartraining/

Related

Object matching in OpenCV 3.1 for Java

I found out that there is Chamfer Matching available in OpenCV. I can see there is a function chamferMatching() for C++ and there seems to be a way to use it in Python, too. However, I was unable to find how to use this feature in Java. I am using OpenCV 3.1 Where can I find it in the Java interface? Is it even available there?
If not, what can I use instead? I am trying to recognize fruits. For now apples in particular. I want to match precomputed apple contour to found contours in the image (chamfer matching). After finding a possible apple I am planning to use a classifier to make sure the color and texture are correct.
Template matching seems to be a bad choice because it doesn't work with recognizing rotated objects. I am wondering if I can use Feature Descriptors. Note that I am not trying to recognize a particular apple and I don't know if Feature Descriptors are good for this.
Any thoughts?
EDIT: Ok, I decided to use the findContours() function to get all of the contours in the image, then filter them by area and compare each of the filtered contours with others, designated as templates from training, using matchShapes(). I implemented this and it is not working right (because findContours() is not detecting the apple contours) but I'll post another question with this specific problem. Here I want to ask if this way sounds ok and if there is a better way to detect and compare contours.
Ok, I figured it out. There seems to be no Chamfer Matching in OpenCV. It is implemented in JavaCV and there is no sign of it in the native code. Since I'm using OpenCV for Java it is not a good solution for me.
This answer helped me a lot. It is in C++ but it can easily be written in Java.
Initially, I am training the program using a database of 100 images of green apples. The training is actually just storing the largest contour of every photo in a file.
The key to my problem was dividing the image into the 3 different channels resulting in 3 different grayscale images. I transform them using Canny and dilate. Now I check every one of them for contours and it is very likely I will detect the contours of the apple in at least one of them. Once I have all the contours from the 3 images, I filter them by size and then comparing them with every single contour from the training data. If the contour is close enough to one of them I assume it is a contour of an apple.
There seems to be quite a lot of false positives but they will be filtered out when my coleague implements the module doing checks for color and texture of the selected contours (their content).
Here's our project's repository if it would be of help to anyone.

How to count color pages in a PDF/Word doc using Java

I am looking to develop a desktop application using Java to count the number of colored pages in a PDF or Word file. This will be used as part of an overall system to help calculate the cost of printing a document in terms of how many pages there are (color/B&W).
Ideally, the user of the application would use a file dialog to select the desired PRF/Word file, the application could then count and output the number of colored pages, allowing the system to automatically calculate document cost accordingly.
i.e
if A4 colored pages cost 50c per page to print,
and B&W cost 10c per page,
calculate the total cost of the document per colored/B&W pages.
I am aware of the existing software Rapid PDF Count http://www.traction-software.co.uk/rapidpdfcount/, but would be unsuitable as part on integration into a new system. I have also tried using GhostScript/Python as per this solution: http://root42.blogspot.de/2012/10/counting-color-pages-in-pdf-files.html, however this takes too long (5mins to count a 100 page pdf), and would be difficult to implement into a desktop app.
Is there any method of counting the number of colored pages in a PDF or Word file using Java (or alternative language)
Thanks
Although it might sound easy, the task is rather complicated.
One option would be to use a program such as iText to walk every single token in the PDF, look for tokens that support color and compare that to your definition of "black". However, this will only get you basic text and drawing commands. Images are a completely different beast so you'll probably need to find an image parser or grab a copy of each spec and then walk each of those.
One of the downsides of token walking is you need to properly handle tokens that reference other things and further walk those tokens.
Another downside is that things can overlap each other so you'd probably want be aware of their coordinates, z-index, transparency and such.
There will be many more bumps in the road but that's a good start. What's most interesting is that if you accomplish this, you'll actually have found that you've partially built a PDF renderer!
Next, you'll need to define "black". Off the top of my head there's RGB black, CMYK black, Grey black and maybe Lab black along with some Pantones. That shouldn't be too hard but if I were to build this I'd want to know "blank ink usage" which could also be shades of grey. There's also "rich blank" that you might need to deal with, too!
So, all that said, I think that the GhostScript option you found is really the best bet. It literally renders the PDF and calculates the ink coverage from an RGB standpoint. You still should handle grey's, too, but that shouldn't be too hard, here's a good starting point.
Wanting to know what the click-charge is going to be is a pretty common problem, but it's not easy to solve at all. As already indicated by the answer Chris Haas gave, but I want to put another spin on it.
First of all, you have to wonder whether you really want to support both Word and PDF documents. Analysing Word files is less useful than you might think because that Word file is probably going to be converted into something else before it's going to be printed. And because of the fact that you're starting from Word, the chance that your nice RGB black text in Word gets converted to less-than-perfect 4 color black in PDF is very high. In other words, even though you might count a page of black text in Word as a 'cheap' page, it might turn into an expensive color page after conversion from Word to something that can be printed.
Let's consider the PDF case then. PDF supports a whole host of color spaces (gray, RGB, CMYK, the same with an ICC Profile attached, spot color and a few multi-spot color variants, CalGray and CalRGB and Lab. Besides that there is a whole range of very tricky features such as transparency, overprint, shades, images, masks... that you all have to take into account. The only truly good way to calculate what you need is to do essentially the same work as your printer will do; convert the PDF into one image per page and examine the pixels.
Because of what you want to do, the best way to progress would be to:
1) Convert any word files into PDF
2) Convert any PDF files into CMYK
3) Render each page of that CMYK file into an image.
Once you've done that you can examine the image and see whether you have any colors left. There are a number of potential technologies you can use for this. GhostScript is definitely one, but there are commercial solutions too that would certainly be more expensive but potentially faster.

How to detect a motion in a video by using openCV

I'm new to OpenCV and I want to detect the actions in a video by using openCV. Let say the video is a cricket match, then I want to detect who is the batmat and who is the bowler by using their motions. Can anyone guide me how can I do this with examples or some related videos. All your comments are highly appreciated.
With my limited understanding on image processing, I feel the approach ( especially haar classifiers ) in the accepted answer might not be the best option you have.
Read up on following
Optical flow based processing - That will help you identify motion.
Background subtraction - Ground color is usually green and player clothes also have color.
Contours - They let you identify shapes.
Hough Line transform - There will be lines in your video stream.
Edge detection
I assume one of intentions of doing this project is to learn image processing and just not to get the result. Training a haar xml for identifying a batsman/bowler with +ve/-ve image samples is more like repetitive job than a real learning process. More over, you will need to spend lots of time collecting samples, and then retraining xmls on failure etc. Also, haar classifiers are for object detection are not for motion detection as mentioned in question.
Aishack website has some references projects with image processing ideas. Wait for more responses to this question from experts.
Look into object recognition and Haar classifiers, specifically train_cascade methods of theOpenCV library. You'll need a LOT of still samples of each player type and their typical moves, then train a classifier and then analyze video frames to pick them out. You have a long, but awesome road ahead of you.

Using Java & BoofCV to detect shapes in an image file

I've not found anything here or on google. I'm looking for a way to identify shapes (circle, square, triangle and various other shapes) from a image file. Some examples:
You get the general idea. Not sure if BoofCV is the best choice here but it looks like it should be straightforward enough to use, but again I know nothing about it. I've looked at some of the examples and I though before I get in over my head (which is not hard to do some days), I thought I would ask if there is any info out there.
I'm taking a class on Knowledge Based AI solving Ravens Progressive Matrix problems and the final assignment will use strictly visual based images instead of the text files with attributes. We are not being graded on the visual since we only have a few weeks to work on this section of the project and we are encouraged to share this information. SOF has always been my go to source for information and I'm hoping someone out there might have some ideas on where to start with this...
Essentially what I want to do is detect the shapes (?? convert them into 2D geometry) and then make some assumptions about attributes such as size, fill, placement etc, create a text file with these attributes and then using that, send it through my existing code based that I wrote for my other projects to solve the problems.
Any suggestions????
There are a lot of ways you can do it. One way is to find the contour of the shape then fit a polygon to it or a oval. If you git a polygon to it and there are 4 sides with almost equal length then its a square. The contour can be found with binary blobs (my recommendation for the above images) or canny edge.
http://boofcv.org/index.php?title=Example_Fit_Polygon
http://boofcv.org/index.php?title=Example_Fit_Ellipse

Object detection with a generic webcam

Here’s my task which I want to solve with as little effort as possible (preferrably with QT & C++ or Java): I want to use webcam video input to detect if there’s a (or more) crate(s) in front of the camera lens or not. The scene can change from "clear" to "there is a crate in front of the lens" and back while the cam feeds its video signal to my application. For prototype testing/ learning I have 2-3 images of the “empty” scene, and 2-3 images with one or more crates.
Do you know straightforward idea how to tackle this task? I found OpenCV, but isn't this framework too bulky for this simple task? I'm new to the field of computer vision. Is this generally a hard task or is it simple and robust to detect if there's an obstacle in front of the cam in live feeds? Your expert opinion is deeply appreciated!
Here's an approach I've heard of, which may yield some success:
Perform edge detection on your image to translate it into a black and white image, whereby edges are shown as black pixels.
Now create a histogram to record the frequency of black pixels in each vertical column of pixels in the image. The theory here is that a high frequency value in the histogram in or around one bucket is indicative of a vertical edge, which could be the edge of a crate.
You could also consider a second histogram to measure pixels on each row of the image.
Obviously this is a fairly simple approach and is highly dependent on "simple" input; i.e. plain boxes with "hard" edges against a blank background (preferable a background that contrasts heavily with the box).
You dont need a full-blown computer-vision library to detect if there is a crate or no crate in front of the camera. You can just take a snapshot and make a color-histogram (simple). To capture the snapshot take a look here:
http://msdn.microsoft.com/en-us/library/dd742882%28VS.85%29.aspx
Lots of variables here including any possible changes in ambient lighting and any other activity in the field of view. Look at implementing a Canny edge detector (which OpenCV has and also Intel Performance Primitives have as well) to look for the outline of the shape of interest. If you then kinda know where the box will be, you can perhaps sum pixels in the region of interest. If the box can appear anywhere in the field of view, this is more challenging.
This is not something you should start in Java. When I had this kind of problems I would start with Matlab (OpenCV library) or something similar, see if the solution would work there and then port it to Java.
To answer your question I did something similar by XOR-ing the 'reference' image (no crate in your case) with the current image then either work on the histogram (clustered pixels at right means large difference) or just sum the visible pixels and compare them with a threshold. XOR is not really precise but it is fast.
My point is, it took me 2hrs to install Scilab and the toolkits and write a proof of concept. It would have taken me two days in Java and if the first solution didn't work each additional algorithm (already done in Mat-/Scilab) another few hours. IMHO you are approaching the problem from the wrong angle.
If really Java/C++ are just some simple tools that don't matter then drop them and use Scilab or some other Matlab clone - prototyping and fine tuning would be much faster.
There are 2 parts involved in object detection. One is feature extraction, the other is similarity calculation. Some obvious features of the crate are geometry, edge, texture, etc...
So you can find some algorithms to extract these features from your crate image. Then comparing these features with your training sample images.

Categories

Resources