Commit 43ce7908 authored by Davis King's avatar Davis King

Added skeleton of fhog object detection example.

parent f3dc3c0e
...@@ -33,6 +33,7 @@ add_example(custom_trainer_ex) ...@@ -33,6 +33,7 @@ add_example(custom_trainer_ex)
add_example(dir_nav_ex) add_example(dir_nav_ex)
add_example(empirical_kernel_map_ex) add_example(empirical_kernel_map_ex)
add_example(fhog_ex) add_example(fhog_ex)
add_example(fhog_object_detector_ex)
add_example(file_to_code_ex) add_example(file_to_code_ex)
add_example(graph_labeling_ex) add_example(graph_labeling_ex)
add_example(gui_api_ex) add_example(gui_api_ex)
......
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes' />
<!-- ************************************************************************* -->
<xsl:variable name="max_images_displayed">30</xsl:variable>
<!-- ************************************************************************* -->
<xsl:template match="/dataset">
<html>
<head>
<style type="text/css">
div#box{
position: absolute;
border-style:solid;
border-width:1px;
border-color:red;
}
div#circle{
position: absolute;
border-style:solid;
border-width:1px;
border-color:red;
border-radius:7px;
width:14px;
height: 14px;
}
div#label{
position: absolute;
color: red;
}
div#img{
position: relative;
margin-bottom:2em;
}
pre {
color: black;
margin: 1em 0.25in;
padding: 0.5em;
background: rgb(240,240,240);
border-top: black dotted 1px;
border-left: black dotted 1px;
border-right: black solid 2px;
border-bottom: black solid 2px;
}
</style>
</head>
<body>
Dataset name: <b><xsl:value-of select='/dataset/name'/></b> <br/>
Dataset comment: <pre><xsl:value-of select='/dataset/comment'/></pre> <br/>
Number of images: <xsl:value-of select="count(images/image)"/> <br/>
Number of boxes: <xsl:value-of select="count(images/image/box)"/> <br/>
<br/>
<hr/>
<!-- Show a warning if we aren't going to show all the images -->
<xsl:if test="count(images/image) &gt; $max_images_displayed">
<h2>Only displaying the first <xsl:value-of select="$max_images_displayed"/> images.</h2>
<hr/>
</xsl:if>
<xsl:for-each select="images/image">
<!-- Don't try to display too many images. It makes your browser hang -->
<xsl:if test="position() &lt;= $max_images_displayed">
<b><xsl:value-of select="@file"/></b> (Number of boxes: <xsl:value-of select="count(box)"/>)
<div id="img">
<img src="{@file}"/>
<xsl:for-each select="box">
<div id="box" style="top: {@top}px; left: {@left}px; width: {@width}px; height: {@height}px;"></div>
<!-- If there is a label then display it in the lower right corner. -->
<xsl:if test="label">
<div id="label" style="top: {@top+@height}px; left: {@left+@width}px;">
<xsl:value-of select="label"/>
</div>
</xsl:if>
<xsl:for-each select="part">
<div id="label" style="top: {@y+7}px; left: {@x}px;">
<xsl:value-of select="@name"/>
</div>
<div id="circle" style="top: {(@y)-7}px; left: {(@x)-7}px; "></div>
</xsl:for-each>
</xsl:for-each>
</div>
</xsl:if>
</xsl:for-each>
</body>
</html>
</xsl:template>
<!-- ************************************************************************* -->
</xsl:stylesheet>
<?xml version='1.0' encoding='ISO-8859-1'?>
<?xml-stylesheet type='text/xsl' href='image_metadata_stylesheet.xsl'?>
<dataset>
<name>imglab dataset</name>
<comment>Created by imglab tool.</comment>
<images>
<image file='2008_002470.jpg'>
<box top='181' left='274' width='52' height='53'/>
<box top='156' left='55' width='44' height='44'/>
<box top='166' left='146' width='37' height='37'/>
<box top='55' left='329' width='44' height='44'/>
<box top='74' left='233' width='44' height='44'/>
<box top='86' left='178' width='37' height='37'/>
</image>
<image file='2008_002506.jpg'>
<box top='78' left='329' width='109' height='109'/>
<box top='95' left='224' width='91' height='91'/>
<box top='65' left='125' width='90' height='91'/>
</image>
<image file='2008_004176.jpg'>
<box top='230' left='206' width='37' height='37'/>
<box top='118' left='162' width='37' height='37'/>
<box top='82' left='190' width='37' height='37'/>
<box top='78' left='326' width='37' height='37'/>
<box top='98' left='222' width='37' height='37'/>
<box top='86' left='110' width='37' height='37'/>
<box top='102' left='282' width='37' height='37'/>
</image>
<image file='2008_007676.jpg'>
<box top='62' left='226' width='37' height='37'/>
<box top='113' left='194' width='44' height='44'/>
<box top='130' left='262' width='37' height='37'/>
<box top='134' left='366' width='37' height='37'/>
<box top='122' left='314' width='37' height='37'/>
<box top='141' left='107' width='52' height='53'/>
<box top='84' left='137' width='44' height='44'/>
</image>
<image file='2009_004587.jpg'>
<box top='46' left='154' width='75' height='76'/>
<box top='280' left='266' width='63' height='63'/>
</image>
</images>
</dataset>
<?xml version='1.0' encoding='ISO-8859-1'?>
<?xml-stylesheet type='text/xsl' href='image_metadata_stylesheet.xsl'?>
<dataset>
<name>imglab dataset</name>
<comment>Created by imglab tool.</comment>
<images>
<image file='2007_007763.jpg'>
<box top='90' left='194' width='37' height='37'/>
<box top='114' left='158' width='37' height='37'/>
<box top='89' left='381' width='45' height='44'/>
<box top='198' left='94' width='37' height='37'/>
<box top='214' left='178' width='37' height='37'/>
<box top='86' left='294' width='37' height='37'/>
<box top='233' left='309' width='45' height='44'/>
</image>
<image file='2008_002079.jpg'>
<box top='166' left='406' width='37' height='37'/>
<box top='134' left='122' width='37' height='37'/>
<box top='138' left='346' width='37' height='37'/>
<box top='175' left='439' width='44' height='44'/>
<box top='134' left='62' width='37' height='37'/>
<box top='194' left='41' width='44' height='44'/>
</image>
<image file='2008_001009.jpg'>
<box top='79' left='145' width='76' height='76'/>
<box top='214' left='125' width='90' height='91'/>
</image>
<image file='2008_001322.jpg'>
<box top='162' left='104' width='76' height='76'/>
<box top='218' left='232' width='63' height='63'/>
<box top='155' left='344' width='90' height='90'/>
</image>
</images>
</dataset>
// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
/*
This is an example illustrating the use of the dlib tools for
detecting objects in images. In this example we will create
three simple images, each containing some white squares. We
will then use the sliding window classifier tools to learn to
detect these squares.
*/
#include <dlib/time_this.h>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/svm_threaded.h>
#include <dlib/gui_widgets.h>
#include <dlib/array.h>
#include <dlib/array2d.h>
#include <dlib/image_keypoint.h>
#include <dlib/image_processing.h>
#include <dlib/data_io.h>
#include <iostream>
#include <fstream>
using namespace std;
using namespace dlib;
// ----------------------------------------------------------------------------------------
int main()
{
/*
NOTES
- explain the concepts of ignore boxes
*/
try
{
dlib::array<array2d<unsigned char> > images, images_test;
std::vector<std::vector<rectangle> > object_locations, object_locations_test;
load_image_dataset(images, object_locations, "../faces/training.xml");
upsample_image_dataset<pyramid_down<2> >(images, object_locations);
load_image_dataset(images_test, object_locations_test, "../faces/testing.xml");
upsample_image_dataset<pyramid_down<2> >(images_test, object_locations_test);
add_image_left_right_flips(images, object_locations);
cout << "num training images: " << images.size() << endl;
cout << "num testing images: " << images_test.size() << endl;
typedef scan_fhog_pyramid<pyramid_down<6> > image_scanner_type;
image_scanner_type scanner;
scanner.set_detection_window_size(80, 80); // faces
//scanner.set_nuclear_norm_regularization_strength(1.0);
structural_object_detection_trainer<image_scanner_type> trainer(scanner);
trainer.set_num_threads(6); // Set this to the number of processing cores on your machine.
trainer.set_c(1);
//trainer.set_c(10);
trainer.be_verbose();
trainer.set_epsilon(0.01);
// TODO, talk about this option
//remove_unobtainable_rectangles(trainer, images, object_locations);
object_detector<image_scanner_type> detector = trainer.train(images, object_locations);
cout << "num filters 0.0: "<< num_separable_filters(detector) << endl;
cout << "training results 0.0: " << test_object_detection_function(detector, images, object_locations) << endl;
cout << "testing results 0.0: " << test_object_detection_function(detector, images_test, object_locations_test) << endl;
detector = threshold_filter_singular_values(detector,0.01);
cout << "num filters 0.01: "<< num_separable_filters(detector) << endl;
cout << "testing results 0.01: " << test_object_detection_function(detector, images_test, object_locations_test) << endl;
detector = threshold_filter_singular_values(detector,0.1);
cout << "num filters 0.1: "<< num_separable_filters(detector) << endl;
cout << "testing results 0.1: " << test_object_detection_function(detector, images_test, object_locations_test) << endl;
image_window win, hogwin(draw_fhog(detector));
for (unsigned long i = 0; i < images_test.size(); ++i)
{
std::vector<rectangle> dets;
TIME_THIS(
dets = detector(images_test[i]);
);
win.clear_overlay();
win.set_image(images_test[i]);
win.add_overlay(dets, rgb_pixel(255,0,0));
cin.get();
}
ofstream fout("face_detector.svm", ios::binary);
serialize(detector, fout);
}
catch (exception& e)
{
cout << "\nexception thrown!" << endl;
cout << e.what() << endl;
}
}
// ----------------------------------------------------------------------------------------
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment