Commit 1f8ccc16 authored by Leonardo lontra's avatar Leonardo lontra Committed by Vadim Pisarevsky

added edgeboxes algorithm (#1215)

samples added

fix edgeboxes_demo

fix edgeboxes_demo

added edgeboxes bib

fix edgeboxes_demo

small fixes

fix edgeboxes_demo

fix warnings

fix warnings

small fixes

detectEdges needs rgb image instead bgr image.

Removed unnecessary protection

small fixes
parent a44a2ba7
......@@ -2,6 +2,7 @@ Extended Image Processing
=========================
- Structured Forests
- Edge Boxes
- Domain Transform Filter
- Guided Filter
- Adaptive Manifold Filter
......
@inproceedings{ZitnickECCV14edgeBoxes,
author = {C. Lawrence Zitnick and Piotr Doll{\'a}r},
title = {Edge Boxes: Locating Object Proposals from Edges},
booktitle = {ECCV},
year = {2014},
}
@inproceedings{Dollar2013,
title={Structured forests for fast edge detection},
author={Doll{\'a}r, Piotr and Zitnick, C Lawrence},
......
......@@ -41,6 +41,7 @@
#include "ximgproc/disparity_filter.hpp"
#include "ximgproc/sparse_match_interpolator.hpp"
#include "ximgproc/structured_edge_detection.hpp"
#include "ximgproc/edgeboxes.hpp"
#include "ximgproc/seeds.hpp"
#include "ximgproc/segmentation.hpp"
#include "ximgproc/fast_hough_transform.hpp"
......@@ -62,6 +63,8 @@
This module contains implementations of modern structured edge detection algorithms,
i.e. algorithms which somehow takes into account pixel affinities in natural images.
@defgroup ximgproc_edgeboxes EdgeBoxes
@defgroup ximgproc_filters Filters
@defgroup ximgproc_superpixel Superpixels
......
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef __OPENCV_EDGEBOXES_HPP__
#define __OPENCV_EDGEBOXES_HPP__
#include <opencv2/core.hpp>
namespace cv
{
namespace ximgproc
{
//! @addtogroup ximgproc_edgeboxes
//! @{
// bounding box data structures
typedef struct
{
int x, y, w, h;
float score;
} Box;
typedef std::vector<Box> Boxes;
/** @brief Class implementing EdgeBoxes algorithm from @cite ZitnickECCV14edgeBoxes :
*/
class CV_EXPORTS_W EdgeBoxes : public Algorithm
{
public:
/** @brief Returns array containing proposal boxes.
@param edge_map edge image.
@param orientation_map orientation map.
@param boxes proposal boxes.
*/
CV_WRAP virtual void getBoundingBoxes(InputArray edge_map, InputArray orientation_map, CV_OUT std::vector<Rect> &boxes) = 0;
/** @brief Returns the step size of sliding window search.
*/
CV_WRAP virtual float getAlpha() const = 0;
/** @brief Sets the step size of sliding window search.
*/
CV_WRAP virtual void setAlpha(float value) = 0;
/** @brief Returns the nms threshold for object proposals.
*/
CV_WRAP virtual float getBeta() const = 0;
/** @brief Sets the nms threshold for object proposals.
*/
CV_WRAP virtual void setBeta(float value) = 0;
/** @brief Returns adaptation rate for nms threshold.
*/
CV_WRAP virtual float getEta() const = 0;
/** @brief Sets the adaptation rate for nms threshold.
*/
CV_WRAP virtual void setEta(float value) = 0;
/** @brief Returns the min score of boxes to detect.
*/
CV_WRAP virtual float getMinScore() const = 0;
/** @brief Sets the min score of boxes to detect.
*/
CV_WRAP virtual void setMinScore(float value) = 0;
/** @brief Returns the max number of boxes to detect.
*/
CV_WRAP virtual int getMaxBoxes() const = 0;
/** @brief Sets max number of boxes to detect.
*/
CV_WRAP virtual void setMaxBoxes(int value) = 0;
/** @brief Returns the edge min magnitude.
*/
CV_WRAP virtual float getEdgeMinMag() const = 0;
/** @brief Sets the edge min magnitude.
*/
CV_WRAP virtual void setEdgeMinMag(float value) = 0;
/** @brief Returns the edge merge threshold.
*/
CV_WRAP virtual float getEdgeMergeThr() const = 0;
/** @brief Sets the edge merge threshold.
*/
CV_WRAP virtual void setEdgeMergeThr(float value) = 0;
/** @brief Returns the cluster min magnitude.
*/
CV_WRAP virtual float getClusterMinMag() const = 0;
/** @brief Sets the cluster min magnitude.
*/
CV_WRAP virtual void setClusterMinMag(float value) = 0;
/** @brief Returns the max aspect ratio of boxes.
*/
CV_WRAP virtual float getMaxAspectRatio() const = 0;
/** @brief Sets the max aspect ratio of boxes.
*/
CV_WRAP virtual void setMaxAspectRatio(float value) = 0;
/** @brief Returns the minimum area of boxes.
*/
CV_WRAP virtual float getMinBoxArea() const = 0;
/** @brief Sets the minimum area of boxes.
*/
CV_WRAP virtual void setMinBoxArea(float value) = 0;
/** @brief Returns the affinity sensitivity.
*/
CV_WRAP virtual float getGamma() const = 0;
/** @brief Sets the affinity sensitivity
*/
CV_WRAP virtual void setGamma(float value) = 0;
/** @brief Returns the scale sensitivity.
*/
CV_WRAP virtual float getKappa() const = 0;
/** @brief Sets the scale sensitivity.
*/
CV_WRAP virtual void setKappa(float value) = 0;
};
/** @brief Creates a Edgeboxes
@param alpha step size of sliding window search.
@param beta nms threshold for object proposals.
@param eta adaptation rate for nms threshold.
@param minScore min score of boxes to detect.
@param maxBoxes max number of boxes to detect.
@param edgeMinMag edge min magnitude. Increase to trade off accuracy for speed.
@param edgeMergeThr edge merge threshold. Increase to trade off accuracy for speed.
@param clusterMinMag cluster min magnitude. Increase to trade off accuracy for speed.
@param maxAspectRatio max aspect ratio of boxes.
@param minBoxArea minimum area of boxes.
@param gamma affinity sensitivity.
@param kappa scale sensitivity.
*/
CV_EXPORTS_W Ptr<EdgeBoxes>
createEdgeBoxes(float alpha=0.65f,
float beta=0.75f,
float eta=1,
float minScore=0.01f,
int maxBoxes=10000,
float edgeMinMag=0.1f,
float edgeMergeThr=0.5f,
float clusterMinMag=0.5f,
float maxAspectRatio=3,
float minBoxArea=1000,
float gamma=2,
float kappa=1.5f);
//! @}
}
}
#endif /* __OPENCV_EDGEBOXES_HPP__ */
/*
By downloading, copying, installing or using the software you agree to this
license. If you do not agree to this license, do not download, install,
copy or use the software.
License Agreement
For Open Source Computer Vision Library
(3-clause BSD License)
Copyright (C) 2013, OpenCV Foundation, all rights reserved.
Third party copyrights are property of their respective owners.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the names of the copyright holders nor the names of the contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
This software is provided by the copyright holders and contributors "as is" and
any express or implied warranties, including, but not limited to, the implied
warranties of merchantability and fitness for a particular purpose are
disclaimed. In no event shall copyright holders or contributors be liable for
any direct, indirect, incidental, special, exemplary, or consequential damages
(including, but not limited to, procurement of substitute goods or services;
loss of use, data, or profits; or business interruption) however caused
and on any theory of liability, whether in contract, strict liability,
or tort (including negligence or otherwise) arising in any way out of
the use of this software, even if advised of the possibility of such damage.
*/
#include "opencv2/ximgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
using namespace cv::ximgproc;
static void help()
{
std::cout << std::endl <<
"This sample demonstrates structured edge detection and edgeboxes." << std::endl <<
"Usage:" << std::endl <<
"./edgeboxes_demo [<model>] [<input_image>]" << std::endl;
}
int main(int argc, char **argv)
{
if (argc < 3)
{
help();
return -1;
}
Ptr<StructuredEdgeDetection> pDollar = createStructuredEdgeDetection(argv[1]);
Mat im;
im = imread(argv[2]);
Mat rgb_im;
cvtColor(im, rgb_im, COLOR_BGR2RGB);
rgb_im.convertTo(rgb_im, CV_32F, 1.0 / 255.0f);
Mat edge_im;
pDollar->detectEdges(rgb_im, edge_im);
// computes orientation from edge map
Mat O;
pDollar->computeOrientation(edge_im, O);
// apply edge nms
Mat edge_nms;
pDollar->edgesNms(edge_im, O, edge_nms, 2, 0, 1, true);
std::vector<Rect> boxes;
Ptr<EdgeBoxes> edgeboxes = createEdgeBoxes();
edgeboxes->setMaxBoxes(30);
edgeboxes->getBoundingBoxes(edge_nms, O, boxes);
for(int i = 0; i < (int)boxes.size(); i++)
{
Point p1(boxes[i].x, boxes[i].y), p2(boxes[i].x + boxes[i].width, boxes[i].y + boxes[i].height);
Scalar color(0, 255, 0);
rectangle(im, p1, p2, color, 1);
}
imshow("im", im);
waitKey(0);
return 0;
}
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
This sample demonstrates structured edge detection and edgeboxes.
Usage:
edgeboxes_demo.py [<model>] [<input_image>]
'''
import cv2
import numpy as np
import sys
if __name__ == '__main__':
print(__doc__)
model = sys.argv[1]
im = cv2.imread(sys.argv[2])
edge_detection = cv2.ximgproc.createStructuredEdgeDetection(model)
rgb_im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
edges = edge_detection.detectEdges(np.float32(rgb_im) / 255.0)
orimap = edge_detection.computeOrientation(edges)
edges = edge_detection.edgesNms(edges, orimap)
edge_boxes = cv2.ximgproc.createEdgeBoxes()
edge_boxes.setMaxBoxes(30)
boxes = edge_boxes.getBoundingBoxes(edges, orimap)
for b in boxes:
x, y, w, h = b
cv2.rectangle(im, (x, y), (x+w, y+h), (0, 255, 0), 1, cv2.LINE_AA)
cv2.imshow("edges", edges)
cv2.imshow("edgeboxes", im)
cv2.waitKey(0)
cv2.destroyAllWindows()
This diff is collapsed.
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