|
@@ -19,6 +19,7 @@
|
|
|
#include "optimal_angle.h"
|
|
|
#include "cut_point_sc.h"
|
|
|
#include "cut_point_rs.h"
|
|
|
+#include "cut_point_rs_reid.h"
|
|
|
#include "graft_cv_api.h"
|
|
|
#include "logger.h"
|
|
|
|
|
@@ -680,149 +681,149 @@ void test_sc_cut_point_simulate()
|
|
|
}
|
|
|
|
|
|
};
|
|
|
-void test_rs_cut_point(){
|
|
|
- ConfigParam cp;
|
|
|
- test_init_cp(cp);
|
|
|
-
|
|
|
- namedWindow("pic", CV_WINDOW_NORMAL);
|
|
|
- CRootStockCutPoint rscp(cp);
|
|
|
- ofstream g_logger_ofs;
|
|
|
- CGcvLogger g_logger = CGcvLogger(
|
|
|
- g_logger_ofs,
|
|
|
- CGcvLogger::file_and_terminal,
|
|
|
- CGcvLogger::warning,
|
|
|
- "./gcv_debug.log");
|
|
|
- clock_t t;
|
|
|
- for(int i=4;i<193;++i){
|
|
|
- //if (/*i !=11 &&*/ D:\private\grafting_robot\samples\rs_cut_simulate
|
|
|
- // i !=32 &&
|
|
|
- // i !=48 &&
|
|
|
- // i != 49 &&
|
|
|
- // i != 53 &&
|
|
|
- // i != 103 &&
|
|
|
- // i != 104 &&
|
|
|
- // i != 106 &&
|
|
|
- // i != 110 &&
|
|
|
- // i != 125 &&
|
|
|
- // i !=182 &&
|
|
|
- // i != 187 &&
|
|
|
- // i != 191)
|
|
|
- //{
|
|
|
- // continue;
|
|
|
- //}
|
|
|
-
|
|
|
- stringstream buff;
|
|
|
- buff<<setw(3) << setfill('0') << i;
|
|
|
- cout<<buff.str()<<endl;
|
|
|
-
|
|
|
- //string img_file= "E:/projects/grafting_robots/samples/rootstlock_pumpkin/"+buff.str()+"/6.jpg";
|
|
|
- //string img_file= "D:/private/grafting_robot/samples/rootstlock_pumpkin/"+buff.str()+"/6.jpg";
|
|
|
- string img_file= "D:/grafting_robot/samples/rootstlock_pumpkin/"+buff.str()+"/6.jpg";
|
|
|
-
|
|
|
-
|
|
|
- Mat img = imread(img_file,CV_LOAD_IMAGE_COLOR );
|
|
|
- //ImgInfo* imginfo = mat2imginfo(img);
|
|
|
- PositionInfo pinfo;
|
|
|
- try{
|
|
|
- t = clock();
|
|
|
- int fold_y = rscp.up_point_detect(0,img, pinfo);
|
|
|
- t = clock() - t;
|
|
|
- }
|
|
|
- catch(exception &err){
|
|
|
- cout<<err.what()<<endl;
|
|
|
- }
|
|
|
- catch(string msg){
|
|
|
- cout<<msg<<endl;
|
|
|
- cout<<img_file<<endl<<endl;
|
|
|
- g_logger.ERRORINFO(msg);
|
|
|
- g_logger.INFO(buff.str());
|
|
|
- }
|
|
|
- catch(...){
|
|
|
- cout<<"============================================unknown error"<<endl;
|
|
|
- cout<<img_file<<endl<<endl;
|
|
|
- }
|
|
|
- //cv::line(img,Point(0,fold_y), Point(img.cols,fold_y),Scalar(0,0,255));
|
|
|
-
|
|
|
- imshow("pic", img);
|
|
|
- waitKey(1);
|
|
|
-
|
|
|
- cout<<"time(seconds): "<<((float)t)/CLOCKS_PER_SEC<<endl;
|
|
|
-
|
|
|
- cout<<"\n\n";
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-};
|
|
|
-void test_rs_cut_point_simulate(){
|
|
|
- ConfigParam cp;
|
|
|
- test_init_cp(cp);
|
|
|
- cp.image_show=true;
|
|
|
- cp.image_return = true;
|
|
|
-
|
|
|
- namedWindow("pic", CV_WINDOW_NORMAL);
|
|
|
- CRootStockCutPoint rscp(cp,&g_logger);
|
|
|
- /*ofstream g_logger_ofs;
|
|
|
- Logger g_logger = Logger(
|
|
|
- g_logger_ofs,
|
|
|
- Logger::file_and_terminal,
|
|
|
- Logger::warning,
|
|
|
- "./gcv_debug.log");*/
|
|
|
-
|
|
|
- //string src_folder = "D:\\private\\grafting_robot\\samples\\rs_cut_simulate";
|
|
|
- //string src_folder = "D:\\private\\grafting_robot\\samples\\rootstock_hold_down";
|
|
|
- //string src_folder = "D:\\grafting_robot\\samples\\rootstock_hold_down";
|
|
|
- string src_folder = "D:\\private\\grafting_robot\\samples\\20211215\\rootstock";
|
|
|
- vector<cv::String>filenames;
|
|
|
- cv::glob(src_folder, filenames);
|
|
|
-
|
|
|
- clock_t t;
|
|
|
- for(int i=0;i<filenames.size();++i){
|
|
|
-
|
|
|
- string img_file= filenames[i];
|
|
|
-
|
|
|
- Mat img = imread(img_file,CV_LOAD_IMAGE_COLOR );
|
|
|
- //ImgInfo* imginfo = mat2imginfo(img);
|
|
|
- PositionInfo pinfo;
|
|
|
- memset(&pinfo,0,sizeof(PositionInfo));
|
|
|
- try{
|
|
|
- t = clock();
|
|
|
- int fold_y = rscp.up_point_detect(0,img, pinfo);
|
|
|
- t = clock() - t;
|
|
|
- }
|
|
|
- catch(exception &err){
|
|
|
- cout<<err.what()<<endl;
|
|
|
- }
|
|
|
- catch(string msg){
|
|
|
- cout<<msg<<endl;
|
|
|
- cout<<img_file<<endl<<endl;
|
|
|
- g_logger.ERRORINFO(msg);
|
|
|
- g_logger.INFO(img_file);
|
|
|
- }
|
|
|
- catch(...){
|
|
|
- cout<<"============================================unknown error"<<endl;
|
|
|
- cout<<img_file<<endl<<endl;
|
|
|
- }
|
|
|
- //cv::line(img,Point(0,fold_y), Point(img.cols,fold_y),Scalar(0,0,255));
|
|
|
-
|
|
|
- imshow("pic", img);
|
|
|
- waitKey(1);
|
|
|
-
|
|
|
- //show return images
|
|
|
- for (int i =0;i<5;++i){
|
|
|
- if (!pinfo.pp_images[i]){continue;}
|
|
|
- Mat tmp_img = imginfo2mat(pinfo.pp_images[i]);
|
|
|
- imshow("pic", tmp_img);
|
|
|
- waitKey(-1);
|
|
|
- }
|
|
|
- cout<<"time(seconds): "<<((float)t)/CLOCKS_PER_SEC<<endl;
|
|
|
-
|
|
|
- cout<<"\n\n";
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-};
|
|
|
+//void test_rs_cut_point(){
|
|
|
+// ConfigParam cp;
|
|
|
+// test_init_cp(cp);
|
|
|
+//
|
|
|
+// namedWindow("pic", CV_WINDOW_NORMAL);
|
|
|
+// CRootStockCutPoint rscp(cp);
|
|
|
+// ofstream g_logger_ofs;
|
|
|
+// CGcvLogger g_logger = CGcvLogger(
|
|
|
+// g_logger_ofs,
|
|
|
+// CGcvLogger::file_and_terminal,
|
|
|
+// CGcvLogger::warning,
|
|
|
+// "./gcv_debug.log");
|
|
|
+// clock_t t;
|
|
|
+// for(int i=4;i<193;++i){
|
|
|
+// //if (/*i !=11 &&*/ D:\private\grafting_robot\samples\rs_cut_simulate
|
|
|
+// // i !=32 &&
|
|
|
+// // i !=48 &&
|
|
|
+// // i != 49 &&
|
|
|
+// // i != 53 &&
|
|
|
+// // i != 103 &&
|
|
|
+// // i != 104 &&
|
|
|
+// // i != 106 &&
|
|
|
+// // i != 110 &&
|
|
|
+// // i != 125 &&
|
|
|
+// // i !=182 &&
|
|
|
+// // i != 187 &&
|
|
|
+// // i != 191)
|
|
|
+// //{
|
|
|
+// // continue;
|
|
|
+// //}
|
|
|
+//
|
|
|
+// stringstream buff;
|
|
|
+// buff<<setw(3) << setfill('0') << i;
|
|
|
+// cout<<buff.str()<<endl;
|
|
|
+//
|
|
|
+// //string img_file= "E:/projects/grafting_robots/samples/rootstlock_pumpkin/"+buff.str()+"/6.jpg";
|
|
|
+// //string img_file= "D:/private/grafting_robot/samples/rootstlock_pumpkin/"+buff.str()+"/6.jpg";
|
|
|
+// string img_file= "D:/grafting_robot/samples/rootstlock_pumpkin/"+buff.str()+"/6.jpg";
|
|
|
+//
|
|
|
+//
|
|
|
+// Mat img = imread(img_file,CV_LOAD_IMAGE_COLOR );
|
|
|
+// //ImgInfo* imginfo = mat2imginfo(img);
|
|
|
+// PositionInfo pinfo;
|
|
|
+// try{
|
|
|
+// t = clock();
|
|
|
+// int fold_y = rscp.up_point_detect(0,img, pinfo);
|
|
|
+// t = clock() - t;
|
|
|
+// }
|
|
|
+// catch(exception &err){
|
|
|
+// cout<<err.what()<<endl;
|
|
|
+// }
|
|
|
+// catch(string msg){
|
|
|
+// cout<<msg<<endl;
|
|
|
+// cout<<img_file<<endl<<endl;
|
|
|
+// g_logger.ERRORINFO(msg);
|
|
|
+// g_logger.INFO(buff.str());
|
|
|
+// }
|
|
|
+// catch(...){
|
|
|
+// cout<<"============================================unknown error"<<endl;
|
|
|
+// cout<<img_file<<endl<<endl;
|
|
|
+// }
|
|
|
+// //cv::line(img,Point(0,fold_y), Point(img.cols,fold_y),Scalar(0,0,255));
|
|
|
+//
|
|
|
+// imshow("pic", img);
|
|
|
+// waitKey(1);
|
|
|
+//
|
|
|
+// cout<<"time(seconds): "<<((float)t)/CLOCKS_PER_SEC<<endl;
|
|
|
+//
|
|
|
+// cout<<"\n\n";
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//};
|
|
|
+//void test_rs_cut_point_simulate(){
|
|
|
+// ConfigParam cp;
|
|
|
+// test_init_cp(cp);
|
|
|
+// cp.image_show=true;
|
|
|
+// cp.image_return = true;
|
|
|
+//
|
|
|
+// namedWindow("pic", CV_WINDOW_NORMAL);
|
|
|
+// CRootStockCutPoint rscp(cp,&g_logger);
|
|
|
+// /*ofstream g_logger_ofs;
|
|
|
+// Logger g_logger = Logger(
|
|
|
+// g_logger_ofs,
|
|
|
+// Logger::file_and_terminal,
|
|
|
+// Logger::warning,
|
|
|
+// "./gcv_debug.log");*/
|
|
|
+//
|
|
|
+// //string src_folder = "D:\\private\\grafting_robot\\samples\\rs_cut_simulate";
|
|
|
+// //string src_folder = "D:\\private\\grafting_robot\\samples\\rootstock_hold_down";
|
|
|
+// //string src_folder = "D:\\grafting_robot\\samples\\rootstock_hold_down";
|
|
|
+// string src_folder = "D:\\private\\grafting_robot\\samples\\20211215\\rootstock";
|
|
|
+// vector<cv::String>filenames;
|
|
|
+// cv::glob(src_folder, filenames);
|
|
|
+//
|
|
|
+// clock_t t;
|
|
|
+// for(int i=0;i<filenames.size();++i){
|
|
|
+//
|
|
|
+// string img_file= filenames[i];
|
|
|
+//
|
|
|
+// Mat img = imread(img_file,CV_LOAD_IMAGE_COLOR );
|
|
|
+// //ImgInfo* imginfo = mat2imginfo(img);
|
|
|
+// PositionInfo pinfo;
|
|
|
+// memset(&pinfo,0,sizeof(PositionInfo));
|
|
|
+// try{
|
|
|
+// t = clock();
|
|
|
+// int fold_y = rscp.up_point_detect(0,img, pinfo);
|
|
|
+// t = clock() - t;
|
|
|
+// }
|
|
|
+// catch(exception &err){
|
|
|
+// cout<<err.what()<<endl;
|
|
|
+// }
|
|
|
+// catch(string msg){
|
|
|
+// cout<<msg<<endl;
|
|
|
+// cout<<img_file<<endl<<endl;
|
|
|
+// g_logger.ERRORINFO(msg);
|
|
|
+// g_logger.INFO(img_file);
|
|
|
+// }
|
|
|
+// catch(...){
|
|
|
+// cout<<"============================================unknown error"<<endl;
|
|
|
+// cout<<img_file<<endl<<endl;
|
|
|
+// }
|
|
|
+// //cv::line(img,Point(0,fold_y), Point(img.cols,fold_y),Scalar(0,0,255));
|
|
|
+//
|
|
|
+// imshow("pic", img);
|
|
|
+// waitKey(1);
|
|
|
+//
|
|
|
+// //show return images
|
|
|
+// for (int i =0;i<5;++i){
|
|
|
+// if (!pinfo.pp_images[i]){continue;}
|
|
|
+// Mat tmp_img = imginfo2mat(pinfo.pp_images[i]);
|
|
|
+// imshow("pic", tmp_img);
|
|
|
+// waitKey(-1);
|
|
|
+// }
|
|
|
+// cout<<"time(seconds): "<<((float)t)/CLOCKS_PER_SEC<<endl;
|
|
|
+//
|
|
|
+// cout<<"\n\n";
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//};
|
|
|
//void test_rs_cp_reid()
|
|
|
//{
|
|
|
// ConfigParam cp;
|
|
@@ -1249,7 +1250,7 @@ void test_oa_batch(){
|
|
|
//cv_set_param(cp_ret);
|
|
|
//namedWindow("pic", CV_WINDOW_NORMAL);
|
|
|
|
|
|
- string work_folder = "E:\\projects\\grafting_robot\\samples\\20220223\\rotate";
|
|
|
+ string work_folder = "E:\\projects\\grafting_robot\\samples\\20220831\\top";
|
|
|
//string work_folder = "D:\\private\\grafting_robot\\samples\\20220220\\rotate";
|
|
|
vector<cv::String>filenames;
|
|
|
cv::glob(work_folder, filenames);
|
|
@@ -1258,20 +1259,22 @@ void test_oa_batch(){
|
|
|
if(filename.find(".rst_")!=string::npos){continue;}
|
|
|
//if(filename.find("\\249.bmp")==string::npos){continue;}
|
|
|
PositionInfo posinfo;
|
|
|
- Mat img = imread(filename, cv::IMREAD_GRAYSCALE);
|
|
|
+ Mat img = imread(filename, cv::IMREAD_COLOR);//IMREAD_GRAYSCALE
|
|
|
if(img.empty()){continue;}
|
|
|
- image_set_top(img,20,8);
|
|
|
- ImgInfo* imginfo = mat2imginfo(img);
|
|
|
+ //image_set_top(img,20,8);
|
|
|
+ //ImgInfo* imginfo = mat2imginfo(img);
|
|
|
+ ImgInfo* imginfo = (ImgInfo*)(&img);
|
|
|
//imginfo->angle = j*30;
|
|
|
try{
|
|
|
- rs_oa_init();
|
|
|
- rs_oa_append(imginfo, posinfo);
|
|
|
-
|
|
|
+ //rs_oa_init();
|
|
|
+ //rs_oa_append(imginfo, posinfo);
|
|
|
+ rs_oa_get_result(imginfo, posinfo);
|
|
|
+
|
|
|
for (int i =0;i<5;++i){
|
|
|
if (!posinfo.pp_images[i]){continue;}
|
|
|
Mat tmp_img = imginfo2mat(posinfo.pp_images[i]);
|
|
|
- /*imshow("pic", tmp_img);
|
|
|
- waitKey(-1);*/
|
|
|
+ imshow("pic", tmp_img);
|
|
|
+ waitKey(-1);
|
|
|
|
|
|
stringstream bbu;
|
|
|
bbu<<filename<<".rst_"<<i<<".jpg";
|
|
@@ -1283,7 +1286,101 @@ void test_oa_batch(){
|
|
|
std::cout<<"some error ..."<<endl;
|
|
|
}
|
|
|
|
|
|
- imginfo_release(&imginfo);
|
|
|
+ //imginfo_release(&imginfo);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ cv_release();
|
|
|
+}
|
|
|
+void test_rs_batch_reid(){
|
|
|
+
|
|
|
+ // 0 version;
|
|
|
+ char* ver = new char[10];
|
|
|
+ get_version(ver);
|
|
|
+ cout<<ver<<endl;
|
|
|
+ delete [] ver;
|
|
|
+ ver=0;
|
|
|
+
|
|
|
+ //2 cv_init()
|
|
|
+ //char *conf_file = "D:\\private\\grafting_robot\\cpp_code\\demo\\demo\\gcv_conf.yml";
|
|
|
+ //char *conf_file = "D:\\grafting_robot\\cpp_code\\demo\\demo\\gcv_conf.yml";
|
|
|
+ char *conf_file = "E:\\projects\\grafting_robot\\cpp_code\\demo\\demo\\gcv_conf.yml";
|
|
|
+ int rst = cv_init(conf_file);
|
|
|
+ ConfigParam cp_ret;
|
|
|
+ cv_get_param(cp_ret);
|
|
|
+ cv_set_loglevel(0);
|
|
|
+ cv_init_image_saver();
|
|
|
+
|
|
|
+ //cp_ret.image_show=true;
|
|
|
+ //cv_set_param(cp_ret);
|
|
|
+ //namedWindow("pic", CV_WINDOW_NORMAL);
|
|
|
+
|
|
|
+ string work_folder = "E:\\projects\\grafting_robot\\samples\\20221003";
|
|
|
+ //string work_folder = "D:\\private\\grafting_robot\\samples\\20220220\\rotate";
|
|
|
+ vector<cv::String>filenames;
|
|
|
+ cv::glob(work_folder, filenames);
|
|
|
+ map<string, Mat> img_cache;
|
|
|
+ for(size_t idx=0; idx<filenames.size();++idx){
|
|
|
+
|
|
|
+ if(idx %2 ==0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ img_cache.clear();
|
|
|
+
|
|
|
+ string filename_pre = filenames[idx-1];
|
|
|
+ string filename = filenames[idx];
|
|
|
+ if(filename_pre.find(".rst_")!=string::npos){continue;}
|
|
|
+ if(filename.find(".rst_")!=string::npos){continue;}
|
|
|
+ //if(filename.find("\\249.bmp")==string::npos){continue;}
|
|
|
+ PositionInfo posinfo;
|
|
|
+ memset(&posinfo,0,sizeof(PositionInfo));
|
|
|
+ Mat img_pre = imread(filename_pre, cv::IMREAD_GRAYSCALE);
|
|
|
+ Mat img = imread(filename, cv::IMREAD_GRAYSCALE);//IMREAD_GRAYSCALE IMREAD_COLOR
|
|
|
+ if(img_pre.empty() || img.empty()){continue;}
|
|
|
+ //image_set_top(img,20,8);
|
|
|
+ //ImgInfo* imginfo = mat2imginfo(img);
|
|
|
+ //ImgInfo* imginfo = (ImgInfo*)(&img);
|
|
|
+ //imginfo->angle = j*30;
|
|
|
+
|
|
|
+ //for DEBUG
|
|
|
+ int m_width = img.cols/2;
|
|
|
+ int m_height = img.rows/2;
|
|
|
+ cv::resize(img, img, cv::Size(m_width,m_height ));
|
|
|
+ cv::resize(img_pre, img_pre, cv::Size(m_width,m_height ));
|
|
|
+ //for DEBUG end
|
|
|
+
|
|
|
+ string imgid_pre("1");
|
|
|
+ img_cache.insert(make_pair<string, Mat>(imgid_pre,img_pre ));
|
|
|
+
|
|
|
+ try{
|
|
|
+ //rs_oa_init();
|
|
|
+ //rs_oa_append(imginfo, posinfo);
|
|
|
+
|
|
|
+ CRootStockCutPointReid rs_reid(cp_ret,0);
|
|
|
+ rs_reid.cut_point_reid(NULL,
|
|
|
+ img,
|
|
|
+ imgid_pre.c_str(),
|
|
|
+ posinfo,
|
|
|
+ img_cache);
|
|
|
+
|
|
|
+ for (int i =0;i<5;++i){
|
|
|
+ if (!posinfo.pp_images[i]){continue;}
|
|
|
+ Mat tmp_img = imginfo2mat(posinfo.pp_images[i]);
|
|
|
+ imshow("pic", tmp_img);
|
|
|
+ waitKey(-1);
|
|
|
+
|
|
|
+ //stringstream bbu;
|
|
|
+ //bbu<<filename<<".rst_"<<i<<".jpg";
|
|
|
+ //string fnn = bbu.str();
|
|
|
+ //cv::imwrite(fnn,tmp_img);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(...){
|
|
|
+ std::cout<<"some error ..."<<endl;
|
|
|
+ }
|
|
|
+
|
|
|
+ //imginfo_release(&imginfo);
|
|
|
|
|
|
|
|
|
|
|
@@ -1509,8 +1606,9 @@ int _tmain(int argc, _TCHAR* argv[])
|
|
|
//api test
|
|
|
//test_api_scion();
|
|
|
//test_sc_batch();
|
|
|
- test_rs_batch();
|
|
|
+ //test_rs_batch();
|
|
|
//test_rs_batch_camera();
|
|
|
+ test_rs_batch_reid();
|
|
|
//test_oa_batch();
|
|
|
//test_api_batch();
|
|
|
//drawline_rs();
|