|
|
@@ -1,1633 +0,0 @@
|
|
|
-// demo.cpp : 定义控制台应用程序的入口点。
|
|
|
-//
|
|
|
-
|
|
|
-#include "stdafx.h"
|
|
|
-#include <iostream>
|
|
|
-#include <opencv2\highgui\highgui.hpp>
|
|
|
-#include <opencv2\imgproc\imgproc.hpp>
|
|
|
-#include <opencv2\opencv.hpp>
|
|
|
-#include <map>
|
|
|
-#include <fstream>
|
|
|
-#include <time.h>
|
|
|
-#include <iomanip>
|
|
|
-#include <fstream>
|
|
|
-#include <stdlib.h>
|
|
|
-
|
|
|
-#include "utils.h"
|
|
|
-#include "config.h"
|
|
|
-#include "data_def.h"
|
|
|
-#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"
|
|
|
-
|
|
|
-using namespace cv;
|
|
|
-using namespace graft_cv;
|
|
|
-
|
|
|
-ofstream logger_ofs;
|
|
|
-CGcvLogger g_logger = CGcvLogger(
|
|
|
- logger_ofs,
|
|
|
- CGcvLogger::file_and_terminal,
|
|
|
- CGcvLogger::info,
|
|
|
- "D:\\logs\\gcv.log");
|
|
|
-
|
|
|
-void test_init_cp(ConfigParam&cp){
|
|
|
- cp.image_show=true;//
|
|
|
- cp.image_return=true;//
|
|
|
- cp.image_row_grid=20;
|
|
|
- cp.image_col_grid=100;
|
|
|
- cp.timeout_append=100;
|
|
|
- cp.timeout_proc=500;
|
|
|
- cp.self_camera=true;
|
|
|
-
|
|
|
- cp.image_save=true;
|
|
|
- cp.image_depository="D:\\logs\\img_depo";
|
|
|
- cp.image_backup_days=7;
|
|
|
-
|
|
|
-
|
|
|
- cp.oa_y_flip=true;
|
|
|
- cp.oa_morph_radius = 1;
|
|
|
- cp.oa_morph_iteration=2;
|
|
|
- /*cp.oa_min_hist_value=10;
|
|
|
- cp.oa_morph_radius_base = 1;
|
|
|
- cp.oa_morph_iteration_base=2;
|
|
|
- cp.oa_min_hist_value_base=10;
|
|
|
-
|
|
|
- cp.oa_col_th_ratio=0.7;
|
|
|
- cp.oa_row_th_ratio=1.2;
|
|
|
- cp.oa_stem_x_padding=100;
|
|
|
- cp.oa_stem_dia_min=10;
|
|
|
- cp.oa_stem_fork_y_min=10;
|
|
|
- cp.oa_stem_dia_mp=0.9;
|
|
|
- cp.oa_clip_y_min=245;
|
|
|
- cp.oa_clip_y_max = 355;*/
|
|
|
-
|
|
|
- cp.rs_y_flip=false;
|
|
|
- cp.rs_col_th_ratio= 0.7;
|
|
|
- cp.rs_row_th_ratio= 1.15;
|
|
|
- cp.rs_stem_x_padding= 40;
|
|
|
- cp.rs_stem_dia_min=12;
|
|
|
- cp.rs_stem_fork_y_min=10;
|
|
|
- cp.rs_stem_dia_mp=0.98;
|
|
|
- cp.rs_stem_edge_detect_window=5;
|
|
|
- cp.rs_morph_radius=1;
|
|
|
- cp.rs_morph_iteration=2;
|
|
|
- cp.rs_morph_iteration_gray=5;
|
|
|
- cp.rs_max_corner_num=500;
|
|
|
- cp.rs_corner_qaulity_level= 0.1;
|
|
|
- cp.rs_corner_min_distance= 10;
|
|
|
- cp.rs_cand_corner_box_width_ratio=3.0;
|
|
|
- cp.rs_cand_corner_box_xoffset_ratio=0.75;
|
|
|
- cp.rs_opt_corner_xoffset_ratio = 0.2;
|
|
|
- cp.rs_opt_corner_yoffset_ratio = -0.5;
|
|
|
- cp.rs_corner_mask_rad_ratio=0.25;
|
|
|
- cp.rs_cut_angle=-45;
|
|
|
-
|
|
|
- cp.sc_y_flip=false;
|
|
|
- cp.sc_col_th_ratio=0.7;
|
|
|
- cp.sc_row_th_ratio=2.5; //2-3.0
|
|
|
- cp.sc_stem_x_padding=50;
|
|
|
- cp.sc_stem_dia_min=3;
|
|
|
- cp.sc_clip_padding=5;
|
|
|
- cp.sc_stem_ymax_padding=50;
|
|
|
- cp.sc_default_cut_length=20;
|
|
|
-
|
|
|
- cp.sc_stem_edge_detect_window=5;
|
|
|
- cp.sc_r2_th=1.05;
|
|
|
- cp.sc_r2_window=10;
|
|
|
- cp.sc_average_window=10;
|
|
|
- cp.sc_morph_radius=1;
|
|
|
- cp.sc_morph_iteration=2;
|
|
|
-
|
|
|
- cp.rs_oa_pixel_ratio=1.0;
|
|
|
- cp.rs_cut_pixel_ratio=1.0;
|
|
|
- cp.sc_cut_pixel_ratio=1.0;
|
|
|
-}
|
|
|
-void test_imginfo2mat()
|
|
|
-{
|
|
|
- int t=0;
|
|
|
- ImgInfo* ii = new ImgInfo();
|
|
|
- ii->angle=0;
|
|
|
- ii->width = ii->height = 13;
|
|
|
- ii->data = new graft_cv::byte[ii->width*ii->height];
|
|
|
- for (int i=0;i<ii->height;++i){
|
|
|
- for (int j=0;j<ii->width;++j){
|
|
|
- if (i==j || i+j==ii->width-1){
|
|
|
- ii->data[i*ii->width+j]=255;
|
|
|
- }
|
|
|
- else{
|
|
|
- ii->data[i*ii->width+j]=0;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- Mat img = imginfo2mat(ii);
|
|
|
-
|
|
|
- /*namedWindow("3_3", 0);
|
|
|
- imshow("3_3", img);
|
|
|
- waitKey(1);
|
|
|
- destroyAllWindows();*/
|
|
|
- delete [] ii->data;
|
|
|
- delete ii;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-};
|
|
|
-void test_camconfig_write()
|
|
|
-{
|
|
|
- ConfigParam cp0, cp1;
|
|
|
- memset(&cp1, 0, sizeof(ConfigParam));
|
|
|
- cp0 = cp1;
|
|
|
- CGCvConfig cam0 = CGCvConfig();
|
|
|
- CGCvConfig cam1 = CGCvConfig();
|
|
|
- cam0.setConfParam(&cp0);
|
|
|
- cam1.setConfParam(&cp1);
|
|
|
-
|
|
|
- FileStorage fs("cam_config.yml", FileStorage::WRITE);
|
|
|
- fs<<"conf_parameters";
|
|
|
- fs<<cam0;
|
|
|
- //fs<<cam1;
|
|
|
- //fs<<"]";
|
|
|
- fs.release();
|
|
|
-
|
|
|
-
|
|
|
-};
|
|
|
-void test_camconfig_read()
|
|
|
-{
|
|
|
- ConfigParam cp0, cp1;
|
|
|
- memset(&cp1, 0, sizeof(ConfigParam));
|
|
|
- cp0 = cp1;
|
|
|
- //cp0.oa_min_hist_value = 100;
|
|
|
- cout<<&cp0<<endl;
|
|
|
-
|
|
|
- CGCvConfig cam0 = CGCvConfig();
|
|
|
- //CGCvConfig cam1 = CGCvConfig();
|
|
|
- cam0.setConfParam(&cp0);
|
|
|
- //cam1.setConfParam(cp1);
|
|
|
-
|
|
|
- FileStorage fs("cam_config.yml", FileStorage::READ);
|
|
|
- cam0.read(fs["conf_parameters"]);
|
|
|
-
|
|
|
- //fs<<cam1;
|
|
|
- //fs<<"]";
|
|
|
- fs.release();
|
|
|
-
|
|
|
-
|
|
|
-};
|
|
|
-
|
|
|
-void test_anglefit_readdata(vector<map<int,int>>& data){
|
|
|
- string ifile = "E:\\projects\\grafting_robots\\py_code\\test.txt";
|
|
|
- ifstream ifs(ifile.c_str(), ifstream::in );
|
|
|
- data.clear();
|
|
|
- if( ifs.is_open()){
|
|
|
- string line;
|
|
|
- map<int,int> tmp;
|
|
|
- while(getline(ifs,line)){
|
|
|
- std::cout<<line<<std::endl;
|
|
|
- size_t found = line.find(",");
|
|
|
- if(found !=string::npos){
|
|
|
- //found
|
|
|
- string sub0 = line.substr(0,found);
|
|
|
- string sub1 = line.substr(found+1);
|
|
|
- int an = int(stod(sub0));
|
|
|
- int wi = stoi(sub1);
|
|
|
- if(an==0){
|
|
|
- tmp.clear();
|
|
|
- }
|
|
|
- tmp.insert(make_pair<int,int>(an,wi));
|
|
|
- if(an==180){
|
|
|
- data.push_back(tmp);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- 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_sc_cut_point()
|
|
|
-{
|
|
|
-
|
|
|
- //string src_folder = "E:\\projects\\grafting_robots\\samples\\scion1_part";
|
|
|
- //string src_folder = "D:\\private\\grafting_robot\\samples\\scion1_part";
|
|
|
- string src_folder = "D:\\grafting_robot\\samples\\scion1_part";
|
|
|
- vector<cv::String>filenames;
|
|
|
- cv::glob(src_folder, filenames);
|
|
|
- ConfigParam cp;
|
|
|
- test_init_cp(cp);
|
|
|
- /*
|
|
|
- //cp.sc_col_th_ratio=0.7;// = 0.7, scion binary image column histogram, threshold ratio for max-value, for
|
|
|
- // // detect stem x-range
|
|
|
- // cp.sc_row_th_ratio=1.2; // = 1.2, row histogram of stem x-range subimage, stem diameter ratio for detect
|
|
|
- // // stem fork position
|
|
|
- // cp.sc_stem_x_padding=50; // = 50;
|
|
|
- // cp.sc_stem_dia_min=20; //=20,
|
|
|
- // cp.sc_stem_dia_max=60; //=60,
|
|
|
- // cp.sc_stem_fork_y_min=80;//=80, cut slop length, jump this range for seaching stem fork position
|
|
|
- // cp.sc_fork_down=10; // stem fork down X pixels, below this line to calculate r2 ratio
|
|
|
- // cp.sc_r2_th=1.05; //threshold for r2 ratio
|
|
|
- // cp.sc_r2_window=5; //= 5; the radius for calculate r2 index
|
|
|
- // cp.sc_average_window=10;// =10;
|
|
|
-
|
|
|
- //cp.sc_morph_radius=1;//scion, open-operation morph-size, = 1;-->COptimalAngle::imgproc(Mat& img)
|
|
|
- // cp.sc_morph_iteration=2; //
|
|
|
- //
|
|
|
- */
|
|
|
- PositionInfo posinfo;
|
|
|
- CScionCutPoint scp(cp);
|
|
|
- //namedWindow("pic", WINDOW_NORMAL);
|
|
|
- ofstream g_logger_ofs;
|
|
|
- CGcvLogger g_logger = CGcvLogger(
|
|
|
- g_logger_ofs,
|
|
|
- CGcvLogger::file_and_terminal,
|
|
|
- CGcvLogger::warning,
|
|
|
- "./gcv_debug.log");
|
|
|
-
|
|
|
- clock_t t;
|
|
|
-
|
|
|
- for(size_t idx=0; idx<filenames.size();++idx){
|
|
|
- //cout<<idx<<"\t"<<filenames[idx]<<endl;
|
|
|
- //if(idx<38){continue;}
|
|
|
- //string fn = "D:\\private\\grafting_robot\\samples\\scion1_part\\IMG_20210830_153852.jpg";
|
|
|
- //Mat img_src = imread(fn, cv::IMREAD_COLOR);
|
|
|
-
|
|
|
- Mat img_src = imread(filenames[idx], cv::IMREAD_COLOR);
|
|
|
- Mat img;
|
|
|
- resize(img_src,img,Size(img_src.cols/4, img_src.rows/4));
|
|
|
- //ImgInfo* imginfo = mat2imginfo(img);
|
|
|
- int fold_y = 0;
|
|
|
- try{
|
|
|
- t = clock();
|
|
|
- fold_y = scp.up_point_detect(0,img,posinfo);
|
|
|
- t = clock() - t;
|
|
|
- }
|
|
|
- catch(exception &err){
|
|
|
- cout<<err.what()<<endl;
|
|
|
- }
|
|
|
- catch(const char* msg){
|
|
|
- cout<<msg<<endl;
|
|
|
- g_logger.ERRORINFO(msg);
|
|
|
- g_logger.INFO(filenames[idx]);
|
|
|
-
|
|
|
- }
|
|
|
- catch(string msg){
|
|
|
- cout<<msg<<endl;
|
|
|
- g_logger.ERRORINFO(msg);
|
|
|
- g_logger.INFO(filenames[idx]);
|
|
|
-
|
|
|
- }
|
|
|
- catch(...){
|
|
|
- cout<<"============================================unknown error"<<endl;
|
|
|
- cout<<filenames[idx]<<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";
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-};
|
|
|
-void test_sc_cut_point_simulate()
|
|
|
-{
|
|
|
-
|
|
|
- //string src_folder = "E:\\projects\\grafting_robots\\samples\\scion1_part";
|
|
|
- //string src_folder = "D:\\private\\grafting_robot\\samples\\scion1_part";
|
|
|
- //string src_folder = "D:\\grafting_robot\\samples\\scion1_simulate";
|
|
|
- string src_folder = "D:\\private\\grafting_robot\\samples\\20211222\\scion";
|
|
|
- vector<cv::String>filenames;
|
|
|
- cv::glob(src_folder, filenames);
|
|
|
- ConfigParam cp;
|
|
|
- test_init_cp(cp);
|
|
|
- cp.image_return=true;
|
|
|
- cp.image_show=true;
|
|
|
- cp.rs_y_flip=false;
|
|
|
- cp.self_camera=false;
|
|
|
-
|
|
|
- PositionInfo posinfo;
|
|
|
- memset(&posinfo,0,sizeof(PositionInfo));
|
|
|
- CScionCutPoint scp(cp,&g_logger);
|
|
|
- //namedWindow("pic", WINDOW_NORMAL);
|
|
|
- /*ofstream g_logger_ofs;
|
|
|
- Logger g_logger = Logger(
|
|
|
- g_logger_ofs,
|
|
|
- Logger::file_and_terminal,
|
|
|
- Logger::warning,
|
|
|
- "./gcv_debug.log");*/
|
|
|
-
|
|
|
- clock_t t;
|
|
|
-
|
|
|
- for(size_t idx=0; idx<filenames.size();++idx){
|
|
|
- //cout<<idx<<"\t"<<filenames[idx]<<endl;
|
|
|
- //if(idx<38){continue;}
|
|
|
- //string fn = "D:\\private\\grafting_robot\\samples\\scion1_part\\IMG_20210830_153852.jpg";
|
|
|
- //Mat img_src = imread(fn, cv::IMREAD_COLOR);
|
|
|
- cout<<idx<<"\t"<<filenames[idx]<<endl;
|
|
|
- //if(filenames[idx].find("0-4-504")==string::npos){continue;}
|
|
|
-
|
|
|
- Mat img = imread(filenames[idx], cv::IMREAD_COLOR);
|
|
|
- int fold_y = 0;
|
|
|
- try{
|
|
|
- t = clock();
|
|
|
- fold_y = scp.up_point_detect(0,img,posinfo);
|
|
|
- t = clock() - t;
|
|
|
- }
|
|
|
- catch(exception &err){
|
|
|
- cout<<err.what()<<endl;
|
|
|
- }
|
|
|
- catch(const char* msg){
|
|
|
- cout<<msg<<endl;
|
|
|
- g_logger.ERRORINFO(msg);
|
|
|
- g_logger.INFO(filenames[idx]);
|
|
|
-
|
|
|
- }
|
|
|
- catch(string msg){
|
|
|
- cout<<msg<<endl;
|
|
|
- g_logger.ERRORINFO(msg);
|
|
|
- g_logger.INFO(filenames[idx]);
|
|
|
-
|
|
|
- }
|
|
|
- catch(...){
|
|
|
- cout<<"============================================unknown error"<<endl;
|
|
|
- cout<<filenames[idx]<<endl<<endl;
|
|
|
- }
|
|
|
-
|
|
|
- //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);
|
|
|
- }
|
|
|
-
|
|
|
- //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";
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-};
|
|
|
-//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;
|
|
|
-// test_init_cp(cp);
|
|
|
-// cp.image_show=false;
|
|
|
-// cp.image_return = true;
|
|
|
-// cp.self_camera=false;
|
|
|
-// cp.oa_y_flip=false;
|
|
|
-//
|
|
|
-// namedWindow("pic", CV_WINDOW_NORMAL);
|
|
|
-// CRootStockCutPoint rscp(cp,&g_logger);
|
|
|
-//
|
|
|
-// //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\\reid";
|
|
|
-// 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);
|
|
|
-// //img = img(Rect(0,0,img.cols,(int)(img.rows/2)));
|
|
|
-// imshow("pic", img);
|
|
|
-// waitKey(-1);
|
|
|
-//
|
|
|
-// //ImgInfo* imginfo = mat2imginfo(img);
|
|
|
-// PositionInfo pinfo;
|
|
|
-// memset(&pinfo,0,sizeof(PositionInfo));
|
|
|
-// try{
|
|
|
-// t = clock();
|
|
|
-// int fold_y = rscp.up_point_reid(0,img,100.0, 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_api_scion(){
|
|
|
- // 0 ConfigParam cp;
|
|
|
- ConfigParam cp;
|
|
|
-
|
|
|
- //0
|
|
|
- //char* lpath="D:\\grafting_robot\\cpp_code\\logs\\gcv.log";
|
|
|
- //char* lpath = "D:\\private\\grafting_robot\\logs\\gcv.log";
|
|
|
- //cv_set_logpath(lpath);
|
|
|
- //cv_set_loglevel(0);
|
|
|
- //cout<<"test"<<endl;
|
|
|
-
|
|
|
- // 1 get version
|
|
|
- //test_init_cp(cp);
|
|
|
-
|
|
|
-
|
|
|
- char* ver = new char[10];
|
|
|
- get_version(ver);
|
|
|
- cout<<ver<<endl;
|
|
|
- delete [] ver;
|
|
|
- ver=0;
|
|
|
-
|
|
|
- //2 cv_set_param
|
|
|
- //cp.image_show=false;
|
|
|
- //cv_set_param(cp);
|
|
|
- //cv_save_param(0);
|
|
|
-
|
|
|
- //3 set log
|
|
|
- //cv_set_logpath("D:\\logs");
|
|
|
- //cv_set_loglevel(0);
|
|
|
-
|
|
|
- //3 cv_get_param();
|
|
|
- //ConfigParam cp_tmp;
|
|
|
- //cv_get_param(cp_tmp);
|
|
|
-
|
|
|
- //4 void cv_get_conf_file
|
|
|
- //char* conf_file_ret = new char[128];
|
|
|
- //cv_get_conf_file(conf_file_ret);
|
|
|
- //cout<<conf_file_ret<<endl;
|
|
|
- //delete [] conf_file_ret;
|
|
|
- //conf_file_ret=0;
|
|
|
-
|
|
|
- //5 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();
|
|
|
- //return;
|
|
|
-
|
|
|
- //
|
|
|
- //string work_folder = "D:\\private\\grafting_robot\\samples\\20211215\\scion";
|
|
|
- string work_folder = "E:\\projects\\grafting_robot\\samples\\20220115\\scion";
|
|
|
- vector<cv::String>filenames;
|
|
|
- cv::glob(work_folder, filenames);
|
|
|
- for(size_t i=0;i<filenames.size();++i){
|
|
|
- string fname = filenames[i];
|
|
|
- PositionInfo posinfo;
|
|
|
-
|
|
|
- Mat img = imread(fname, cv::IMREAD_GRAYSCALE);
|
|
|
- if(img.empty()){continue;}
|
|
|
- image_set_top(img,20,8);
|
|
|
- ImgInfo* imginfo = mat2imginfo(img);
|
|
|
- int rst = sc_cut_point(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);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- cv_release();
|
|
|
-}
|
|
|
-void test_sc_batch(){
|
|
|
-
|
|
|
- // 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\\20220223\\scion";
|
|
|
- //string work_folder = "D:\\private\\grafting_robot\\samples\\20220220\\scion";
|
|
|
- vector<cv::String>filenames;
|
|
|
- cv::glob(work_folder, filenames);
|
|
|
- for(size_t idx=0; idx<filenames.size();++idx){
|
|
|
- /*stringstream buff;
|
|
|
- buff<<work_folder<<"\\"<<i;
|
|
|
- string batch_folder = buff.str();*/
|
|
|
- PositionInfo posinfo;
|
|
|
- string filename = filenames[idx];
|
|
|
- if(filename.find("rst_")!=string::npos){
|
|
|
- continue;
|
|
|
- }
|
|
|
- cout<<idx<<"\t"<<filename<<endl;
|
|
|
- Mat img = imread(filename, cv::IMREAD_GRAYSCALE);
|
|
|
- if(img.empty()){continue;}
|
|
|
- image_set_top(img,20,8);
|
|
|
- ImgInfo* imginfo = mat2imginfo(img);
|
|
|
- try{
|
|
|
- //if(filename.find("1947_3.jpg")!=string::npos){
|
|
|
- // int ooo=0;
|
|
|
- // /*cp_ret.image_show=true;
|
|
|
- // cv_set_param(cp_ret);*/
|
|
|
- //}
|
|
|
- //else{
|
|
|
- // continue;
|
|
|
- //}
|
|
|
-
|
|
|
- int rst = sc_cut_point(imginfo, posinfo);
|
|
|
- imginfo_release(&imginfo);
|
|
|
- if(rst){
|
|
|
- cout<<"error"<<endl;
|
|
|
- continue;
|
|
|
- }
|
|
|
- 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;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- cv_release();
|
|
|
-}
|
|
|
-void test_rs_batch(){
|
|
|
-
|
|
|
- // 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\\20220620\\rootstock";
|
|
|
- //string work_folder = "D:\\private\\grafting_robot\\samples\\20220220\\rootstock";
|
|
|
- vector<cv::String>filenames;
|
|
|
- cv::glob(work_folder, filenames);
|
|
|
- int cnter=0;
|
|
|
- for(size_t idx=0; idx<filenames.size();++idx){
|
|
|
- string rs_filename = filenames[idx];
|
|
|
- if(rs_filename.find("rst_")!=string::npos){
|
|
|
- continue;
|
|
|
- }
|
|
|
- //if(rs_filename.find("\\379.bmp")==string::npos){continue;}
|
|
|
- cout<<idx<<"\t"<<rs_filename<<endl;
|
|
|
-
|
|
|
-
|
|
|
- PositionInfo posinfo;
|
|
|
- Mat img = imread(rs_filename,cv::IMREAD_GRAYSCALE);
|
|
|
- image_set_top(img,20,8);
|
|
|
- ImgInfo* rs_imginfo = mat2imginfo(img);
|
|
|
-
|
|
|
- memset(&posinfo,0,sizeof(PositionInfo));
|
|
|
- try{
|
|
|
- /*if(cnter==4){
|
|
|
- int test_tmp=0;
|
|
|
- }*/
|
|
|
- int fold_y = rs_cut_point(rs_imginfo, posinfo);
|
|
|
- imginfo_release(&rs_imginfo);
|
|
|
-
|
|
|
- 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<<rs_filename<<".rst_"<<i<<".jpg";
|
|
|
- string fnn = bbu.str();
|
|
|
- cv::imwrite(fnn,tmp_img);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- catch(exception &err){
|
|
|
- cout<<err.what()<<endl;
|
|
|
- }
|
|
|
- catch(string msg){
|
|
|
- cout<<msg<<endl;
|
|
|
- cout<<rs_filename<<endl<<endl;
|
|
|
- //g_logger.ERRORINFO(msg);
|
|
|
- //g_logger.INFO(img_file);
|
|
|
- }
|
|
|
- catch(...){
|
|
|
- cout<<"============================================unknown error"<<endl;
|
|
|
- cout<<rs_filename<<endl<<endl;
|
|
|
- }
|
|
|
- cnter+=1;
|
|
|
- }
|
|
|
- cv_release();
|
|
|
-}
|
|
|
-void test_rs_batch_camera(){
|
|
|
-
|
|
|
- // 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\\20220119\\rootstock_cut_compare";
|
|
|
- //string work_folder = "D:\\private\\grafting_robot\\samples\\20220104\\batch";
|
|
|
- vector<string> sub_path;
|
|
|
- sub_path.push_back("20220119133425");
|
|
|
- sub_path.push_back("20220119134921");
|
|
|
- sub_path.push_back("20220119135818");
|
|
|
- sub_path.push_back("20220119140720");
|
|
|
- sub_path.push_back("20220119141511");
|
|
|
- sub_path.push_back("20220119142616");
|
|
|
- sub_path.push_back("20220119143048");
|
|
|
-
|
|
|
- //vector<cv::String>filenames;
|
|
|
- //cv::glob(work_folder, filenames);
|
|
|
- vector<string> fileidx;
|
|
|
- fileidx.push_back("3.bmp");
|
|
|
- fileidx.push_back("11.bmp");
|
|
|
- fileidx.push_back("19.bmp");
|
|
|
- fileidx.push_back("27.bmp");
|
|
|
- fileidx.push_back("35.bmp");
|
|
|
- fileidx.push_back("43.bmp");
|
|
|
- fileidx.push_back("51.bmp");
|
|
|
- fileidx.push_back("59.bmp");
|
|
|
- fileidx.push_back("67.bmp");
|
|
|
- fileidx.push_back("75.bmp");
|
|
|
- fileidx.push_back("83.bmp");
|
|
|
- fileidx.push_back("91.bmp");
|
|
|
- fileidx.push_back("99.bmp");
|
|
|
- fileidx.push_back("107.bmp");
|
|
|
- fileidx.push_back("115.bmp");
|
|
|
- fileidx.push_back("123.bmp");
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- for(size_t idx=0; idx<sub_path.size();++idx){
|
|
|
- string subp = sub_path[idx];
|
|
|
- for(size_t i=0;i<fileidx.size();++i){
|
|
|
- string rs_filename = work_folder+"\\"+subp+ "\\"+fileidx[i];
|
|
|
-
|
|
|
- PositionInfo posinfo;
|
|
|
- Mat img = imread(rs_filename,cv::IMREAD_GRAYSCALE);
|
|
|
- if(img.empty()){continue;}
|
|
|
-
|
|
|
- ImgInfo* rs_imginfo = mat2imginfo(img);
|
|
|
- memset(&posinfo,0,sizeof(PositionInfo));
|
|
|
- try{
|
|
|
- int fold_y = rs_cut_point(rs_imginfo, posinfo);
|
|
|
- imginfo_release(&rs_imginfo);
|
|
|
-
|
|
|
- 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<<rs_filename<<".rst_"<<i<<".jpg";
|
|
|
- string fnn = bbu.str();
|
|
|
- cv::imwrite(fnn,tmp_img);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- catch(exception &err){
|
|
|
- cout<<err.what()<<endl;
|
|
|
- }
|
|
|
- catch(string msg){
|
|
|
- cout<<msg<<endl;
|
|
|
- cout<<rs_filename<<endl<<endl;
|
|
|
- //g_logger.ERRORINFO(msg);
|
|
|
- //g_logger.INFO(img_file);
|
|
|
- }
|
|
|
- catch(...){
|
|
|
- cout<<"============================================unknown error"<<endl;
|
|
|
- cout<<rs_filename<<endl<<endl;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- cv_release();
|
|
|
-}
|
|
|
-void test_oa_batch(){
|
|
|
-
|
|
|
- // 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\\20220831\\top_cpy_sim";
|
|
|
- //string work_folder = "D:\\private\\grafting_robot\\samples\\20220220\\rotate";
|
|
|
- vector<cv::String>filenames;
|
|
|
- cv::glob(work_folder, filenames);
|
|
|
- for(size_t idx=0; idx<filenames.size();++idx){
|
|
|
- string filename = filenames[idx];
|
|
|
- if(filename.find(".rst_")!=string::npos){continue;}
|
|
|
- //if(filename.find("\\249.bmp")==string::npos){continue;}
|
|
|
- PositionInfo posinfo;
|
|
|
- Mat img = imread(filename, cv::IMREAD_GRAYSCALE);//IMREAD_GRAYSCALE IMREAD_COLOR
|
|
|
- if(img.empty()){continue;}
|
|
|
- //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_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);
|
|
|
-
|
|
|
- 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);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- 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);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- cv_release();
|
|
|
-}
|
|
|
-void test_api_batch(){
|
|
|
-
|
|
|
- // 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();
|
|
|
- namedWindow("pic", CV_WINDOW_NORMAL);
|
|
|
-
|
|
|
- string work_folder = "E:\\projects\\grafting_robot\\samples\\20220105\\batch2";
|
|
|
- //string work_folder = "D:\\private\\grafting_robot\\samples\\20211215\\scion";
|
|
|
- //string work_folder = "D:\\grafting_robot\\samples\\20220102\\batch";
|
|
|
- for(size_t i=1;i<19;++i){
|
|
|
- stringstream buff;
|
|
|
- buff<<work_folder<<"\\"<<i;
|
|
|
- //buff<<work_folder<<"\\"<<"0-4-489.bmp";
|
|
|
- string batch_folder = buff.str();
|
|
|
- PositionInfo posinfo;
|
|
|
- PositionInfo posinfo_cut;
|
|
|
- ///////////////////////////////////////////////////////
|
|
|
- // 1 optimal angle
|
|
|
- /*rs_oa_init();
|
|
|
- for(size_t j=0;j<5;++j){
|
|
|
- stringstream bf;
|
|
|
- bf<<batch_folder<<"\\"<<2*j+1<<".bmp";
|
|
|
- string filename = bf.str();
|
|
|
- Mat img = imread(filename, cv::IMREAD_GRAYSCALE);
|
|
|
- if(img.empty()){continue;}
|
|
|
- image_set_top(img,20,8);
|
|
|
- ImgInfo* imginfo = mat2imginfo(img);
|
|
|
- imginfo->angle = j*30;
|
|
|
- try{
|
|
|
- rs_oa_append(imginfo, posinfo);
|
|
|
- }
|
|
|
- catch(...){
|
|
|
- std::cout<<"some error ..."<<endl;
|
|
|
- }
|
|
|
- std::cout<<"angle="<<imginfo->angle<<" rootstock_width="<<posinfo.rs_oa_width<<endl;
|
|
|
- imginfo_release(&imginfo);
|
|
|
-
|
|
|
-
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- rs_oa_get_result(posinfo);
|
|
|
- cout<<"optimal angle="<<posinfo.rs_oa<<endl;
|
|
|
- double opt_angle = posinfo.rs_oa;*/
|
|
|
-
|
|
|
- //////////////////////////////////////////////////////////////////
|
|
|
- // 2 rootstock cut point
|
|
|
- //if(!(i==4 || i==6 ||i==8 || i==12 || i==15) ){continue;}
|
|
|
- if(i!=10){continue;}
|
|
|
-
|
|
|
- string rs_filename = batch_folder+"\\11.bmp";
|
|
|
- string cut_filename = batch_folder+"\\13.bmp";
|
|
|
- /*if (i==15){
|
|
|
- rs_filename = batch_folder+"\\11.jpg";
|
|
|
- }*/
|
|
|
- Mat img = imread(rs_filename,cv::IMREAD_GRAYSCALE);
|
|
|
- image_set_top(img,20,8);
|
|
|
- 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;
|
|
|
-
|
|
|
- memset(&posinfo,0,sizeof(PositionInfo));
|
|
|
- memset(&posinfo_cut,0,sizeof(PositionInfo));
|
|
|
- try{
|
|
|
- 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){
|
|
|
- cout<<err.what()<<endl;
|
|
|
- }
|
|
|
- catch(string msg){
|
|
|
- cout<<msg<<endl;
|
|
|
- cout<<rs_filename<<endl<<endl;
|
|
|
- //g_logger.ERRORINFO(msg);
|
|
|
- //g_logger.INFO(img_file);
|
|
|
- }
|
|
|
- catch(...){
|
|
|
- cout<<"============================================unknown error"<<endl;
|
|
|
- cout<<rs_filename<<endl<<endl;
|
|
|
- }
|
|
|
- //show return images
|
|
|
- /*stringstream tu;
|
|
|
- tu<<batch_folder<<"\\rst_"<<int(opt_angle)<<"_"<<11<<".jpg";
|
|
|
- string tuu = tu.str();
|
|
|
- cv::imwrite(tuu,img);*/
|
|
|
-
|
|
|
- /*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<<batch_folder<<"\\rst_"<<i<<".jpg";
|
|
|
- string fnn = bbu.str();
|
|
|
- cv::imwrite(fnn,tmp_img);
|
|
|
- } */
|
|
|
- cout<<"time(seconds): "<<((float)t)/CLOCKS_PER_SEC<<endl;
|
|
|
-
|
|
|
- cout<<"\n\n";
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- cv_release();
|
|
|
-}
|
|
|
-void drawline_rs()
|
|
|
-{
|
|
|
- string rs_filename = "D:\\grafting_robot\\samples\\20220108\\rootstock\\27.jpg";
|
|
|
- Mat img = imread(rs_filename,cv::IMREAD_GRAYSCALE);
|
|
|
- double angle = -40.0 * 3.1415926 /180.0;
|
|
|
- //angle =tan(angle );
|
|
|
-
|
|
|
-
|
|
|
- int x0=259;
|
|
|
- int y0 = 461;
|
|
|
- int b = x0-y0;
|
|
|
- Point p0=Point(x0,y0);
|
|
|
- int x1 = img.cols-1;
|
|
|
- double dx=x1-x0;
|
|
|
- double dy = tan(angle) * dx;
|
|
|
- if(dy<0){dy = -dy;}
|
|
|
- int y1 = y0+(int)(dy+0.5);
|
|
|
- Point p1 = Point(x1,y1);
|
|
|
- int x2=0;
|
|
|
- int y2 = x0*tan(angle )+y0;
|
|
|
- Point p2 = Point(x2,y2);
|
|
|
-
|
|
|
- line(img,p0,p1,Scalar(255,255,255));
|
|
|
- line(img,p2,p1,Scalar(255,255,255));
|
|
|
- string fnn = "./tmp27.bmp";
|
|
|
- cv::imwrite(fnn,img);
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
-void drawline_sc()
|
|
|
-{
|
|
|
- string rs_filename = "D:\\grafting_robot\\samples\\20220108\\rootstock\\26.jpg";
|
|
|
- Mat img = imread(rs_filename,cv::IMREAD_GRAYSCALE);
|
|
|
- double angle = -40.0 * 3.1415926 /180.0;
|
|
|
- //angle =tan(angle );
|
|
|
-
|
|
|
-
|
|
|
- int x0=395;
|
|
|
- int y0 = 340;
|
|
|
- int b = x0-y0;
|
|
|
- Point p0=Point(x0,y0);
|
|
|
- int x1 = img.cols-1;
|
|
|
- double dx=x1-x0;
|
|
|
- double dy = tan(angle) * dx;
|
|
|
- if(dy<0){dy = -dy;}
|
|
|
- int y1 = y0+(int)(dy+0.5);
|
|
|
- Point p1 = Point(x1,y1);
|
|
|
- int x2=0;
|
|
|
- int y2 = x0*tan(angle )+y0;
|
|
|
- Point p2 = Point(x2,y2);
|
|
|
-
|
|
|
- line(img,p0,p1,Scalar(255,255,255));
|
|
|
- line(img,p2,p1,Scalar(255,255,255));
|
|
|
- string fnn = "./tmp26.bmp";
|
|
|
- cv::imwrite(fnn,img);
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
-void drawline_dist()
|
|
|
-{
|
|
|
- double x0=260.0;
|
|
|
- double y0=292.0;
|
|
|
-
|
|
|
- double angle = -45.0 * 3.1415926 /180.0;
|
|
|
- double k=tan(angle );
|
|
|
- double b = -k*260.0-435.0;
|
|
|
- double yy = -(k*x0 +b);
|
|
|
- double dy = yy-y0;
|
|
|
-
|
|
|
- double r = 5.8479999999999997e-002;
|
|
|
- double dyy = dy *r;
|
|
|
- cout<<dy<<"\t"<<dyy;
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-int _tmain(int argc, _TCHAR* argv[])
|
|
|
-{
|
|
|
- //test_imginfo2mat();
|
|
|
- //test_camconfig_write();
|
|
|
- //test_camconfig_read();
|
|
|
- //test_anglefit();
|
|
|
- //test_optimal_angle();
|
|
|
- //test_optimal_angle_simulate();
|
|
|
- //test_optimal_angle_part();
|
|
|
- //test_sc_cut_point();
|
|
|
- //test_sc_cut_point_simulate();
|
|
|
- //test_rs_cut_point();
|
|
|
- //test_rs_cut_point_simulate();
|
|
|
- //test_rs_cp_reid();
|
|
|
-
|
|
|
- /////////////////////////////
|
|
|
- //api test
|
|
|
- //test_api_scion();
|
|
|
- //test_sc_batch();
|
|
|
- //test_rs_batch();
|
|
|
- //test_rs_batch_camera();
|
|
|
- //test_rs_batch_reid();
|
|
|
- //test_oa_batch();
|
|
|
- test_api_batch();
|
|
|
- //drawline_rs();
|
|
|
- //drawline_sc();
|
|
|
- //drawline_dist();
|
|
|
-
|
|
|
-
|
|
|
- //system("pause");
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|