|
@@ -14,7 +14,7 @@
|
|
|
#include "utils.h"
|
|
|
#include "data_def.h"
|
|
|
#include "logger.h"
|
|
|
-using namespace cv;
|
|
|
+//using namespace cv;
|
|
|
|
|
|
namespace graft_cv{
|
|
|
|
|
@@ -50,9 +50,9 @@ void CRootStockCutPoint::clear_imginfo(){
|
|
|
|
|
|
int CRootStockCutPoint::up_point_detect(
|
|
|
ImgInfo* imginfo,
|
|
|
- Mat&cimg,
|
|
|
+ cv::Mat&cimg,
|
|
|
PositionInfo& posinfo,
|
|
|
- map<string, Mat>& img_cache
|
|
|
+ map<string, cv::Mat>& img_cache
|
|
|
)
|
|
|
{
|
|
|
// cimg --- color image, bgr
|
|
@@ -74,7 +74,7 @@ int CRootStockCutPoint::up_point_detect(
|
|
|
|
|
|
|
|
|
|
|
|
- Mat img;
|
|
|
+ cv::Mat img;
|
|
|
if(imginfo){
|
|
|
if(m_pLogger){
|
|
|
stringstream buff;
|
|
@@ -133,14 +133,14 @@ int CRootStockCutPoint::up_point_detect(
|
|
|
this->img_segment(img);
|
|
|
// image save to cache, clear first
|
|
|
img_cache.clear();
|
|
|
- img_cache.insert(make_pair<string, Mat>(m_imgId, m_grayImg.clone()));
|
|
|
+ img_cache.insert(pair<string, cv::Mat>(m_imgId, m_grayImg.clone()));
|
|
|
|
|
|
if(m_pLogger){
|
|
|
m_pLogger->DEBUG(m_imgId+" after image segment.");
|
|
|
}
|
|
|
|
|
|
if(m_cparam.image_show){
|
|
|
- destroyAllWindows();
|
|
|
+ cv::destroyAllWindows();
|
|
|
imshow_wait("rs_bin",m_binImg);
|
|
|
}
|
|
|
else{
|
|
@@ -177,9 +177,9 @@ int CRootStockCutPoint::up_point_detect(
|
|
|
}
|
|
|
|
|
|
if(m_cparam.image_show){
|
|
|
- Mat tmp = m_binImg.clone();
|
|
|
- cv::line(tmp,Point(min_idx,0), Point(min_idx,tmp.rows),Scalar(156),3);
|
|
|
- cv::line(tmp,Point(max_idx,0), Point(max_idx,tmp.rows),Scalar(156),3);
|
|
|
+ cv::Mat tmp = m_binImg.clone();
|
|
|
+ cv::line(tmp, cv::Point(min_idx,0), cv::Point(min_idx,tmp.rows), cv::Scalar(156),3);
|
|
|
+ cv::line(tmp, cv::Point(max_idx,0), cv::Point(max_idx,tmp.rows), cv::Scalar(156),3);
|
|
|
|
|
|
imshow_wait("rs_bin_x_range", tmp);
|
|
|
}
|
|
@@ -191,7 +191,7 @@ int CRootStockCutPoint::up_point_detect(
|
|
|
mat_histogram_w(m_binImg,hist_col);
|
|
|
|
|
|
if(m_cparam.image_show){
|
|
|
- Mat hist_col_img;
|
|
|
+ cv::Mat hist_col_img;
|
|
|
hist2image(hist_col,hist_col_img,1,m_cparam.image_col_grid,m_cparam.image_row_grid);
|
|
|
imshow_wait("rs_hist_col", hist_col_img);
|
|
|
}
|
|
@@ -221,10 +221,10 @@ int CRootStockCutPoint::up_point_detect(
|
|
|
}
|
|
|
|
|
|
if(m_cparam.image_show){
|
|
|
- Mat tmp_img = m_binImg.clone();
|
|
|
+ cv::Mat tmp_img = m_binImg.clone();
|
|
|
|
|
|
- line(tmp_img,Point(x0,0),Point(x0,m_binImg.rows-1),Scalar(100),2);
|
|
|
- line(tmp_img,Point(x1,0),Point(x1,m_binImg.rows-1),Scalar(100),2);
|
|
|
+ cv::line(tmp_img, cv::Point(x0,0), cv::Point(x0,m_binImg.rows-1), cv::Scalar(100),2);
|
|
|
+ cv::line(tmp_img, cv::Point(x1,0), cv::Point(x1,m_binImg.rows-1), cv::Scalar(100),2);
|
|
|
//fork right point
|
|
|
imshow_wait("rs_x_field", tmp_img);
|
|
|
}
|
|
@@ -238,7 +238,7 @@ int CRootStockCutPoint::up_point_detect(
|
|
|
}
|
|
|
|
|
|
if(m_cparam.image_show){
|
|
|
- Mat hist_row_img;
|
|
|
+ cv::Mat hist_row_img;
|
|
|
hist2image(hist_row,hist_row_img, 0,m_cparam.image_col_grid,m_cparam.image_row_grid);
|
|
|
imshow_wait("rs_hist_row", hist_row_img);
|
|
|
}
|
|
@@ -267,7 +267,7 @@ int CRootStockCutPoint::up_point_detect(
|
|
|
roi_max_y);
|
|
|
|
|
|
|
|
|
- Point fork_cent;
|
|
|
+ cv::Point fork_cent;
|
|
|
double max_radius;
|
|
|
double stem_angle;
|
|
|
get_stem_y_fork_rs_update(
|
|
@@ -322,18 +322,18 @@ int CRootStockCutPoint::up_point_detect(
|
|
|
gcv_point<int> lower_cut_pt = gcv_point<int>(-1,-1);
|
|
|
find_lower_cut_point(m_binImg,cut_pt, lower_cut_pt, m_cparam.rs_cut_angle, stem_dia);
|
|
|
if(m_cparam.image_show){
|
|
|
- Mat stem_img = m_binImg.clone();
|
|
|
- line(stem_img,Point(stem_x0,0),Point(stem_x0,stem_img.rows-1),Scalar(100),2);
|
|
|
- line(stem_img,Point(stem_x1,0),Point(stem_x1,stem_img.rows-1),Scalar(100),2);
|
|
|
+ cv::Mat stem_img = m_binImg.clone();
|
|
|
+ cv::line(stem_img, cv::Point(stem_x0,0), cv::Point(stem_x0,stem_img.rows-1), cv::Scalar(100),2);
|
|
|
+ cv::line(stem_img, cv::Point(stem_x1,0), cv::Point(stem_x1,stem_img.rows-1), cv::Scalar(100),2);
|
|
|
//fork left point
|
|
|
- circle(stem_img, Point(stem_fork_left_x,stem_fork_y),5, Scalar(128,0,128), -1, 8,0);
|
|
|
- circle(stem_img, Point(stem_fork_right_x,stem_fork_y),5, Scalar(128,0,128), -1, 8,0);
|
|
|
+ circle(stem_img, cv::Point(stem_fork_left_x,stem_fork_y),5, cv::Scalar(128,0,128), -1, 8,0);
|
|
|
+ circle(stem_img, cv::Point(stem_fork_right_x,stem_fork_y),5, cv::Scalar(128,0,128), -1, 8,0);
|
|
|
|
|
|
- Mat gray_img = m_grayImg.clone();
|
|
|
- circle(gray_img, Point(stem_fork_left_x,stem_fork_y),5, Scalar(128,0,128), -1, 8,0);
|
|
|
- circle(gray_img, Point(stem_fork_right_x,stem_fork_y),5, Scalar(128,0,128), -1, 8,0);
|
|
|
- circle(gray_img, Point((int)cut_pt.x,cut_pt.y),5, Scalar(200,0,200), -1, 8,0);
|
|
|
- circle(gray_img, Point(lower_cut_pt.x,lower_cut_pt.y),5, Scalar(200,0,200), -1, 8,0);
|
|
|
+ cv::Mat gray_img = m_grayImg.clone();
|
|
|
+ cv::circle(gray_img, cv::Point(stem_fork_left_x,stem_fork_y),5, cv::Scalar(128,0,128), -1, 8,0);
|
|
|
+ cv::circle(gray_img, cv::Point(stem_fork_right_x,stem_fork_y),5, cv::Scalar(128,0,128), -1, 8,0);
|
|
|
+ cv::circle(gray_img, cv::Point((int)cut_pt.x,cut_pt.y),5, cv::Scalar(200,0,200), -1, 8,0);
|
|
|
+ cv::circle(gray_img, cv::Point(lower_cut_pt.x,lower_cut_pt.y),5, cv::Scalar(200,0,200), -1, 8,0);
|
|
|
image_draw_line(gray_img,cut_pt.x,cut_pt.y,lower_cut_pt.x,lower_cut_pt.y);
|
|
|
imshow_wait("rs_fork_left_right_point", stem_img);
|
|
|
imshow_wait("rs_fork_left_right_point", gray_img);
|
|
@@ -402,22 +402,22 @@ int CRootStockCutPoint::up_point_detect(
|
|
|
if(m_cparam.image_return){
|
|
|
this->clear_imginfo();
|
|
|
//0) image id
|
|
|
- strcpy(posinfo.rs_img_id,m_imgId.c_str());
|
|
|
+ strcpy_s(posinfo.rs_img_id,m_imgId.c_str());
|
|
|
|
|
|
//1)
|
|
|
//stem x-range
|
|
|
- line(m_binImg,Point(stem_x0,0),Point(stem_x0,m_binImg.cols-1),Scalar(100),2);
|
|
|
- line(m_binImg,Point(stem_x1,0),Point(stem_x1,m_binImg.cols-1),Scalar(100),2);
|
|
|
+ cv::line(m_binImg, cv::Point(stem_x0,0), cv::Point(stem_x0,m_binImg.cols-1), cv::Scalar(100),2);
|
|
|
+ cv::line(m_binImg, cv::Point(stem_x1,0), cv::Point(stem_x1,m_binImg.cols-1), cv::Scalar(100),2);
|
|
|
//fork right point
|
|
|
- circle(m_binImg, Point(stem_fork_left_x,stem_fork_y),5, Scalar(128,0,128), -1, 8,0);
|
|
|
+ cv::circle(m_binImg, cv::Point(stem_fork_left_x,stem_fork_y),5, cv::Scalar(128,0,128), -1, 8,0);
|
|
|
m_pImginfoBinFork=mat2imginfo(m_binImg);
|
|
|
|
|
|
//3 cut point int gray image
|
|
|
- circle(m_grayImg, Point(stem_fork_left_x,stem_fork_y),5, Scalar(128,0,128), -1, 8,0);
|
|
|
- circle(m_grayImg, Point(stem_fork_right_x,stem_fork_y),5, Scalar(128,0,128), -1, 8,0);//v0.5.9.3 reference point
|
|
|
- circle(m_grayImg, Point(cut_pt.x,stem_fork_y),5, Scalar(128,0,128), -1, 8,0);//v0.5.9.3 reference point
|
|
|
- circle(m_grayImg, Point(cut_pt.x,stem_fork_y),2, Scalar(255,0,255), -1, 8,0);
|
|
|
- circle(m_grayImg, Point(lower_cut_pt.x,lower_cut_pt.y),5, Scalar(200,0,200), -1, 8,0);
|
|
|
+ cv::circle(m_grayImg, cv::Point(stem_fork_left_x,stem_fork_y),5, cv::Scalar(128,0,128), -1, 8,0);
|
|
|
+ cv::circle(m_grayImg, cv::Point(stem_fork_right_x,stem_fork_y),5, cv::Scalar(128,0,128), -1, 8,0);//v0.5.9.3 reference point
|
|
|
+ cv::circle(m_grayImg, cv::Point(cut_pt.x,stem_fork_y),5, cv::Scalar(128,0,128), -1, 8,0);//v0.5.9.3 reference point
|
|
|
+ cv::circle(m_grayImg, cv::Point(cut_pt.x,stem_fork_y),2, cv::Scalar(255,0,255), -1, 8,0);
|
|
|
+ cv::circle(m_grayImg, cv::Point(lower_cut_pt.x,lower_cut_pt.y),5, cv::Scalar(200,0,200), -1, 8,0);
|
|
|
image_draw_line(m_grayImg,cut_pt.x,cut_pt.y,lower_cut_pt.x,lower_cut_pt.y);
|
|
|
|
|
|
m_pImgCutPoint = mat2imginfo(m_grayImg);
|
|
@@ -484,7 +484,7 @@ void CRootStockCutPoint::get_default_cutpoint(
|
|
|
int fork_cent_x,
|
|
|
int fork_cent_y,
|
|
|
int fork_stem_dia,
|
|
|
- Point2f& cut_pt)
|
|
|
+ cv::Point2f& cut_pt)
|
|
|
{
|
|
|
gcv_point<int> start_pt(fork_cent_x,fork_cent_y);
|
|
|
gcv_point<int> lower_cut_pt = gcv_point<int>(-1,-1);
|
|
@@ -504,21 +504,21 @@ void CRootStockCutPoint::get_default_cutpoint(
|
|
|
cut_pt.y = lower_cut_pt.y;
|
|
|
}
|
|
|
}
|
|
|
-void CRootStockCutPoint::img_segment(Mat&img)
|
|
|
+void CRootStockCutPoint::img_segment(cv::Mat&img)
|
|
|
{
|
|
|
- Mat b_img;
|
|
|
+ cv::Mat b_img;
|
|
|
if(img.channels()!=1){
|
|
|
//color image ,bgr, for testing
|
|
|
- cvtColor(img,m_grayImg,COLOR_BGR2GRAY);
|
|
|
+ cvtColor(img,m_grayImg, cv::COLOR_BGR2GRAY);
|
|
|
}
|
|
|
else{
|
|
|
m_grayImg = img.clone();
|
|
|
}
|
|
|
|
|
|
- Mat kernel = getStructuringElement(
|
|
|
- MORPH_ELLIPSE,
|
|
|
- Size( 2*m_cparam.rs_morph_radius + 1, 2*m_cparam.rs_morph_radius+1 ),
|
|
|
- Point( m_cparam.rs_morph_radius, m_cparam.rs_morph_radius )
|
|
|
+ cv::Mat kernel = cv::getStructuringElement(
|
|
|
+ cv::MORPH_ELLIPSE,
|
|
|
+ cv::Size( 2*m_cparam.rs_morph_radius + 1, 2*m_cparam.rs_morph_radius+1 ),
|
|
|
+ cv::Point( m_cparam.rs_morph_radius, m_cparam.rs_morph_radius )
|
|
|
);
|
|
|
/*
|
|
|
morphologyEx(
|
|
@@ -530,14 +530,14 @@ void CRootStockCutPoint::img_segment(Mat&img)
|
|
|
m_cparam.rs_morph_iteration_gray
|
|
|
);*/
|
|
|
|
|
|
- double th = threshold(m_grayImg, b_img, 255, 255,THRESH_OTSU);
|
|
|
+ double th = threshold(m_grayImg, b_img, 255, 255, cv::THRESH_OTSU);
|
|
|
|
|
|
morphologyEx(
|
|
|
b_img,
|
|
|
m_binImg,
|
|
|
- MORPH_CLOSE,
|
|
|
+ cv::MORPH_CLOSE,
|
|
|
kernel,
|
|
|
- Point(-1,-1),
|
|
|
+ cv::Point(-1,-1),
|
|
|
m_cparam.rs_morph_iteration
|
|
|
);
|
|
|
|
|
@@ -547,14 +547,14 @@ void CRootStockCutPoint::img_segment(Mat&img)
|
|
|
int CRootStockCutPoint::get_optimal_corner(
|
|
|
int ref_x,
|
|
|
int ref_y,
|
|
|
- std::vector<Point2f>& corners,
|
|
|
+ std::vector<cv::Point2f>& corners,
|
|
|
int stem_dia,
|
|
|
double cand_corner_box_width_ratio,
|
|
|
double cand_corner_box_xoffset_ratio,
|
|
|
double opt_corner_xoffset_ratio,
|
|
|
double opt_corner_yoffset_ratio,
|
|
|
double corner_mask_radius_ratio,
|
|
|
- Point2f& cut_pt)
|
|
|
+ cv::Point2f& cut_pt)
|
|
|
{
|
|
|
|
|
|
/*"""
|
|
@@ -580,12 +580,12 @@ int CRootStockCutPoint::get_optimal_corner(
|
|
|
int by = ref_y - cand_corner_box_window;
|
|
|
|
|
|
roi_box<int> candidate_box = roi_box<int>(bx,by,cand_corner_box_window,cand_corner_box_window);
|
|
|
- vector<Point2f>cand_pts;
|
|
|
+ vector<cv::Point2f>cand_pts;
|
|
|
for(size_t i=0; i<corners.size(); ++i){
|
|
|
int pt_x = corners[i].x;
|
|
|
int pt_y = corners[i].y;
|
|
|
if (candidate_box.isInBox(pt_x,pt_y)){
|
|
|
- Point2f pt;
|
|
|
+ cv::Point2f pt;
|
|
|
pt.x=corners[i].x;
|
|
|
pt.y=corners[i].y;
|
|
|
cand_pts.push_back(pt);
|
|
@@ -628,7 +628,7 @@ int CRootStockCutPoint::get_optimal_corner(
|
|
|
}
|
|
|
|
|
|
void CRootStockCutPoint::corner_magnificence(
|
|
|
- const vector<Point2f>& cand_pts,
|
|
|
+ const vector<cv::Point2f>& cand_pts,
|
|
|
int stem_dia,
|
|
|
double corner_mask_radius_ratio,
|
|
|
vector<double>& scores
|
|
@@ -664,8 +664,8 @@ void CRootStockCutPoint::corner_magnificence(
|
|
|
|
|
|
double CRootStockCutPoint::get_cut_edge_length
|
|
|
(
|
|
|
- Mat& bin_img,
|
|
|
- Mat& edge_img,
|
|
|
+ cv::Mat& bin_img,
|
|
|
+ cv::Mat& edge_img,
|
|
|
gcv_point<int>& start_pt, //up cut point
|
|
|
gcv_point<int>& lower_cut_pt,//output
|
|
|
gcv_point<int>& root_pt,//output
|
|
@@ -697,7 +697,7 @@ double CRootStockCutPoint::get_cut_edge_length
|
|
|
}
|
|
|
|
|
|
void CRootStockCutPoint::find_lower_cut_point(
|
|
|
- Mat& bin_img,
|
|
|
+ cv::Mat& bin_img,
|
|
|
gcv_point<int>&start_pt,
|
|
|
gcv_point<int>&end_pt,//output
|
|
|
double cut_angle,
|
|
@@ -763,7 +763,7 @@ double CRootStockCutPoint::get_cut_edge_length
|
|
|
}
|
|
|
}
|
|
|
double CRootStockCutPoint::calculate_edge_length(
|
|
|
- Mat& edge_img,
|
|
|
+ cv::Mat& edge_img,
|
|
|
gcv_point<int>&lower_cut_pt,
|
|
|
gcv_point<int>&root_pt,//output
|
|
|
int y_max,
|
|
@@ -892,7 +892,7 @@ double CRootStockCutPoint::get_cut_edge_length
|
|
|
}
|
|
|
|
|
|
void CRootStockCutPoint::find_upper_cut_point_reid(
|
|
|
- Mat& edge_img,
|
|
|
+ cv::Mat& edge_img,
|
|
|
gcv_point<int>&start_pt,
|
|
|
gcv_point<int>&end_pt,//output
|
|
|
double curve_length
|