Skip to content

Commit

Permalink
big change: detectors need not cleanup between detections and they ig…
Browse files Browse the repository at this point in the history
…nore each other's circles for free; global cleanup is used only once at the end

since it is quite fast; all console printing is now turned off and can be turned on during compilation
  • Loading branch information
v01d committed May 8, 2015
1 parent 61cdba7 commit abf7837
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 181 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ cmake_minimum_required(VERSION 2.8)
project(whycon)

# set some flags
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -O4 -march=native -Wfatal-errors")
add_definitions(-std=c++11)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_RELEASE} -Wall -O4 -march=native -Wfatal-errors")
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_RELEASE} -Wall -O0 -g -Wfatal-errors")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake-configs")

# set some options
option(DISABLE_ROS "Do not build for ROS, but as standalone code" OFF)
option(ENABLE_FULL_UNDISTORT "Undistort the whole frame" OFF)
option(ENABLE_RANDOMIZED_THRESHOLD "Use rand() instead of binary-like search for threshold" OFF)
option(ENABLE_VERBOSE "Enable verbose console messages during detection" OFF)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/include/whycon/config.h)

#### ROS CONFIGURATION ####
Expand Down
7 changes: 7 additions & 0 deletions config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@

#cmakedefine ENABLE_FULL_UNDISTORT
#cmakedefine ENABLE_RANDOMIZED_THRESHOLD
#cmakedefine ENABLE_VERBOSE

#if defined(ENABLE_VERBOSE)
#define WHYCON_DEBUG(x) cout << x << endl
#else
#define WHYCON_DEBUG(x)
#endif

#endif
31 changes: 20 additions & 11 deletions include/whycon/circle_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <opencv2/opencv.hpp>
#include <math.h>
#include <vector>
#include <whycon/config.h>
#include <unordered_set>

#define WHYCON_DEFAULT_OUTER_DIAMETER 0.122
#define WHYCON_DEFAULT_INNER_DIAMETER 0.050
Expand All @@ -24,7 +26,7 @@ namespace cv {
CircleDetector(int width, int height, Context* context, float diameter_ratio = WHYCON_DEFAULT_DIAMETER_RATIO);
~CircleDetector();

Circle detect(const cv::Mat& image, const Circle& previous_circle = cv::CircleDetector::Circle());
Circle detect(const cv::Mat& image, bool& fast_cleanup_possible, const Circle& previous_circle = cv::CircleDetector::Circle());
bool examineCircle(const cv::Mat& image, Circle& circle, int ii, float areaRatio, bool search_in_window);
void cover_last_detected(cv::Mat& image);

Expand All @@ -46,6 +48,7 @@ namespace cv {

int threshold, threshold_counter;
void change_threshold(void);
inline int threshold_pixel(uchar* ptr);

int queueStart,queueEnd,queueOldStart,numSegments;

Expand All @@ -54,22 +57,23 @@ namespace cv {
int local_window_width, local_window_height, local_window_x, local_window_y;

Context* context;

int detector_id, BLACK, WHITE, UNKNOWN;
int initial_segment_id;

inline bool is_unclassified(int pixel_class);

public:
class Circle {
public:
Circle(void);

float x;
float y;
float x, y;
int size;
int maxy,maxx,miny,minx;
int mean;
int type;
float roundness;
float bwRatio;
bool round;
bool valid;
float roundness, bwRatio;
bool round, valid;
float m0,m1; // axis dimensions
float v0,v1; // axis (v0,v1) and (v1,-v0)

Expand All @@ -84,12 +88,17 @@ namespace cv {
Context(int _width, int _height);
void debug_buffer(const cv::Mat& image, cv::Mat& img);

void cleanup_buffer(void);
void cleanup_buffer(const Circle& c);
void reset(void);

std::vector<int> buffer, queue;
int width, height;

private:
void cleanup(const Circle& c, bool fast_cleanup);
friend class CircleDetector;
int next_detector_id;
std::unordered_set<int> valid_segment_ids;
int total_segments;

};
};
}
Expand Down
6 changes: 4 additions & 2 deletions launch/mono.launch
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
<group ns="camera">
<node pkg="image_proc" type="image_proc" name="image_proc"/>
</group>
<node name="whycon" type="whycon" pkg="whycon" _launch-prefix="konsole --new-tab -e bash /home/v01d/misc/scripts/ros-debug" output="screen">
<node name="whycon" type="whycon" pkg="whycon" _launch-prefix="konsole --new-tab -e bash /home/v01d/misc/scripts/ros-debug" output="screen">
<remap from="/camera/image_raw" to="/camera/image_rect_color"/>
<param name="targets" value="2"/>
<param name="targets" value="1"/>
<param name="max_refine" value="5"/>
<param name="max_attempts" value="5"/>
<!--<param name="axis" value="$(find whycon)/axis"/>-->
</node>
</launch>
Expand Down
Loading

0 comments on commit abf7837

Please sign in to comment.