|
@@ -50,7 +50,7 @@ void test_init_cp(ConfigParam&cp){
|
|
cp.oa_y_flip=true;
|
|
cp.oa_y_flip=true;
|
|
cp.oa_morph_radius = 1;
|
|
cp.oa_morph_radius = 1;
|
|
cp.oa_morph_iteration=2;
|
|
cp.oa_morph_iteration=2;
|
|
- cp.oa_min_hist_value=10;
|
|
|
|
|
|
+ /*cp.oa_min_hist_value=10;
|
|
cp.oa_morph_radius_base = 1;
|
|
cp.oa_morph_radius_base = 1;
|
|
cp.oa_morph_iteration_base=2;
|
|
cp.oa_morph_iteration_base=2;
|
|
cp.oa_min_hist_value_base=10;
|
|
cp.oa_min_hist_value_base=10;
|
|
@@ -62,7 +62,7 @@ void test_init_cp(ConfigParam&cp){
|
|
cp.oa_stem_fork_y_min=10;
|
|
cp.oa_stem_fork_y_min=10;
|
|
cp.oa_stem_dia_mp=0.9;
|
|
cp.oa_stem_dia_mp=0.9;
|
|
cp.oa_clip_y_min=245;
|
|
cp.oa_clip_y_min=245;
|
|
- cp.oa_clip_y_max = 355;
|
|
|
|
|
|
+ cp.oa_clip_y_max = 355;*/
|
|
|
|
|
|
cp.rs_y_flip=false;
|
|
cp.rs_y_flip=false;
|
|
cp.rs_col_th_ratio= 0.7;
|
|
cp.rs_col_th_ratio= 0.7;
|
|
@@ -158,7 +158,7 @@ void test_camconfig_read()
|
|
ConfigParam cp0, cp1;
|
|
ConfigParam cp0, cp1;
|
|
memset(&cp1, 0, sizeof(ConfigParam));
|
|
memset(&cp1, 0, sizeof(ConfigParam));
|
|
cp0 = cp1;
|
|
cp0 = cp1;
|
|
- cp0.oa_min_hist_value = 100;
|
|
|
|
|
|
+ //cp0.oa_min_hist_value = 100;
|
|
cout<<&cp0<<endl;
|
|
cout<<&cp0<<endl;
|
|
|
|
|
|
CGCvConfig cam0 = CGCvConfig();
|
|
CGCvConfig cam0 = CGCvConfig();
|
|
@@ -206,309 +206,309 @@ void test_anglefit_readdata(vector<map<int,int>>& data){
|
|
ifs.close();
|
|
ifs.close();
|
|
}
|
|
}
|
|
};
|
|
};
|
|
-void test_anglefit()
|
|
|
|
-{
|
|
|
|
- ConfigParam cp;
|
|
|
|
- COptimalAnglePart opa = COptimalAnglePart(cp);
|
|
|
|
- vector<map<int,int>> data;
|
|
|
|
- //test_anglefit_readdata(data);
|
|
|
|
- map<int,int>tmp;
|
|
|
|
- /*tmp.insert(make_pair<int,int>(0,216));
|
|
|
|
- tmp.insert(make_pair<int,int>(30,189));
|
|
|
|
- tmp.insert(make_pair<int,int>(60,112));
|
|
|
|
- tmp.insert(make_pair<int,int>(90,151));
|
|
|
|
- tmp.insert(make_pair<int,int>(120,188));*/
|
|
|
|
-
|
|
|
|
- tmp.insert(make_pair<int,int>(0,315));
|
|
|
|
- tmp.insert(make_pair<int,int>(30,270));
|
|
|
|
- tmp.insert(make_pair<int,int>(60,218));
|
|
|
|
- tmp.insert(make_pair<int,int>(90,141));
|
|
|
|
- tmp.insert(make_pair<int,int>(120,127));
|
|
|
|
-
|
|
|
|
- data.push_back(tmp);
|
|
|
|
- for(vector<map<int,int>>::iterator it = data.begin(); it!=data.end(); ++it){
|
|
|
|
-
|
|
|
|
- map<int,int>& an2width = *it;
|
|
|
|
- double oa = opa.angle_fit(an2width);
|
|
|
|
- cout<<oa<<endl;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-};
|
|
|
|
-void test_optimal_angle(){
|
|
|
|
- //string folder = "E:\\projects\\grafting_robots\\py_code\\tmp";
|
|
|
|
- string folder = "D:\\grafting_robot\\samples\\tmp";
|
|
|
|
- namedWindow("pic", 0);
|
|
|
|
- vector<cv::String>filenames;
|
|
|
|
- ConfigParam cp;
|
|
|
|
- test_init_cp(cp);
|
|
|
|
- /*cp.oa_min_hist_value=10;
|
|
|
|
- cp.oa_morph_iteration=2;
|
|
|
|
- cp.oa_morph_radius = 1;*/
|
|
|
|
- COptimalAngle opa(cp);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- for(int i = 1;i<=5;++i){
|
|
|
|
- for(int j = 0;j<=1;++j){
|
|
|
|
- ostringstream ostr;
|
|
|
|
- ostr<<i<<j;
|
|
|
|
- string subfold = ostr.str();
|
|
|
|
- string src_folder = folder+"\\p"+subfold;
|
|
|
|
-
|
|
|
|
- cv::glob(src_folder, filenames);
|
|
|
|
- opa.reset();
|
|
|
|
-
|
|
|
|
- PositionInfo posinfo;
|
|
|
|
-
|
|
|
|
- clock_t t,t0;
|
|
|
|
- t = clock();
|
|
|
|
- for(size_t idx=0; idx<filenames.size();++idx){
|
|
|
|
- //cout<<filenames[idx]<<endl;
|
|
|
|
- size_t found0 = filenames[idx].rfind("\\");
|
|
|
|
- size_t found1 = filenames[idx].rfind(".");
|
|
|
|
- int an = stoi(filenames[idx].substr(found0+1, found1-found0))*20;
|
|
|
|
- if(an >=200){
|
|
|
|
- an-=200;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Mat img = imread(filenames[idx], cv::IMREAD_GRAYSCALE);
|
|
|
|
- ImgInfo* imginfo = mat2imginfo(img);
|
|
|
|
- imginfo->angle = an;
|
|
|
|
- int obj_width=0;
|
|
|
|
- try{
|
|
|
|
- t0 = clock();
|
|
|
|
- obj_width = opa.append(imginfo,posinfo);
|
|
|
|
- t0 = clock() - t0;
|
|
|
|
-
|
|
|
|
- imginfo_release(&imginfo);
|
|
|
|
- }
|
|
|
|
- catch(int i)
|
|
|
|
- {
|
|
|
|
- cout<<"i= "<<i<<"异常了"<<endl;
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- catch(string& msg){
|
|
|
|
- cout<<"error: "<<msg<<endl;
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- catch(...)
|
|
|
|
- {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //imshow("pic", img);
|
|
|
|
- //waitKey(1);
|
|
|
|
-
|
|
|
|
- cout<<"angle="<<an<<" rootstock_width="<<obj_width<<" time(seconds): "<<((float)t0)/CLOCKS_PER_SEC<<endl;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- double oa = opa.infer(posinfo);
|
|
|
|
- t = clock() - t;
|
|
|
|
- cout<<"optimal angle: "<<oa<<endl;
|
|
|
|
- cout<<"time(seconds): "<<((float)t)/CLOCKS_PER_SEC<<endl;
|
|
|
|
-
|
|
|
|
- cout<<"\n\n";
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- destroyAllWindows();
|
|
|
|
-};
|
|
|
|
-void test_optimal_angle_simulate(){
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //string folder = "E:\\projects\\grafting_robots\\py_code\\tmp";
|
|
|
|
- string folder = "D:\\grafting_robot\\samples\\tmp";
|
|
|
|
- //string folder = "D:\\grafting_robot\\samples\\rootstock_rotate_part";
|
|
|
|
- //string folder = "D:\\private\\grafting_robot\\samples\\rootstock_rotate_part";
|
|
|
|
- //string folder = "D:\\private\\grafting_robot\\samples\\20211215\\rotate";
|
|
|
|
- namedWindow("pic", CV_WINDOW_NORMAL);
|
|
|
|
- vector<cv::String>filenames;
|
|
|
|
- ConfigParam cp;
|
|
|
|
- test_init_cp(cp);
|
|
|
|
- cp.image_return=true;
|
|
|
|
- cp.image_show=true;
|
|
|
|
- cp.oa_y_flip=false;
|
|
|
|
- cp.oa_clip_y_min=750;
|
|
|
|
-
|
|
|
|
- COptimalAnglePart opa(cp,&g_logger);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- for(int i = 1;i<=1;++i){
|
|
|
|
- //for(int j = 0;j<=1;++j){
|
|
|
|
- ostringstream ostr;
|
|
|
|
- ostr<<i;
|
|
|
|
- string subfold = ostr.str();
|
|
|
|
- string src_folder = folder+"\\"+subfold;
|
|
|
|
-
|
|
|
|
- cv::glob(src_folder, filenames);
|
|
|
|
- opa.reset();
|
|
|
|
-
|
|
|
|
- PositionInfo posinfo;
|
|
|
|
-
|
|
|
|
- clock_t t,t0;
|
|
|
|
- t = clock();
|
|
|
|
- for(size_t idx=0; idx<filenames.size();++idx){
|
|
|
|
- //cout<<filenames[idx]<<endl;
|
|
|
|
- size_t found0 = filenames[idx].rfind("\\");
|
|
|
|
- size_t found1 = filenames[idx].rfind(".");
|
|
|
|
- int an = stoi(filenames[idx].substr(found0+1, found1-found0));
|
|
|
|
- if(an >=200){
|
|
|
|
- an-=200;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Mat img = imread(filenames[idx], cv::IMREAD_GRAYSCALE);
|
|
|
|
- //Rect rect(Point(0,0),Point(img_.cols,cp.oa_clip_y_min));
|
|
|
|
- //Mat img = img_(rect);
|
|
|
|
-
|
|
|
|
- ImgInfo* imginfo = mat2imginfo(img);
|
|
|
|
- imginfo->angle = an;
|
|
|
|
- int obj_width=0;
|
|
|
|
- try{
|
|
|
|
- memset(&posinfo,0,sizeof(PositionInfo));
|
|
|
|
- t0 = clock();
|
|
|
|
- obj_width = opa.append(imginfo,posinfo);
|
|
|
|
- t0 = clock() - t0;
|
|
|
|
-
|
|
|
|
- imginfo_release(&imginfo);
|
|
|
|
- }
|
|
|
|
- catch(int i)
|
|
|
|
- {
|
|
|
|
- cout<<"i= "<<i<<"异常了"<<endl;
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- catch(string& msg){
|
|
|
|
- cout<<"error: "<<msg<<endl;
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- catch(...)
|
|
|
|
- {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //show return images
|
|
|
|
- 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);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- cout<<"angle="<<an<<" rootstock_width="<<obj_width<<" time(seconds): "<<((float)t0)/CLOCKS_PER_SEC<<endl;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- try{
|
|
|
|
- double oa = opa.infer(posinfo);
|
|
|
|
- t = clock() - t;
|
|
|
|
- cout<<"optimal angle: "<<oa<<endl;
|
|
|
|
- cout<<"time(seconds): "<<((float)t)/CLOCKS_PER_SEC<<endl;
|
|
|
|
-
|
|
|
|
- cout<<"\n\n";
|
|
|
|
- }
|
|
|
|
- catch(string& msg){
|
|
|
|
- cout<<"error: "<<msg<<endl;
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- catch(...)
|
|
|
|
- {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //}
|
|
|
|
- }
|
|
|
|
- destroyAllWindows();
|
|
|
|
-};
|
|
|
|
-void test_optimal_angle_part(){
|
|
|
|
- /*
|
|
|
|
- string data_file = "D:\\private\\grafting_robot\\py_code\\test.txt";
|
|
|
|
- ifstream ifs;
|
|
|
|
- ifs.open(data_file, fstream::out);
|
|
|
|
- std::vector<std::map<int,int>>data;
|
|
|
|
- std::vector<string> answer;
|
|
|
|
- if(ifs.is_open()){
|
|
|
|
- string line;
|
|
|
|
- std::map<int,int>tmp;
|
|
|
|
- while(!ifs.eof()){
|
|
|
|
- getline(ifs, line);
|
|
|
|
- //cout<<line<<endl;
|
|
|
|
- size_t ptmp = line.find("tmp");
|
|
|
|
- if(ptmp!=string::npos){
|
|
|
|
- tmp.clear();
|
|
|
|
- }
|
|
|
|
- else{
|
|
|
|
- size_t pos = line.find(",");
|
|
|
|
- if(pos==string::npos){
|
|
|
|
- data.push_back(tmp);
|
|
|
|
- tmp.clear();
|
|
|
|
- answer.push_back(line);
|
|
|
|
- }
|
|
|
|
- else{
|
|
|
|
- string ang = line.substr(0,pos);
|
|
|
|
- int an = atoi(ang.c_str());
|
|
|
|
- string wid = line.substr(pos+1,string::npos);
|
|
|
|
- int wi = atoi(wid.c_str());
|
|
|
|
- //cout<<ang<<" "<<wid<<endl;
|
|
|
|
- tmp.insert(make_pair<int,int>(an,wi));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- ifs.close();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //calculate
|
|
|
|
- ConfigParam cp;
|
|
|
|
- test_init_cp(cp);
|
|
|
|
- cp.image_return=true;
|
|
|
|
- cp.image_show=true;
|
|
|
|
-
|
|
|
|
- COptimalAnglePart opa(cp);
|
|
|
|
- for(size_t i=0;i< data.size();++i){
|
|
|
|
- cout<<"optimal angle: "<<answer[i]<<endl;
|
|
|
|
- for(size_t j=0;j<5;++j){
|
|
|
|
- int start_angle = j*20;
|
|
|
|
- std::map<int,int> impl_data;
|
|
|
|
- int impl_an = start_angle;
|
|
|
|
- if (impl_an==80 && data[i][impl_an]==277)
|
|
|
|
- {
|
|
|
|
- cout<<"debug"<<endl;
|
|
|
|
- }
|
|
|
|
- while(true){
|
|
|
|
- if((impl_an-start_angle)>110){break;}
|
|
|
|
- if(impl_an>180){break;}
|
|
|
|
- impl_data.insert(make_pair<int,int>(impl_an,data[i][impl_an]));
|
|
|
|
- cout<<impl_an<<"\t"<<data[i][impl_an]<<endl;
|
|
|
|
- impl_an+=20;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- double a = opa.angle_fit(impl_data);
|
|
|
|
- cout<<"angle: "<<a<<"\n"<<endl;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }*/
|
|
|
|
-
|
|
|
|
- ConfigParam cp;
|
|
|
|
- test_init_cp(cp);
|
|
|
|
- cp.image_return=true;
|
|
|
|
- cp.image_show=true;
|
|
|
|
-
|
|
|
|
- COptimalAnglePart* opa=new COptimalAnglePart(cp);
|
|
|
|
- map<int,int> d;
|
|
|
|
- d.insert(make_pair<int,int>(0,167));
|
|
|
|
- d.insert(make_pair<int,int>(30,126));
|
|
|
|
- d.insert(make_pair<int,int>(60,202));
|
|
|
|
- d.insert(make_pair<int,int>(90,193));
|
|
|
|
- d.insert(make_pair<int,int>(120,121));
|
|
|
|
- double a = opa->angle_fit(d);
|
|
|
|
- cout<<"angle: "<<a<<"\n"<<endl;
|
|
|
|
-};
|
|
|
|
|
|
+//void test_anglefit()
|
|
|
|
+//{
|
|
|
|
+// ConfigParam cp;
|
|
|
|
+// COptimalAnglePart opa = COptimalAnglePart(cp);
|
|
|
|
+// vector<map<int,int>> data;
|
|
|
|
+// //test_anglefit_readdata(data);
|
|
|
|
+// map<int,int>tmp;
|
|
|
|
+// /*tmp.insert(make_pair<int,int>(0,216));
|
|
|
|
+// tmp.insert(make_pair<int,int>(30,189));
|
|
|
|
+// tmp.insert(make_pair<int,int>(60,112));
|
|
|
|
+// tmp.insert(make_pair<int,int>(90,151));
|
|
|
|
+// tmp.insert(make_pair<int,int>(120,188));*/
|
|
|
|
+//
|
|
|
|
+// tmp.insert(make_pair<int,int>(0,315));
|
|
|
|
+// tmp.insert(make_pair<int,int>(30,270));
|
|
|
|
+// tmp.insert(make_pair<int,int>(60,218));
|
|
|
|
+// tmp.insert(make_pair<int,int>(90,141));
|
|
|
|
+// tmp.insert(make_pair<int,int>(120,127));
|
|
|
|
+//
|
|
|
|
+// data.push_back(tmp);
|
|
|
|
+// for(vector<map<int,int>>::iterator it = data.begin(); it!=data.end(); ++it){
|
|
|
|
+//
|
|
|
|
+// map<int,int>& an2width = *it;
|
|
|
|
+// double oa = opa.angle_fit(an2width);
|
|
|
|
+// cout<<oa<<endl;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+//};
|
|
|
|
+//void test_optimal_angle(){
|
|
|
|
+// //string folder = "E:\\projects\\grafting_robots\\py_code\\tmp";
|
|
|
|
+// string folder = "D:\\grafting_robot\\samples\\tmp";
|
|
|
|
+// namedWindow("pic", 0);
|
|
|
|
+// vector<cv::String>filenames;
|
|
|
|
+// ConfigParam cp;
|
|
|
|
+// test_init_cp(cp);
|
|
|
|
+// /*cp.oa_min_hist_value=10;
|
|
|
|
+// cp.oa_morph_iteration=2;
|
|
|
|
+// cp.oa_morph_radius = 1;*/
|
|
|
|
+// COptimalAngle opa(cp);
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// for(int i = 1;i<=5;++i){
|
|
|
|
+// for(int j = 0;j<=1;++j){
|
|
|
|
+// ostringstream ostr;
|
|
|
|
+// ostr<<i<<j;
|
|
|
|
+// string subfold = ostr.str();
|
|
|
|
+// string src_folder = folder+"\\p"+subfold;
|
|
|
|
+//
|
|
|
|
+// cv::glob(src_folder, filenames);
|
|
|
|
+// opa.reset();
|
|
|
|
+//
|
|
|
|
+// PositionInfo posinfo;
|
|
|
|
+//
|
|
|
|
+// clock_t t,t0;
|
|
|
|
+// t = clock();
|
|
|
|
+// for(size_t idx=0; idx<filenames.size();++idx){
|
|
|
|
+// //cout<<filenames[idx]<<endl;
|
|
|
|
+// size_t found0 = filenames[idx].rfind("\\");
|
|
|
|
+// size_t found1 = filenames[idx].rfind(".");
|
|
|
|
+// int an = stoi(filenames[idx].substr(found0+1, found1-found0))*20;
|
|
|
|
+// if(an >=200){
|
|
|
|
+// an-=200;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// Mat img = imread(filenames[idx], cv::IMREAD_GRAYSCALE);
|
|
|
|
+// ImgInfo* imginfo = mat2imginfo(img);
|
|
|
|
+// imginfo->angle = an;
|
|
|
|
+// int obj_width=0;
|
|
|
|
+// try{
|
|
|
|
+// t0 = clock();
|
|
|
|
+// obj_width = opa.append(imginfo,posinfo);
|
|
|
|
+// t0 = clock() - t0;
|
|
|
|
+//
|
|
|
|
+// imginfo_release(&imginfo);
|
|
|
|
+// }
|
|
|
|
+// catch(int i)
|
|
|
|
+// {
|
|
|
|
+// cout<<"i= "<<i<<"异常了"<<endl;
|
|
|
|
+// continue;
|
|
|
|
+// }
|
|
|
|
+// catch(string& msg){
|
|
|
|
+// cout<<"error: "<<msg<<endl;
|
|
|
|
+// continue;
|
|
|
|
+// }
|
|
|
|
+// catch(...)
|
|
|
|
+// {
|
|
|
|
+// continue;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// //imshow("pic", img);
|
|
|
|
+// //waitKey(1);
|
|
|
|
+//
|
|
|
|
+// cout<<"angle="<<an<<" rootstock_width="<<obj_width<<" time(seconds): "<<((float)t0)/CLOCKS_PER_SEC<<endl;
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+// double oa = opa.infer(posinfo);
|
|
|
|
+// t = clock() - t;
|
|
|
|
+// cout<<"optimal angle: "<<oa<<endl;
|
|
|
|
+// cout<<"time(seconds): "<<((float)t)/CLOCKS_PER_SEC<<endl;
|
|
|
|
+//
|
|
|
|
+// cout<<"\n\n";
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// destroyAllWindows();
|
|
|
|
+//};
|
|
|
|
+//void test_optimal_angle_simulate(){
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// //string folder = "E:\\projects\\grafting_robots\\py_code\\tmp";
|
|
|
|
+// string folder = "D:\\grafting_robot\\samples\\tmp";
|
|
|
|
+// //string folder = "D:\\grafting_robot\\samples\\rootstock_rotate_part";
|
|
|
|
+// //string folder = "D:\\private\\grafting_robot\\samples\\rootstock_rotate_part";
|
|
|
|
+// //string folder = "D:\\private\\grafting_robot\\samples\\20211215\\rotate";
|
|
|
|
+// namedWindow("pic", CV_WINDOW_NORMAL);
|
|
|
|
+// vector<cv::String>filenames;
|
|
|
|
+// ConfigParam cp;
|
|
|
|
+// test_init_cp(cp);
|
|
|
|
+// cp.image_return=true;
|
|
|
|
+// cp.image_show=true;
|
|
|
|
+// cp.oa_y_flip=false;
|
|
|
|
+// cp.oa_clip_y_min=750;
|
|
|
|
+//
|
|
|
|
+// COptimalAnglePart opa(cp,&g_logger);
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// for(int i = 1;i<=1;++i){
|
|
|
|
+// //for(int j = 0;j<=1;++j){
|
|
|
|
+// ostringstream ostr;
|
|
|
|
+// ostr<<i;
|
|
|
|
+// string subfold = ostr.str();
|
|
|
|
+// string src_folder = folder+"\\"+subfold;
|
|
|
|
+//
|
|
|
|
+// cv::glob(src_folder, filenames);
|
|
|
|
+// opa.reset();
|
|
|
|
+//
|
|
|
|
+// PositionInfo posinfo;
|
|
|
|
+//
|
|
|
|
+// clock_t t,t0;
|
|
|
|
+// t = clock();
|
|
|
|
+// for(size_t idx=0; idx<filenames.size();++idx){
|
|
|
|
+// //cout<<filenames[idx]<<endl;
|
|
|
|
+// size_t found0 = filenames[idx].rfind("\\");
|
|
|
|
+// size_t found1 = filenames[idx].rfind(".");
|
|
|
|
+// int an = stoi(filenames[idx].substr(found0+1, found1-found0));
|
|
|
|
+// if(an >=200){
|
|
|
|
+// an-=200;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// Mat img = imread(filenames[idx], cv::IMREAD_GRAYSCALE);
|
|
|
|
+// //Rect rect(Point(0,0),Point(img_.cols,cp.oa_clip_y_min));
|
|
|
|
+// //Mat img = img_(rect);
|
|
|
|
+//
|
|
|
|
+// ImgInfo* imginfo = mat2imginfo(img);
|
|
|
|
+// imginfo->angle = an;
|
|
|
|
+// int obj_width=0;
|
|
|
|
+// try{
|
|
|
|
+// memset(&posinfo,0,sizeof(PositionInfo));
|
|
|
|
+// t0 = clock();
|
|
|
|
+// obj_width = opa.append(imginfo,posinfo);
|
|
|
|
+// t0 = clock() - t0;
|
|
|
|
+//
|
|
|
|
+// imginfo_release(&imginfo);
|
|
|
|
+// }
|
|
|
|
+// catch(int i)
|
|
|
|
+// {
|
|
|
|
+// cout<<"i= "<<i<<"异常了"<<endl;
|
|
|
|
+// continue;
|
|
|
|
+// }
|
|
|
|
+// catch(string& msg){
|
|
|
|
+// cout<<"error: "<<msg<<endl;
|
|
|
|
+// continue;
|
|
|
|
+// }
|
|
|
|
+// catch(...)
|
|
|
|
+// {
|
|
|
|
+// continue;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// //show return images
|
|
|
|
+// 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);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// cout<<"angle="<<an<<" rootstock_width="<<obj_width<<" time(seconds): "<<((float)t0)/CLOCKS_PER_SEC<<endl;
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+// try{
|
|
|
|
+// double oa = opa.infer(posinfo);
|
|
|
|
+// t = clock() - t;
|
|
|
|
+// cout<<"optimal angle: "<<oa<<endl;
|
|
|
|
+// cout<<"time(seconds): "<<((float)t)/CLOCKS_PER_SEC<<endl;
|
|
|
|
+//
|
|
|
|
+// cout<<"\n\n";
|
|
|
|
+// }
|
|
|
|
+// catch(string& msg){
|
|
|
|
+// cout<<"error: "<<msg<<endl;
|
|
|
|
+// continue;
|
|
|
|
+// }
|
|
|
|
+// catch(...)
|
|
|
|
+// {
|
|
|
|
+// continue;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// //}
|
|
|
|
+// }
|
|
|
|
+// destroyAllWindows();
|
|
|
|
+//};
|
|
|
|
+//void test_optimal_angle_part(){
|
|
|
|
+// /*
|
|
|
|
+// string data_file = "D:\\private\\grafting_robot\\py_code\\test.txt";
|
|
|
|
+// ifstream ifs;
|
|
|
|
+// ifs.open(data_file, fstream::out);
|
|
|
|
+// std::vector<std::map<int,int>>data;
|
|
|
|
+// std::vector<string> answer;
|
|
|
|
+// if(ifs.is_open()){
|
|
|
|
+// string line;
|
|
|
|
+// std::map<int,int>tmp;
|
|
|
|
+// while(!ifs.eof()){
|
|
|
|
+// getline(ifs, line);
|
|
|
|
+// //cout<<line<<endl;
|
|
|
|
+// size_t ptmp = line.find("tmp");
|
|
|
|
+// if(ptmp!=string::npos){
|
|
|
|
+// tmp.clear();
|
|
|
|
+// }
|
|
|
|
+// else{
|
|
|
|
+// size_t pos = line.find(",");
|
|
|
|
+// if(pos==string::npos){
|
|
|
|
+// data.push_back(tmp);
|
|
|
|
+// tmp.clear();
|
|
|
|
+// answer.push_back(line);
|
|
|
|
+// }
|
|
|
|
+// else{
|
|
|
|
+// string ang = line.substr(0,pos);
|
|
|
|
+// int an = atoi(ang.c_str());
|
|
|
|
+// string wid = line.substr(pos+1,string::npos);
|
|
|
|
+// int wi = atoi(wid.c_str());
|
|
|
|
+// //cout<<ang<<" "<<wid<<endl;
|
|
|
|
+// tmp.insert(make_pair<int,int>(an,wi));
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// ifs.close();
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// //calculate
|
|
|
|
+// ConfigParam cp;
|
|
|
|
+// test_init_cp(cp);
|
|
|
|
+// cp.image_return=true;
|
|
|
|
+// cp.image_show=true;
|
|
|
|
+//
|
|
|
|
+// COptimalAnglePart opa(cp);
|
|
|
|
+// for(size_t i=0;i< data.size();++i){
|
|
|
|
+// cout<<"optimal angle: "<<answer[i]<<endl;
|
|
|
|
+// for(size_t j=0;j<5;++j){
|
|
|
|
+// int start_angle = j*20;
|
|
|
|
+// std::map<int,int> impl_data;
|
|
|
|
+// int impl_an = start_angle;
|
|
|
|
+// if (impl_an==80 && data[i][impl_an]==277)
|
|
|
|
+// {
|
|
|
|
+// cout<<"debug"<<endl;
|
|
|
|
+// }
|
|
|
|
+// while(true){
|
|
|
|
+// if((impl_an-start_angle)>110){break;}
|
|
|
|
+// if(impl_an>180){break;}
|
|
|
|
+// impl_data.insert(make_pair<int,int>(impl_an,data[i][impl_an]));
|
|
|
|
+// cout<<impl_an<<"\t"<<data[i][impl_an]<<endl;
|
|
|
|
+// impl_an+=20;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// double a = opa.angle_fit(impl_data);
|
|
|
|
+// cout<<"angle: "<<a<<"\n"<<endl;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// }*/
|
|
|
|
+//
|
|
|
|
+// ConfigParam cp;
|
|
|
|
+// test_init_cp(cp);
|
|
|
|
+// cp.image_return=true;
|
|
|
|
+// cp.image_show=true;
|
|
|
|
+//
|
|
|
|
+// COptimalAnglePart* opa=new COptimalAnglePart(cp);
|
|
|
|
+// map<int,int> d;
|
|
|
|
+// d.insert(make_pair<int,int>(0,167));
|
|
|
|
+// d.insert(make_pair<int,int>(30,126));
|
|
|
|
+// d.insert(make_pair<int,int>(60,202));
|
|
|
|
+// d.insert(make_pair<int,int>(90,193));
|
|
|
|
+// d.insert(make_pair<int,int>(120,121));
|
|
|
|
+// double a = opa->angle_fit(d);
|
|
|
|
+// cout<<"angle: "<<a<<"\n"<<endl;
|
|
|
|
+//};
|
|
void test_sc_cut_point()
|
|
void test_sc_cut_point()
|
|
{
|
|
{
|
|
|
|
|
|
@@ -1250,7 +1250,7 @@ void test_oa_batch(){
|
|
//cv_set_param(cp_ret);
|
|
//cv_set_param(cp_ret);
|
|
//namedWindow("pic", CV_WINDOW_NORMAL);
|
|
//namedWindow("pic", CV_WINDOW_NORMAL);
|
|
|
|
|
|
- string work_folder = "E:\\projects\\grafting_robot\\samples\\20220831\\top";
|
|
|
|
|
|
+ string work_folder = "E:\\projects\\grafting_robot\\samples\\20220831\\top_cpy_sim";
|
|
//string work_folder = "D:\\private\\grafting_robot\\samples\\20220220\\rotate";
|
|
//string work_folder = "D:\\private\\grafting_robot\\samples\\20220220\\rotate";
|
|
vector<cv::String>filenames;
|
|
vector<cv::String>filenames;
|
|
cv::glob(work_folder, filenames);
|
|
cv::glob(work_folder, filenames);
|
|
@@ -1259,11 +1259,11 @@ void test_oa_batch(){
|
|
if(filename.find(".rst_")!=string::npos){continue;}
|
|
if(filename.find(".rst_")!=string::npos){continue;}
|
|
//if(filename.find("\\249.bmp")==string::npos){continue;}
|
|
//if(filename.find("\\249.bmp")==string::npos){continue;}
|
|
PositionInfo posinfo;
|
|
PositionInfo posinfo;
|
|
- Mat img = imread(filename, cv::IMREAD_COLOR);//IMREAD_GRAYSCALE
|
|
|
|
|
|
+ Mat img = imread(filename, cv::IMREAD_GRAYSCALE);//IMREAD_GRAYSCALE IMREAD_COLOR
|
|
if(img.empty()){continue;}
|
|
if(img.empty()){continue;}
|
|
//image_set_top(img,20,8);
|
|
//image_set_top(img,20,8);
|
|
- //ImgInfo* imginfo = mat2imginfo(img);
|
|
|
|
- ImgInfo* imginfo = (ImgInfo*)(&img);
|
|
|
|
|
|
+ ImgInfo* imginfo = mat2imginfo(img);
|
|
|
|
+ //ImgInfo* imginfo = (ImgInfo*)(&img);
|
|
//imginfo->angle = j*30;
|
|
//imginfo->angle = j*30;
|
|
try{
|
|
try{
|
|
//rs_oa_init();
|
|
//rs_oa_init();
|
|
@@ -1407,7 +1407,7 @@ void test_api_batch(){
|
|
cv_init_image_saver();
|
|
cv_init_image_saver();
|
|
namedWindow("pic", CV_WINDOW_NORMAL);
|
|
namedWindow("pic", CV_WINDOW_NORMAL);
|
|
|
|
|
|
- string work_folder = "E:\\projects\\grafting_robot\\samples\\20220105\\batch";
|
|
|
|
|
|
+ string work_folder = "E:\\projects\\grafting_robot\\samples\\20220105\\batch2";
|
|
//string work_folder = "D:\\private\\grafting_robot\\samples\\20211215\\scion";
|
|
//string work_folder = "D:\\private\\grafting_robot\\samples\\20211215\\scion";
|
|
//string work_folder = "D:\\grafting_robot\\samples\\20220102\\batch";
|
|
//string work_folder = "D:\\grafting_robot\\samples\\20220102\\batch";
|
|
for(size_t i=1;i<19;++i){
|
|
for(size_t i=1;i<19;++i){
|
|
@@ -1416,7 +1416,7 @@ void test_api_batch(){
|
|
//buff<<work_folder<<"\\"<<"0-4-489.bmp";
|
|
//buff<<work_folder<<"\\"<<"0-4-489.bmp";
|
|
string batch_folder = buff.str();
|
|
string batch_folder = buff.str();
|
|
PositionInfo posinfo;
|
|
PositionInfo posinfo;
|
|
-
|
|
|
|
|
|
+ PositionInfo posinfo_cut;
|
|
///////////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////////
|
|
// 1 optimal angle
|
|
// 1 optimal angle
|
|
/*rs_oa_init();
|
|
/*rs_oa_init();
|
|
@@ -1453,23 +1453,34 @@ void test_api_batch(){
|
|
//////////////////////////////////////////////////////////////////
|
|
//////////////////////////////////////////////////////////////////
|
|
// 2 rootstock cut point
|
|
// 2 rootstock cut point
|
|
//if(!(i==4 || i==6 ||i==8 || i==12 || i==15) ){continue;}
|
|
//if(!(i==4 || i==6 ||i==8 || i==12 || i==15) ){continue;}
|
|
- //if(i!=12){continue;}
|
|
|
|
|
|
+ if(i!=10){continue;}
|
|
|
|
|
|
string rs_filename = batch_folder+"\\11.bmp";
|
|
string rs_filename = batch_folder+"\\11.bmp";
|
|
|
|
+ string cut_filename = batch_folder+"\\13.bmp";
|
|
/*if (i==15){
|
|
/*if (i==15){
|
|
rs_filename = batch_folder+"\\11.jpg";
|
|
rs_filename = batch_folder+"\\11.jpg";
|
|
}*/
|
|
}*/
|
|
Mat img = imread(rs_filename,cv::IMREAD_GRAYSCALE);
|
|
Mat img = imread(rs_filename,cv::IMREAD_GRAYSCALE);
|
|
image_set_top(img,20,8);
|
|
image_set_top(img,20,8);
|
|
- ImgInfo* rs_imginfo = mat2imginfo(img);
|
|
|
|
|
|
+ ImgInfo* rs_imginfo = mat2imginfo(img);
|
|
|
|
+
|
|
|
|
+ Mat img_cut = imread(cut_filename,cv::IMREAD_GRAYSCALE);
|
|
|
|
+ image_set_top(img_cut,20,8);
|
|
|
|
+ ImgInfo* cut_imginfo = mat2imginfo(img_cut);
|
|
|
|
+
|
|
|
|
+
|
|
clock_t t;
|
|
clock_t t;
|
|
|
|
|
|
memset(&posinfo,0,sizeof(PositionInfo));
|
|
memset(&posinfo,0,sizeof(PositionInfo));
|
|
|
|
+ memset(&posinfo_cut,0,sizeof(PositionInfo));
|
|
try{
|
|
try{
|
|
- t = clock();
|
|
|
|
- int fold_y = rs_cut_point(rs_imginfo, posinfo);
|
|
|
|
- t = clock() - t;
|
|
|
|
- imginfo_release(&rs_imginfo);
|
|
|
|
|
|
+ t = clock();
|
|
|
|
+ int fold_y = rs_cut_point(rs_imginfo, posinfo);
|
|
|
|
+ t = clock() - t;
|
|
|
|
+ imginfo_release(&rs_imginfo);
|
|
|
|
+
|
|
|
|
+ int reid = rs_cut_point_reid(cut_imginfo,posinfo.rs_img_id, posinfo_cut);
|
|
|
|
+ int x = posinfo_cut.rs_reid_upoint_x;
|
|
|
|
|
|
}
|
|
}
|
|
catch(exception &err){
|
|
catch(exception &err){
|
|
@@ -1608,9 +1619,9 @@ int _tmain(int argc, _TCHAR* argv[])
|
|
//test_sc_batch();
|
|
//test_sc_batch();
|
|
//test_rs_batch();
|
|
//test_rs_batch();
|
|
//test_rs_batch_camera();
|
|
//test_rs_batch_camera();
|
|
- test_rs_batch_reid();
|
|
|
|
|
|
+ //test_rs_batch_reid();
|
|
//test_oa_batch();
|
|
//test_oa_batch();
|
|
- //test_api_batch();
|
|
|
|
|
|
+ test_api_batch();
|
|
//drawline_rs();
|
|
//drawline_rs();
|
|
//drawline_sc();
|
|
//drawline_sc();
|
|
//drawline_dist();
|
|
//drawline_dist();
|