Skip to content

Commit

Permalink
some more processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Chao Qu committed Sep 11, 2014
1 parent e542a5f commit e93f816
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
Binary file modified calib/circles_grid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion calib/draw_circles_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
fig = plt.gcf()
n_cols = 5
n_rows = 4
r = 0.2
r = 0.1
for x in range(0, n_cols):
for y in range(0, n_rows):
circle = plt.Circle((x, y), r, color='k')
Expand Down
8 changes: 8 additions & 0 deletions cfg/CalibProcDyn.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ gen = ParameterGenerator()

# name / type / level / description / default / min / max
# Flir A35 has a maximum resolution of 320 x 256
gen.add("sigma", double_t, 0,
"gaussian sigma", 1, 1, 20)
gen.add("min_area", double_t, 0,
"contour min area", 40, 1, 1000)
gen.add("max_area", double_t, 0,
"contour max area", 200, 100, 10000)
gen.add("thresh_window", int_t, 0,
"adaptive threshold window size", 11, 3, 100)
gen.add("erosion_size", int_t, 0,
"erosion size", 1, 1, 10)
size_enum = gen.enum([gen.const("mean", int_t, 0, "Adaptive thresh mean"),
gen.const("gaussian", int_t, 1, "Adaptive thresh gaussian")],
"Adaptive thresh type ")
Expand Down
48 changes: 32 additions & 16 deletions src/calib_proc/calib_proc_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,55 @@ void CalibProcNode::ConfigCb(CalibProcDynConfig &config, int level) {
if (!(config.thresh_window % 2)) {
config.thresh_window += 1;
}
if (config.min_area > config.max_area) {
config.max_area = config.min_area + 1;
}
config_ = config;
}

void CalibProcNode::ImageCb(const sensor_msgs::ImageConstPtr &image_msg) {
cv::Mat image = cv_bridge::toCvCopy(image_msg, image_msg->encoding)->image;
// cv::imshow("image", image);

cv::Mat inverted;
cv::bitwise_not(image, inverted);
// cv::imshow("inverted", inverted);

/*
// Threshold
cv::Mat thresh;
cv::adaptiveThreshold(image, thresh, 255, config_.thresh_type,
cv::THRESH_BINARY, config_.thresh_window, 0);
cv::imshow("thresh", thresh);
*/

/*
std::vector<std::vector<cv::Point>> contours;
cv::findContours(raw, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
// Gaussian blur
cv::Mat gauss;
cv::GaussianBlur(thresh, gauss, cv::Size(), config_.sigma, config_.sigma,
cv::BORDER_DEFAULT);
cv::imshow("gauss", gauss);

// Erosion
cv::Mat eroded;
int erosion_size = config_.erosion_size;
cv::Mat element = cv::getStructuringElement(
cv::MORPH_RECT, cv::Size(2 * erosion_size + 1, 2 * erosion_size + 1),
cv::Point(erosion_size, erosion_size));
cv::erode(thresh, eroded, element);
cv::imshow("erosion", eroded);

cv::Mat contour_image;
cv::cvtColor(raw, contour_image, CV_GRAY2BGR);
for (size_t i = 0; i < contours.size(); ++i) {
cv::drawContours(contour_image, contours, i, cv::Scalar(255, 0, 0), 2, 8);
}
cv::imshow("contour", contour_image);
*/
// Contour
std::vector<std::vector<cv::Point>> contours;
cv::findContours(eroded, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);

cv::Mat ctr_image;
cv::cvtColor(image, ctr_image, CV_GRAY2BGR);
for (size_t i = 0; i < contours.size(); ++i) {
double area = cv::contourArea(contours[i]);
if (area > config_.min_area && area < config_.max_area) {
cv::drawContours(ctr_image, contours, i, cv::Scalar(255, 0, 0), 2, 8);
}
}
cv::imshow("contour", ctr_image);

// Detect circles grid
cv::Mat display;
DetectAndDrawCriclesGrid(inverted, cv::Size(4, 5), display);
DetectAndDrawCriclesGrid(inverted, cv::Size(5, 4), display);

cv::Mat calib(inverted);

Expand Down

0 comments on commit e93f816

Please sign in to comment.