Jelajahi Sumber

v0.6.1 移植到vs2015平台(vc14),选用OpenCV v4.55

chenhongjiang 2 tahun lalu
induk
melakukan
c097535bd8
23 mengubah file dengan 445 tambahan dan 439 penghapusan
  1. 2 0
      .gitignore
  2. 63 62
      ReadMe.txt
  3. 2 2
      config.cpp
  4. 5 5
      config.h
  5. 1 1
      cut_point_impl_rs.h
  6. 55 55
      cut_point_rs.cpp
  7. 16 16
      cut_point_rs.h
  8. 32 32
      cut_point_rs_reid.cpp
  9. 7 7
      cut_point_rs_reid.h
  10. 55 55
      cut_point_sc.cpp
  11. 6 6
      cut_point_sc.h
  12. 22 22
      fork_rs.cpp
  13. 4 4
      fork_rs.h
  14. 14 13
      graft_cv_api.cpp
  15. 3 3
      imstorage_manager.cpp
  16. 3 3
      imstorage_manager.h
  17. 49 49
      optimal_angle.cpp
  18. 9 9
      optimal_angle.h
  19. 5 5
      stdafx.cpp
  20. 4 4
      stdafx.h
  21. 3 3
      targetver.h
  22. 61 59
      utils.cpp
  23. 24 24
      utils.h

+ 2 - 0
.gitignore

@@ -7,4 +7,6 @@ demo.vcxproj*
 *.log
 gcv_conf——.yml
 cam_config*
+graft_cv.cpp
+graft_cv.vcxproj*
 

+ 63 - 62
ReadMe.txt

@@ -1,71 +1,72 @@
-锘縱0.5.9.2 澧炲姞浜嗗浘鐗囦繚瀛橈紝鑷�姩瀹氭湡鍒犻櫎鍔熻兘锛涘�鍔犱簡histogram鐢熸垚鏃讹紝澧炲姞鏉冮噸銆�
-v0.5.9.3 鍘嬪彾鍒囧壊鐐硅瘑鍒�粨鏋滐紝涓嶈兘鐢ㄤ簬鍒囧壊锛屽皢鍒囧壊鐐规敼鎴愬垎鍙夌偣闂达紝闈犺繎鍙充晶涓夊垎涔嬩竴浣嶇疆
-v0.5.9.4 鍘绘帀鍒囧悗閲嶈瘑鍒�浉鍏崇殑浠g爜锛涘�鍔犺瘑鍒�粨鏋滅殑鍥剧墖;淇�敼stem_x0,stem_x1鐨勮瘑鍒�柟娉曪紱鍒嗗弶涓�偣浣滀负鍒囧壊鐐癸紱閫傜敤浜庝笉鍘嬪彾鐨勬儏鍐�
-v0.5.9.5 鐮ф湪鍒囧壊鐐硅瘑鍒�腑锛屾湁鐨勫彾瀛愯緝澶т笖涓嬪瀭锛岃瘑鍒�腑灏嗗彾瀛愯瘑鍒�垚鑼庯紝閫犳垚閿欒�锛屼慨鏀硅寧璇嗗埆鏂规硶get_stem_x_range锛堬級
-v0.5.9.6 1锛変慨鏀规棆杞�彾灞曡瘑鍒�柟娉曪紝鏀圭敤鏈€澶у彾瀹界殑鍥惧儚鍒嗗弶y鍊硷紱
-         2锛夐厤缃�枃浠朵腑
-		     澧炲姞
+v0.5.9.2 增加了图片保存,自动定期删除功能;增加了histogram生成时,增加权重。
+v0.5.9.3 压叶切割点识别结果,不能用于切割,将切割点改成分叉点间,靠近右侧三分之一位置
+v0.5.9.4 去掉切后重识别相关的代码;增加识别结果的图片;修改stem_x0,stem_x1的识别方法;分叉中点作为切割点;适用于不压叶的情况
+v0.5.9.5 砧木切割点识别中,有的叶子较大且下垂,识别中将叶子识别成茎,造成错误,修改茎识别方法get_stem_x_range()
+v0.5.9.6 1)修改旋转叶展识别方法,改用最大叶宽的图像分叉y值;
+         2)配置文件中
+		     增加
 			 rs_min_hist_value: 5
-		     淇�敼
+		     修改
 		     oa_min_hist_value: 5
 			 oa_stem_x_padding: 40
 
-		 3锛夊ぇ鍙朵笅鍨傝瘑鍒�寧浣嶇疆锛屽�鍔犱腑蹇冪偣瀹氫綅锛屽湪涓�績鐐圭殑浼橀€夛紝鐒跺悗璁$畻var閫夋嫨var澶х殑
-		 4锛夎繑鍥炵粨鏋滀腑澧炲姞 double rs_cut_lpoint_x;//鐮ф湪涓嬪垏鍓茬偣x浣嶇疆锛屾�绫�
-	                       double rs_cut_lpoint_y;//鐮ф湪涓嬪垏鍓茬偣y浣嶇疆锛屾�绫�
-						   double sc_cut_lpoint_x;//绌楄嫍鍒囧壊涓嬬偣x浣嶇疆锛屾�绫�
-	                       double sc_cut_lpoint_y;//绌楄嫍鍒囧壊涓嬬偣y浣嶇疆锛屾�绫�
-					鍘婚櫎鏇茬嚎闀垮害
-v0.5.9.7 淇�敼淇濆瓨鍥剧墖鐨勪綅缃�紝缈昏浆锛屽~鍏呭悗鐨勫浘鐗囦繚瀛�   
+		 3)大叶下垂识别茎位置,增加中心点定位,在中心点的优选,然后计算var选择var大的
+		 4)返回结果中增加 double rs_cut_lpoint_x;//砧木下切割点x位置,毫米
+	                       double rs_cut_lpoint_y;//砧木下切割点y位置,毫米
+						   double sc_cut_lpoint_x;//穗苗切割下点x位置,毫米
+	                       double sc_cut_lpoint_y;//穗苗切割下点y位置,毫米
+					去除曲线长度
+v0.5.9.7 修改保存图片的位置,翻转,填充后的图片保存   
 v0.5.9.8 
-        1锛変慨鏀规渶浼樿�搴﹁瘑鍒�腑鍗曡皟鎯呭喌鐨勭畻娉曪紝閲囩敤鏈€澶х偣鐨勮�搴︼紙鍘熸潵3鐐逛簩娆″樊鍊间細鍑虹幇杈冨ぇ璇�樊锛�   
-		2锛夊幓鎺夋渶浼樿�搴﹁瘑鍒�紝浜哄伐涓婃枡淇濊瘉鍙跺睍鏂瑰悜锛屾媿鐓т竴娆¤瘑鍒�垎鍙夌偣y楂樺害(鐩�墠浠g爜娌℃湁鏀瑰姩)
-		3锛夋渶浼樿�搴﹁瘑鍒玦nfer鍑芥暟澧炲姞杈撳嚭鏃ュ織锛氬垎鍙夌偣鍜屾牴鐐箉鐨勫儚绱犲€煎拰姣�背鍊�
+        1)修改最优角度识别中单调情况的算法,采用最大点的角度(原来3点二次差值会出现较大误差)   
+		2)去掉最优角度识别,人工上料保证叶展方向,拍照一次识别分叉点y高度(目前代码没有改动)
+		3)最优角度识别infer函数增加输出日志:分叉点和根点y的像素值和毫米值
 
-v0.5.9.9 鏈€浼樿�搴﹁瘑鍒�紝append鏂规硶锛岃繑鍥炲綋鏃剁殑鍒嗗弶鐐箉鍧愭爣锛屾渶浣庣偣y鍧愭爣
-         瀹炵幇涓€娆″浘鍍忚瘑鍒�繑鍥炵粨鏋滐紙閫傜敤浜庝汉宸ヤ笂鏂欙紝涓嶈嚜鍔ㄦ棆杞�殑鎯呭喌锛夛紝璋冪敤娴佺▼涓嶅彉锛屽彧鏄�皟鐢ㄦ�鏁颁负1
-		 澧炲姞杩斿洖鍙傛暟   double rs_oa_stem_y_fork;//鑼庡垎鍙夌偣y锛屾�绫�
-		            	double rs_oa_clamp_y_end;//鑼庡彲瑙嗕笅绔痽锛屾�绫�
-v0.5.9.10 澧炲姞鐮ф湪鍒囧壊鐐归棿杩炵嚎
-v0.5.9.11 澧炲姞鎺ュ彛璋冪敤杩涘叆銆佺�寮€鐨勬棩蹇椾俊鎭�; 鏀箁s_stem_dia_mp: 9.6e-001
-v0.5.9.12 绌楄嫍涓婂垏鍓茬偣璇嗗埆淇�敼锛屾敼鐢ㄤ腑鍊兼硶鍙栬寧绮楋紝杈惧埌鑼庣矖锛堟垨95鐧惧垎浣嶏級浣嶇疆涓轰笂鍒囧壊鐐�
-v0.5.9.13 1锛夌�鑻楀垏鍓茬偣鏈夎瘑鍒�笉鍒扮殑鎯呭喌锛堝洜涓鸿嫍鍊炬枩瑙掑害杩囧ぇ锛夛紝淇�敼锛堟墿澶э級璇嗗埆鑼冨洿
-          2锛夌牕鏈ㄥ垎鍙夌偣妫€娴嬫柟娉曪紙閫氳繃婊戝姩骞冲潎锛夛紝涓嶇ǔ瀹氾紝鍙�兘鍑虹幇涓嶈兘妫€娴嬪埌鍒嗗弶鐐圭殑鎯呭喌
-		     鐮ф湪鍑嗙‘鐨勪笂鍒囧壊鐐硅瘑鍒�柟娉�
-v0.5.9.14 淇�敼娴嬭瘯涓��鑻楀垏鍓茬偣妫€娴嬪嚭鐜癰ug锛寁ector瓒婄晫闂��
-          淇�敼  sc_stem_ymax_padding: 200
-v0.5.9.15 閽堝�鐮ф湪鏃嬭浆宸ヤ綅鍒嗗弶鐐硅瘑鍒�紝淇�敼util.cpp涓�殑get_stem_x_range()   
-          淇�敼鍙傛暟 rs_morph_radius: 2
+v0.5.9.9 最优角度识别,append方法,返回当时的分叉点y坐标,最低点y坐标
+         实现一次图像识别返回结果(适用于人工上料,不自动旋转的情况),调用流程不变,只是调用次数为1
+		 增加返回参数   double rs_oa_stem_y_fork;//茎分叉点y,毫米
+		            	double rs_oa_clamp_y_end;//茎可视下端y,毫米
+v0.5.9.10 增加砧木切割点间连线
+v0.5.9.11 增加接口调用进入、离开的日志信息; 改rs_stem_dia_mp: 9.6e-001
+v0.5.9.12 穗苗上切割点识别修改,改用中值法取茎粗,达到茎粗(或95百分位)位置为上切割点
+v0.5.9.13 1)穗苗切割点有识别不到的情况(因为苗倾斜角度过大),修改(扩大)识别范围
+          2)砧木分叉点检测方法(通过滑动平均),不稳定,可能出现不能检测到分叉点的情况
+		     砧木准确的上切割点识别方法
+v0.5.9.14 修改测试中穗苗切割点检测出现bug,vector越界问题
+          修改  sc_stem_ymax_padding: 200
+v0.5.9.15 针对砧木旋转工位分叉点识别,修改util.cpp中的get_stem_x_range()   
+          修改参数 rs_morph_radius: 2
                    rs_morph_iteration: 5    
-	      淇�敼鐮ф湪鍥惧儚鍒嗗壊鏂规硶涓虹洿鎺ヤ簩鍊煎寲锛岀劧鍚巆lose鏂规硶锛岀敤涓婅堪鏂板弬鏁帮紝瀹炵幇鍘绘瘺鍒�
-		  鐮ф湪col鏂瑰悜鐨刪istogram锛岄€氳繃涓�€兼护娉㈠啀娆″幓姣涘埡
-		  鐮ф湪涓嬪垏鍓茬偣浣嶇疆鎹㈢畻bug淇�敼
-v0.5.9.16 鐮ф湪鍒囧壊宸ヤ綅鍒囧壊鐐规�娴嬪垎2姝�
-          0锛夌牕鏈ㄥ垎鍙夌偣妫€娴嬫柟娉曪紝鏃嬭浆宸ヤ綅鍜屽垏鍓插伐浣嶅嚱鏁板垎寮€
-          1锛夊師鏉ョ殑鏂规硶妫€娴嬪垎鍙夌偣y鍧愭爣get_stem_y_fork_rs锛堬級锛岄€氳繃鐩村緞鍙樺寲绯绘暟鍜岀洿寰勶紙宸茬煡鐩村緞锛夊亸宸�郴鏁扮‘瀹氬垎鍙夌偣锛�
-		     骞堕檺瀹氬湪鑼庢牴閮ㄥ拰鑼庢渶瀹戒綅缃�紙閫氳繃x0鍜寈1闄愬畾锛夋壘鍑烘渶澶ф寚瀹氱殑鏂规硶纭�畾鍒嗗弶y鍊�
-		  2锛夊湪1锛夌殑鍩虹�涓婂�鍔爂et_stem_y_fork_rs_update锛堬級鍑芥暟锛屽熀浜�1锛変腑鐨勭粨鏋滐紝
-		     瀹炵幇鑼庝腑蹇冪嚎妫€娴嬶紱
-		     甯﹁�搴︾殑x鏂瑰悜padding鍥惧儚鍖哄煙鍓��锛�
-			 鎵惧嚭澶栬竟缂橈紝璁$畻涓�績绾垮埌杈圭紭鐨勬渶灏忚窛绂伙紱
-			 鎵惧嚭涓�嚎涓婄偣鏈€澶ц窛绂荤殑鐐逛綔涓哄垎鍙夊弬鑰冪偣
+	      修改砧木图像分割方法为直接二值化,然后close方法,用上述新参数,实现去毛刺
+		  砧木col方向的histogram,通过中值滤波再次去毛刺
+		  砧木下切割点位置换算bug修改
+v0.5.9.16 砧木切割工位切割点检测分2步
+          0)砧木分叉点检测方法,旋转工位和切割工位函数分开
+          1)原来的方法检测分叉点y坐标get_stem_y_fork_rs(),通过直径变化系数和直径(已知直径)偏差系数确定分叉点,
+		     并限定在茎根部和茎最宽位置(通过x0和x1限定)找出最大指定的方法确定分叉y值
+		  2)在1)的基础上增加get_stem_y_fork_rs_update()函数,基于1)中的结果,
+		     实现茎中心线检测;
+		     带角度的x方向padding图像区域剪裁;
+			 找出外边缘,计算中心线到边缘的最小距离;
+			 找出中线上点最大距离的点作为分叉参考点
           
-		  3锛変慨鏀瑰弬鏁�   rs_row_th_ratio: 1.1999999999999999e+000
-	      4) 鐢ㄥ埌flann锛屽�鍔爋pencv_flann2410d.lib
-v0.5.9.17 澧炲姞鐮ф湪鍒囧壊宸ヤ綅鍒囧壊鐐瑰亸绉诲弬鏁�
+		  3)修改参数   rs_row_th_ratio: 1.1999999999999999e+000
+	      4) 用到flann,增加opencv_flann2410d.lib
+v0.5.9.17 增加砧木切割工位切割点偏移参数
           rs_cut_point_offset_ratio: 5.0000000000000000e-001
-v0.5.9.18 鎬€鐤戝唴瀛樻硠闇诧紝妫€娴嬩紭鍖�
-          1)楂橀€熻繛缁�姞杞界牕鏈ㄥ浘鐗囨祴璇曞嚭鐜颁腑閫旈€€鍑猴紝1绉掑唴鍥剧墖id閲嶅�閫犳垚瀛樺偍寮傚父閫€鍑�
-		    淇�敼鍥剧墖id锛屽�鍔犲簭鍒楀€硷紙00-99锛�
-		  2锛塱mginfo2mat()涓�瀯寤簃at鐭╅樀锛岃嚜宸辩敵璇风殑鍐呭瓨锛坣ew锛夛紝鎸囬拡璧嬪€肩粰mat瀵硅薄锛宮at瀵硅薄
-		    鏋愭瀯鏄�笉璐熻矗閲婃斁锛岄€犳垚鍐呭瓨娉勯湶锛屽凡淇�敼
-v0.5.9.19 澧炲姞閰嶇疆鍙傛暟鍐欏叆鏃ュ織鍔熻兘锛氬惎鍔�-鍒濆�鍖栵紝鎴栬�涓鸿�缃�弬鏁板悗灏嗘渶鏂伴厤缃�弬鏁板啓鍏ユ棩蹇楁枃浠�
-          澧炲姞鐗堟湰鍙锋棩蹇�
-		  澧炲姞瀹藉ぇ鐪熷彾鐨勬儏鍐电殑澶勭悊
-v0.5.9.20 澧炲姞鐮ф湪鍒嗗弶鐐规�娴嬩紭鍖栵紝澧炲姞fork_rs.h,cpp(杩樻病鏈夊叏闈㈡祴璇�)
-          淇�敼鐮ф湪roi鏈€澶х偣璇嗗埆锛屽皢姣斾緥鍙傛暟1.5璋冩暣鑷�2.0锛坲tils.cpp锛�
-		  淇�敼鐮ф湪鑼庝腑蹇冩渶澶у唴鎺ュ洯鍗婂緞鐨勬柟娉曪紝涓嶉噰鐢╢lann鏌ユ壘锛堝嚭鐜拌�宸�緝澶э級锛屾敼鐢╬ointPolygonTest()
-		  鍘绘帀opencv_flann2410d.lib
-		  鎸夋祴璇曪紝淇�敼rs_cut_point_offset_ratio: 9.0000000000000000e-001
-		  淇�敼绌楄嫍璇嗗埆鏂规硶锛堢敤浜庢爣瀹氫綅缃�殑澶瑰瓙琚�伄鎸★級
-v0.6.0 淇�敼鏃嬭浆瑙掑害璇嗗埆绠楁硶锛岄噰鐢ㄩ《閮ㄦ媿鐓э紝涓€娆¤瘑鍒�棆杞��搴�
+v0.5.9.18 怀疑内存泄露,检测优化
+          1)高速连续加载砧木图片测试出现中途退出,1秒内图片id重复造成存储异常退出
+		    修改图片id,增加序列值(00-99)
+		  2)imginfo2mat()中构建mat矩阵,自己申请的内存(new),指针赋值给mat对象,mat对象
+		    析构是不负责释放,造成内存泄露,已修改
+v0.5.9.19 增加配置参数写入日志功能:启动-初始化,或认为设置参数后将最新配置参数写入日志文件
+          增加版本号日志
+		  增加宽大真叶的情况的处理
+v0.5.9.20 增加砧木分叉点检测优化,增加fork_rs.h,cpp(还没有全面测试)
+          修改砧木roi最大点识别,将比例参数1.5调整至2.0(utils.cpp)
+		  修改砧木茎中心最大内接园半径的方法,不采用flann查找(出现误差较大),改用pointPolygonTest()
+		  去掉opencv_flann2410d.lib
+		  按测试,修改rs_cut_point_offset_ratio: 9.0000000000000000e-001
+		  修改穗苗识别方法(用于标定位置的夹子被遮挡)
+v0.6.0 修改旋转角度识别算法,采用顶部拍照,一次识别旋转角度
+v0.6.1 移植到vs2015平台(vc14),选用OpenCV v4.55

+ 2 - 2
config.cpp

@@ -16,7 +16,7 @@ namespace graft_cv{
 	{
 		m_cparam = cp;
 	}
-	void CGCvConfig::write(FileStorage &fs)const{
+	void CGCvConfig::write(cv::FileStorage &fs)const{
 		assert(m_cparam!=0);
 		fs << "{" 
 			<< "image_show"<<  m_cparam->image_show
@@ -96,7 +96,7 @@ namespace graft_cv{
 			<< "sc_cut_pixel_ratio" << m_cparam->sc_cut_pixel_ratio
 			<< "}"; 	
 	};
-	void CGCvConfig::read(const FileNode& node){ //Read serialization for this class
+	void CGCvConfig::read(const cv::FileNode& node){ //Read serialization for this class
 		assert(m_cparam!=0);
 		m_cparam->image_show = (bool)(int)node["image_show"];
 		m_cparam->image_return = (bool)(int)node["image_return"];

+ 5 - 5
config.h

@@ -4,7 +4,7 @@
 #include "data_def_api.h"
 
 using namespace std;
-using namespace cv;
+//using namespace cv;
 
 namespace graft_cv{
 
@@ -14,17 +14,17 @@ namespace graft_cv{
 		CGCvConfig();
 		~CGCvConfig();
 		void setConfParam(ConfigParam*);		
-		void write(FileStorage &fs)const;
-		void read(const FileNode& node);
+		void write(cv::FileStorage &fs)const;
+		void read(const cv::FileNode& node);
 	private:
 		ConfigParam* m_cparam;	
 
 	};
 	//These write and read functions must exist as per the inline functions in operations.hpp
-	static void write(FileStorage& fs, const std::string&, const CGCvConfig& x){
+	static void write(cv::FileStorage& fs, const std::string&, const CGCvConfig& x){
 	  x.write(fs);
 	}
-	static void read(const FileNode& node, CGCvConfig& x, const CGCvConfig& default_value = CGCvConfig()){
+	static void read(const cv::FileNode& node, CGCvConfig& x, const CGCvConfig& default_value = CGCvConfig()){
 	  if(node.empty())
 		x = default_value;
 	  else

+ 1 - 1
cut_point_impl_rs.h

@@ -1,7 +1,7 @@
 #pragma once
 
 #include <opencv.hpp>
-using namespace cv;
+//using namespace cv;
 namespace graft_cv{
 
 }

+ 55 - 55
cut_point_rs.cpp

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

+ 16 - 16
cut_point_rs.h

@@ -7,7 +7,7 @@
 #include "logger.h"
 #include "imstorage_manager.h"
 
-using namespace cv;
+//using namespace cv;
 namespace graft_cv{
 
 class CRootStockCutPoint{
@@ -16,9 +16,9 @@ public:
 	~CRootStockCutPoint();
 	int up_point_detect(//上切割点,切前识别
 		ImgInfo*, 
-		Mat&,
+		cv::Mat&,
 		PositionInfo& posinfo,
-		map<string, Mat>& img_cache
+		map<string, cv::Mat>& img_cache
 		);
 
 	//int up_point_reid( // 上切割点,切后重识别
@@ -29,9 +29,9 @@ public:
 	//	);
 	void set_image_saver(CImStoreManager** ppis){m_ppImgSaver=ppis;}
 private:	
-	Mat m_binImg;// binary image
-	Mat m_grayImg;// gray image
-	Mat m_edgeImg;
+	cv::Mat m_binImg;// binary image
+	cv::Mat m_grayImg;// gray image
+	cv::Mat m_edgeImg;
 	string m_imgId;
 	CImStoreManager** m_ppImgSaver;
 
@@ -45,26 +45,26 @@ private:
 	ConfigParam& m_cparam;
 	CGcvLogger * m_pLogger;
 	// image segment
-	void img_segment(Mat&);
+	void img_segment(cv::Mat&);
 	
 	// get_optimal_corner()
 	// return 0--success, 1--error
 	int get_optimal_corner( 
 		int ref_x, 
 		int ref_y,
-		std::vector<Point2f>& corners,
+		std::vector<cv::Point2f>& corners,
 		int stem_dia,
 		double cand_corner_box_width_ratio,
 		double cand_corner_box_xoffset_ratio,
 		double opt_corner_xoffset_ratio,
 	    double opt_corner_yoffset_ratio,
 		double corner_mask_radius_ratio,
-		Point2f& cut_pt);
+		cv::Point2f& cut_pt);
 	void get_default_cutpoint(
 		int fork_cent_x,
 		int fork_cent_y,
 		int fork_stem_dia,
-		Point2f& cut_pt);
+		cv::Point2f& cut_pt);
 
 	void clear_imginfo();
 
@@ -72,8 +72,8 @@ private:
 	//# 通过砧木切前切割点识别结果(切割点)、二值图像,茎根y值,刀角度
 	//# 输出切割点到根部的边缘曲线长度
 	double get_cut_edge_length(
-		Mat& bin_img,
-		Mat& edge_img,
+		cv::Mat& bin_img,
+		cv::Mat& edge_img,
 		gcv_point<int>& start_pt, //up cut point
 		gcv_point<int>& lower_cut_pt,//output
 		gcv_point<int>& root_pt,//output
@@ -84,13 +84,13 @@ private:
 		);
 
 	void find_lower_cut_point(
-		Mat& bin_img,
+		cv::Mat& bin_img,
 		gcv_point<int>&start_pt,
 		gcv_point<int>&end_pt,//output
 		double cut_angle,
 		int stem_dia);
 	double calculate_edge_length(
-		Mat& edge_img,
+		cv::Mat& edge_img,
 		gcv_point<int>&lower_cut_pt,
 		gcv_point<int>&root_pt,//output
 		int y_max,
@@ -99,7 +99,7 @@ private:
 
 	//corner evluation
 	void corner_magnificence(
-		const vector<Point2f>& cand_pts,
+		const vector<cv::Point2f>& cand_pts,
 		int stem_dia,
 		double corner_mask_radius_ratio,
 		vector<double>& scores
@@ -114,7 +114,7 @@ private:
 		bool is_right  //是否右侧根部点, true-右侧,false-左侧
 		);
 	void  find_upper_cut_point_reid(
-		Mat& edge_img,
+		cv::Mat& edge_img,
 		gcv_point<int>&start_pt,
 		gcv_point<int>&end_pt,//output
 		double curve_length

+ 32 - 32
cut_point_rs_reid.cpp

@@ -4,7 +4,7 @@
 */
 #include <opencv2\imgproc\imgproc.hpp>
 #include <opencv2\features2d\features2d.hpp>
-#include <opencv2\nonfree\features2d.hpp>
+//#include <opencv2\nonfree\features2d.hpp>
 #include <math.h>
 #include <algorithm>
 
@@ -12,7 +12,7 @@
 #include "utils.h"
 #include "data_def.h"
 #include "logger.h"
-using namespace cv;
+//using namespace cv;
 
 namespace graft_cv{
 
@@ -48,10 +48,10 @@ void CRootStockCutPointReid::clear_imginfo(){
 
 int CRootStockCutPointReid::cut_point_reid(
 	ImgInfo* imginfo, 
-	Mat&cimg, 
+	cv::Mat&cimg,
 	const char * pre_img_id,
 	PositionInfo& posinfo,
-	map<string, Mat>& img_cache
+	map<string, cv::Mat>& img_cache
 	)
 {
 	// cimg --- color image, bgr
@@ -66,7 +66,7 @@ int CRootStockCutPointReid::cut_point_reid(
 		return 1;
 	} 
 	string pre_imgid(pre_img_id);
-	map<string, Mat>::iterator iter = img_cache.find(pre_imgid);
+	map<string, cv::Mat>::iterator iter = img_cache.find(pre_imgid);
 	if(iter==img_cache.end()){
 		if(m_pLogger){				
 			m_pLogger->ERRORINFO(m_imgId +" pre-image NOT in cache");
@@ -80,7 +80,7 @@ int CRootStockCutPointReid::cut_point_reid(
 	clock_t t;
 	clock_t t0 = clock();	
 
-	Mat img;
+	cv::Mat img;
 	if(imginfo){
 		if(m_pLogger){		
 			stringstream buff;
@@ -142,7 +142,7 @@ int CRootStockCutPointReid::cut_point_reid(
 	}
 
 	if(m_cparam.image_show){
-		destroyAllWindows();	
+		cv::destroyAllWindows();
 		imshow_wait("rs_pre_gray",m_preGrayImg);	
 		imshow_wait("rs_gray",m_grayImg);		
 	}
@@ -160,29 +160,29 @@ int CRootStockCutPointReid::cut_point_reid(
 	}
 	
 	//ÌØÕ÷ÌáÈ¡
-	int max_feature = 500;
-	OrbFeatureDetector fts_detector(max_feature);
-	//SurfFeatureDetector fts_detector(max_feature);
-	std::vector<KeyPoint> keypoints_pre, keypoints_cur;
-	fts_detector.detect( m_preGrayImg, keypoints_pre );
-	fts_detector.detect( m_grayImg, keypoints_cur );
+	//int max_feature = 500;
+	//cv::OrbFeatureDetector fts_detector(max_feature);
+	////SurfFeatureDetector fts_detector(max_feature);
+	//std::vector<cv::KeyPoint> keypoints_pre, keypoints_cur;
+	//fts_detector.detect( m_preGrayImg, keypoints_pre );
+	//fts_detector.detect( m_grayImg, keypoints_cur );
 
-	SurfDescriptorExtractor extractor;
-	Mat descriptors_pre, descriptors_cur;
-	extractor.compute( m_preGrayImg, keypoints_pre, descriptors_pre );
-	extractor.compute( m_grayImg, keypoints_cur, descriptors_cur );
-	//-- Step 3: Matching descriptor vectors with a brute force matcher
-	BFMatcher matcher(NORM_L2);
-	std::vector< DMatch > matches;
-	matcher.match( descriptors_pre, descriptors_cur, matches );
-	if(m_cparam.image_show){
-		//-- Draw matches
-		Mat img_matches;
-		drawMatches( m_preGrayImg, keypoints_pre, m_grayImg, keypoints_cur, matches, img_matches );
-		//-- Show detected matches
-		imshow("Matches", img_matches );
-		waitKey(-1);
-	}
+	//cv::SurfDescriptorExtractor extractor;
+	//cv::Mat descriptors_pre, descriptors_cur;
+	//extractor.compute( m_preGrayImg, keypoints_pre, descriptors_pre );
+	//extractor.compute( m_grayImg, keypoints_cur, descriptors_cur );
+	////-- Step 3: Matching descriptor vectors with a brute force matcher
+	//cv::BFMatcher matcher(cv::NORM_L2);
+	//std::vector< cv::DMatch > matches;
+	//cv::matcher.match( descriptors_pre, descriptors_cur, matches );
+	//if(m_cparam.image_show){
+	//	//-- Draw matches
+	//	cv::Mat img_matches;
+	//	cv::drawMatches( m_preGrayImg, keypoints_pre, m_grayImg, keypoints_cur, matches, img_matches );
+	//	//-- Show detected matches
+	//	cv::imshow("Matches", img_matches );
+	//	cv::waitKey(-1);
+	//}
 
 	posinfo.rs_reid_upoint_x = 10.0;
 	posinfo.rs_reid_upoint_y = 10.0;
@@ -237,13 +237,13 @@ int CRootStockCutPointReid::cut_point_reid(
 	return 0;
 };
 
-void CRootStockCutPointReid::img_preprocess(Mat&img)
+void CRootStockCutPointReid::img_preprocess(cv::Mat&img)
 {
 	//»Ò¶È»¯
-	Mat b_img;
+	cv::Mat b_img;
 	if(img.channels()!=1){
 		//color image ,bgr, for testing		
-		cvtColor(img,m_grayImg,COLOR_BGR2GRAY);
+		cvtColor(img,m_grayImg, cv::COLOR_BGR2GRAY);
 	}
 	else{
 		m_grayImg = img.clone();

+ 7 - 7
cut_point_rs_reid.h

@@ -7,7 +7,7 @@
 #include "logger.h"
 #include "imstorage_manager.h"
 
-using namespace cv;
+//using namespace cv;
 namespace graft_cv{
 
 class CRootStockCutPointReid{
@@ -16,17 +16,17 @@ public:
 	~CRootStockCutPointReid();
 	int cut_point_reid(			//切后切割点识别
 		ImgInfo*,				//切后图片
-		Mat&,					//切后图片,测试用
+		cv::Mat&,					//切后图片,测试用
 		const char * pre_img_id,		//切前图像id
 		PositionInfo& posinfo,	
-		map<string, Mat>& img_cache
+		map<string, cv::Mat>& img_cache
 		);	
 	void set_image_saver(CImStoreManager** ppis){m_ppImgSaver=ppis;}
 private:
-	Mat m_preGrayImg;// gray image
+	cv::Mat m_preGrayImg;// gray image
 	//Mat m_binImg;// binary image
-	Mat m_grayImg;// gray image
-	Mat m_edgeImg;
+	cv::Mat m_grayImg;// gray image
+	cv::Mat m_edgeImg;
 	string m_imgId;
 	CImStoreManager** m_ppImgSaver;
 
@@ -40,7 +40,7 @@ private:
 	ConfigParam& m_cparam;
 	CGcvLogger * m_pLogger;
 	// image segment
-	void img_preprocess(Mat&);
+	void img_preprocess(cv::Mat&);
 	void clear_imginfo();
 	
 };

+ 55 - 55
cut_point_sc.cpp

@@ -1,7 +1,7 @@
 #include <opencv2\imgproc\imgproc.hpp>
 #include "cut_point_sc.h"
 #include "utils.h"
-using namespace cv;
+//using namespace cv;
 
 namespace graft_cv{
 
@@ -29,7 +29,7 @@ void CScionCutPoint::clear_imginfo(){
 
 int CScionCutPoint::up_point_detect(
 	ImgInfo* imginfo, 
-	Mat&cimg, 
+	cv::Mat&cimg,
 	PositionInfo& posinfo
 	)
 {
@@ -42,7 +42,7 @@ int CScionCutPoint::up_point_detect(
 	}
 	
 	// cimg --- color image, bgr
-	Mat img;
+	cv::Mat img;
 	if(imginfo){
 		if(m_pLogger){		
 			stringstream buff;
@@ -108,7 +108,7 @@ int CScionCutPoint::up_point_detect(
 	}
 
 	if(m_cparam.image_show){
-		destroyAllWindows();	
+		cv::destroyAllWindows();
 		imshow_wait("sc_gray", m_grayImg);	
 		imshow_wait("sc_bin", m_binImg);		
 	}
@@ -123,7 +123,7 @@ int CScionCutPoint::up_point_detect(
 	mat_histogram(m_binImg,hist_col);
 
 	if(m_cparam.image_show){		
-		Mat hist_col_img;
+		cv::Mat hist_col_img;
 		hist2image(hist_col,hist_col_img,1,m_cparam.image_col_grid,m_cparam.image_row_grid);		
 		imshow_wait("sc_hist_col", hist_col_img);		
 	}
@@ -152,10 +152,10 @@ int CScionCutPoint::up_point_detect(
 	}
 
 	if(m_cparam.image_show){		
-		Mat tmp_img = m_binImg.clone();
+		cv::Mat tmp_img = m_binImg.clone();
 
-		line(tmp_img,Point(x0,0),Point(x0,m_binImg.rows-1),Scalar(100),2);
-		line(tmp_img,Point(x1,0),Point(x1,m_binImg.rows-1),Scalar(100),2);
+		cv::line(tmp_img, cv::Point(x0,0), cv::Point(x0,m_binImg.rows-1), cv::Scalar(100),2);
+		cv::line(tmp_img, cv::Point(x1,0), cv::Point(x1,m_binImg.rows-1), cv::Scalar(100),2);
 		//fork right point
 		imshow_wait("sc_x_field", tmp_img);				
 	}	
@@ -169,7 +169,7 @@ int CScionCutPoint::up_point_detect(
 	}
 
 	if(m_cparam.image_show){		
-		Mat hist_row_img;
+		cv::Mat hist_row_img;
 		hist2image(hist_row,hist_row_img, 0,m_cparam.image_col_grid,m_cparam.image_row_grid);		
 		imshow_wait("sc_hist_row", hist_row_img);		
 	}
@@ -185,7 +185,7 @@ int CScionCutPoint::up_point_detect(
 	vector<int> sub_hist_row;
 	int sub_stem_x0,sub_stem_x1,sub_x0,sub_x1;
 	sub_x0 = sub_x1=sub_stem_x0=sub_stem_x1=-1;
-	Mat scionBinImg;	
+	cv::Mat scionBinImg;
 	get_stem_local_img(
 		hist_row,		
 		m_cparam.sc_stem_dia_min,
@@ -249,7 +249,7 @@ int CScionCutPoint::up_point_detect(
 	ymax += stem_y_min;
 	slop_cent_y += stem_y_min;
 
-	Mat binRoi = m_binImg(Rect(x0,stem_y_min,scionBinImg.cols,scionBinImg.rows));
+	cv::Mat binRoi = m_binImg(cv::Rect(x0,stem_y_min,scionBinImg.cols,scionBinImg.rows));
 	scionBinImg.copyTo(binRoi);
 	//imshow_wait("m_binImg", m_binImg);
 
@@ -267,18 +267,18 @@ int CScionCutPoint::up_point_detect(
 	}
 
 	if(m_cparam.image_show){		
-		Mat result_img = m_binImg.clone();
+		cv::Mat result_img = m_binImg.clone();
 		//stem x-range
-		line(result_img,Point(stem_x0,0),Point(stem_x0,m_binImg.rows-1),Scalar(100),2);
-		line(result_img,Point(stem_x1,0),Point(stem_x1,m_binImg.rows-1),Scalar(100),2);
+		cv::line(result_img, cv::Point(stem_x0,0), cv::Point(stem_x0,m_binImg.rows-1), cv::Scalar(100),2);
+		cv::line(result_img, cv::Point(stem_x1,0), cv::Point(stem_x1,m_binImg.rows-1), cv::Scalar(100),2);
 
 		//fork y line
-		line(result_img,Point(stem_x0,stem_y_min),Point(stem_x1,stem_y_min),Scalar(100),2);
-		line(result_img,Point(stem_x0,ymax),Point(stem_x1,ymax),Scalar(100),2);
+		cv::line(result_img, cv::Point(stem_x0,stem_y_min), cv::Point(stem_x1,stem_y_min), cv::Scalar(100),2);
+		cv::line(result_img, cv::Point(stem_x0,ymax), cv::Point(stem_x1,ymax), cv::Scalar(100),2);
 		//fold right point
-		circle(result_img, Point(slop_fold_x,ymin),2, Scalar(150,0,128), -1, 8,0);
-		circle(result_img, Point(slop_cent_x,slop_cent_y),2, Scalar(150,0,128), -1, 8,0);
-		circle(result_img, Point(slop_lower_x,ymax),2, Scalar(150,0,128), -1, 8,0);
+		cv::circle(result_img, cv::Point(slop_fold_x,ymin),2, cv::Scalar(150,0,128), -1, 8,0);
+		cv::circle(result_img, cv::Point(slop_cent_x,slop_cent_y),2, cv::Scalar(150,0,128), -1, 8,0);
+		cv::circle(result_img, cv::Point(slop_lower_x,ymax),2, cv::Scalar(150,0,128), -1, 8,0);
 		imshow_wait("sc_result", result_img);		
 	}
 
@@ -335,16 +335,16 @@ int CScionCutPoint::up_point_detect(
 		this->clear_imginfo();
 		//1) 		
 		//stem x-range
-		line(m_binImg,Point(stem_x0,0),Point(stem_x0,m_binImg.cols-1),Scalar(100),2);
-		line(m_binImg,Point(stem_x1,0),Point(stem_x1,m_binImg.cols-1),Scalar(100),2);
+		cv::line(m_binImg, cv::Point(stem_x0,0), cv::Point(stem_x0,m_binImg.cols-1), cv::Scalar(100),2);
+		cv::line(m_binImg, cv::Point(stem_x1,0), cv::Point(stem_x1,m_binImg.cols-1), cv::Scalar(100),2);
 
 		//fork y line
-		line(m_binImg,Point(stem_x0,stem_y_min),Point(stem_x1,stem_y_min),Scalar(100),2);
-		line(m_binImg,Point(stem_x0,ymax),Point(stem_x1,ymax),Scalar(100),2);
+		cv::line(m_binImg, cv::Point(stem_x0,stem_y_min), cv::Point(stem_x1,stem_y_min), cv::Scalar(100),2);
+		cv::line(m_binImg, cv::Point(stem_x0,ymax), cv::Point(stem_x1,ymax), cv::Scalar(100),2);
 		//fold right point
-		circle(m_binImg, Point(slop_fold_x,ymin),5, Scalar(128,0,128), -1, 8,0);
-		circle(m_binImg, Point(slop_cent_x,slop_cent_y),5, Scalar(128,0,128), -1, 8,0);
-		circle(m_binImg, Point(slop_lower_x,ymax),5, Scalar(128,0,128), -1, 8,0);
+		cv::circle(m_binImg, cv::Point(slop_fold_x,ymin),5, cv::Scalar(128,0,128), -1, 8,0);
+		cv::circle(m_binImg, cv::Point(slop_cent_x,slop_cent_y),5, cv::Scalar(128,0,128), -1, 8,0);
+		cv::circle(m_binImg, cv::Point(slop_lower_x,ymax),5, cv::Scalar(128,0,128), -1, 8,0);
 		m_pImginfoBinFork=mat2imginfo(m_binImg);		
 		//
 		posinfo.pp_images[0]=m_pImginfoBinFork;		
@@ -357,31 +357,31 @@ int CScionCutPoint::up_point_detect(
 	}
 	return ymin;
 }
-void CScionCutPoint::img_segment(Mat&img)
+void CScionCutPoint::img_segment(cv::Mat&img)
 {
 	if(img.channels()!=1){
 		//color image ,bgr, for testing
-		Mat b_img;
-		cvtColor(img,m_grayImg,COLOR_BGR2GRAY);		
+		cv::Mat b_img;
+		cvtColor(img,m_grayImg, cv::COLOR_BGR2GRAY);
 		double th = threshold(
 			m_grayImg,
 			b_img,
 			255,
 			255,
-			THRESH_OTSU
+			cv::THRESH_OTSU
 			);
 	   
-		Mat kernel = getStructuringElement(
-			MORPH_RECT,
-			Size( 2*m_cparam.sc_morph_radius + 1, 2*m_cparam.sc_morph_radius+1),
-			Point( m_cparam.sc_morph_radius, m_cparam.sc_morph_radius)
+		cv::Mat kernel = getStructuringElement(
+			cv::MORPH_RECT,
+			cv::Size( 2*m_cparam.sc_morph_radius + 1, 2*m_cparam.sc_morph_radius+1),
+			cv::Point( m_cparam.sc_morph_radius, m_cparam.sc_morph_radius)
 			);  
 		morphologyEx(
 			b_img,
 			m_binImg,
-			MORPH_CLOSE,
+			cv::MORPH_CLOSE,
 			kernel,
-			Point(-1,-1),
+			cv::Point(-1,-1),
 			m_cparam.sc_morph_iteration);
 		
 	}
@@ -389,19 +389,19 @@ void CScionCutPoint::img_segment(Mat&img)
 		//from imginfo image, gray image 
 		//int morph_size = 1;	
 		m_grayImg = img.clone();
-		Mat b_img;
-		double th = threshold(img, b_img, 255, 255,THRESH_OTSU);
-		Mat kernel = getStructuringElement( 
-			MORPH_RECT, 
-			Size( 2*m_cparam.sc_morph_radius + 1, 2*m_cparam.sc_morph_radius+1 ), 
-			Point( m_cparam.sc_morph_radius, m_cparam.sc_morph_radius)
+		cv::Mat b_img;
+		double th = threshold(img, b_img, 255, 255, cv::THRESH_OTSU);
+		cv::Mat kernel = cv::getStructuringElement(
+			cv::MORPH_RECT,
+			cv::Size( 2*m_cparam.sc_morph_radius + 1, 2*m_cparam.sc_morph_radius+1 ),
+			cv::Point( m_cparam.sc_morph_radius, m_cparam.sc_morph_radius)
 			);    
-		morphologyEx(
+		cv::morphologyEx(
 			b_img, 
 			m_binImg, 
-			MORPH_OPEN,
+			cv::MORPH_OPEN,
 			kernel,
-			Point(-1,-1),
+			cv::Point(-1,-1),
 			m_cparam.sc_morph_iteration
 			);
 	}	
@@ -414,7 +414,7 @@ void CScionCutPoint::get_stem_local_img(
 	int& stem_y_min,
 	vector<int>& hist_col,
 	vector<int>& hist_row,
-	Mat& scionBinImg
+	cv::Mat& scionBinImg
 	)
 {
 	//1 夹子被罩上背景板,不能以高亮夹子定位
@@ -479,15 +479,15 @@ void CScionCutPoint::get_stem_local_img(
 	
 	//2	
 	if(m_cparam.image_show){
-		Mat grayimg = m_grayImg.clone();
-		rectangle(grayimg,
-			Point(x0,grayimg.rows-stem_y_min),
-			Point(x1,grayimg.rows-stem_y_max),
-			Scalar(128));
+		cv::Mat grayimg = m_grayImg.clone();
+		cv::rectangle(grayimg,
+			cv::Point(x0,grayimg.rows-stem_y_min),
+			cv::Point(x1,grayimg.rows-stem_y_max),
+			cv::Scalar(128));
 		imshow_wait("gray_rect",grayimg);
 	}
 
-	Mat scionImg = m_grayImg(Rect(x0,
+	cv::Mat scionImg = m_grayImg(cv::Rect(x0,
 		m_grayImg.rows-stem_y_min,
 		x1-x0,
 		stem_y_min-stem_y_max));
@@ -502,13 +502,13 @@ void CScionCutPoint::get_stem_local_img(
 	}
 	
 	//Mat scionBinImg;
-	double th = threshold(scionImg, scionBinImg, 255, 255,THRESH_OTSU);	
+	double th = threshold(scionImg, scionBinImg, 255, 255, cv::THRESH_OTSU);
 	if(m_cparam.image_show){
 	   imshow_wait("scion_sub_bin",scionBinImg);
 	   vector<int>hist;
 	   mat_histogram(scionBinImg,hist,1);
-	   Mat hist_col_img;
-		hist2image(hist,hist_col_img,1,m_cparam.image_col_grid,m_cparam.image_row_grid);		
+	   cv::Mat hist_col_img;
+	   hist2image(hist,hist_col_img,1,m_cparam.image_col_grid,m_cparam.image_row_grid);
 		imshow_wait("sc_sub_hist_col", hist_col_img);
 	}
 	//3

+ 6 - 6
cut_point_sc.h

@@ -6,7 +6,7 @@
 #include "logger.h"
 #include "imstorage_manager.h"
 
-using namespace cv;
+//using namespace cv;
 
 namespace graft_cv{
 class CScionCutPoint{
@@ -15,14 +15,14 @@ class CScionCutPoint{
 		~CScionCutPoint();
 		int up_point_detect(
 			ImgInfo*, 
-			Mat&, 
+			cv::Mat&,
             PositionInfo& posinfo
 			);
 		void set_image_saver(CImStoreManager** ppis){m_ppImgSaver=ppis;}
 
 private:	
-	Mat m_binImg;// binary image
-	Mat m_grayImg;//gray image
+	cv::Mat m_binImg;// binary image
+	cv::Mat m_grayImg;//gray image
 	string m_imgId;
 	CImStoreManager**m_ppImgSaver;
 	//·µ»ØÍ¼Æ¬£¬ÓÃÓÚµ÷ÊÔ
@@ -32,7 +32,7 @@ private:
 	ConfigParam& m_cparam;//global configure parameters
 	CGcvLogger* m_pLogger;
 	// image segment
-	void img_segment(Mat&);	
+	void img_segment(cv::Mat&);
 	
 	void get_stem_local_img(
 		const std::vector<int>& hist,		
@@ -42,7 +42,7 @@ private:
 		int& stem_y_min,
 		vector<int>& hist_col,
 		vector<int>& hist_row,
-		Mat& scionBinImg
+		cv::Mat& scionBinImg
 	);
 		
 	void get_cut_up_point(

+ 22 - 22
fork_rs.cpp

@@ -21,53 +21,53 @@ namespace graft_cv{
 	}
 
 	double CForkDetectOptimal::center_pt_index(
-		const Mat& binimg, 
-		Point&cent, 
+		const cv::Mat& binimg,
+		cv::Point&cent,
 		double cut_angle //刀具切割角度
 		)
 	{
 		double ratio = 0.0;
-		 RotatedRect centers_rect = RotatedRect(Point2f(0,0), Size2f(m_roi_width,m_roi_height), -cut_angle);//换算成顺时针角度
-		 Point2f vertices[4];
+		cv::RotatedRect centers_rect = cv::RotatedRect(cv::Point2f(0,0), cv::Size2f(m_roi_width,m_roi_height), -cut_angle);//换算成顺时针角度
+		cv::Point2f vertices[4];
 		 centers_rect.points(vertices);
 
-		 Point2f left_cent  = Point2f(cent.x + vertices[0].x, cent.y + vertices[0].y);
-		 Point2f right_cent = Point2f(cent.x + vertices[1].x, cent.y + vertices[1].y);
-		 RotatedRect left_rect = RotatedRect(left_cent,   Size2f(m_roi_width,m_roi_height), -cut_angle);
-		 RotatedRect right_rect = RotatedRect(right_cent, Size2f(m_roi_width,m_roi_height), -cut_angle);
+		 cv::Point2f left_cent  = cv::Point2f(cent.x + vertices[0].x, cent.y + vertices[0].y);
+		 cv::Point2f right_cent = cv::Point2f(cent.x + vertices[1].x, cent.y + vertices[1].y);
+		 cv::RotatedRect left_rect = cv::RotatedRect(left_cent, cv::Size2f(m_roi_width,m_roi_height), -cut_angle);
+		 cv::RotatedRect right_rect = cv::RotatedRect(right_cent, cv::Size2f(m_roi_width,m_roi_height), -cut_angle);
 
 		 double left_cnt = roi_object_size(binimg, left_rect);
 		 double right_cnt = roi_object_size(binimg, right_rect);
 		 ratio = left_cnt* left_cnt/right_cnt/(m_roi_width*m_roi_height);
 
 		 //imshow
-		 Mat tmp_img = binimg.clone();
-		 Point2f vertices_left[4];
-		 Point2f vertices_right[4];
+		 cv::Mat tmp_img = binimg.clone();
+		 cv::Point2f vertices_left[4];
+		 cv::Point2f vertices_right[4];
 		 left_rect.points(vertices_left);
 		 right_rect.points(vertices_right);
 		 for (int i = 0; i < 4; i++){
-			line(tmp_img, vertices_left[i], vertices_left[(i+1)%4], Scalar(128,255,0), 1);
-			line(tmp_img, vertices_right[i], vertices_right[(i+1)%4], Scalar(200,255,0), 1);
+			 cv::line(tmp_img, vertices_left[i], vertices_left[(i+1)%4], cv::Scalar(128,255,0), 1);
+			 cv::line(tmp_img, vertices_right[i], vertices_right[(i+1)%4], cv::Scalar(200,255,0), 1);
 		 }
-		 circle(tmp_img,cent,5,Scalar(128,0,0));
+		 circle(tmp_img,cent,5, cv::Scalar(128,0,0));
 
 		 return ratio;
 	}
 
 	double CForkDetectOptimal::roi_object_size(
-		const Mat& binimg, 
-		RotatedRect &rrect)
+		const cv::Mat& binimg,
+		cv::RotatedRect &rrect)
 	{
 		double cnt = 1.0;
-		Rect brect = rrect.boundingRect();	
-		Point2f vertices[4];
+		cv::Rect brect = rrect.boundingRect();
+		cv::Point2f vertices[4];
 		rrect.points(vertices);
 
 		//Mat tmp_img = Mat::zeros(binimg.rows,binimg.cols,CV_8UC1);
 		for(int r = brect.y; r<brect.y+brect.height;++r){
 			for(int c=brect.x; c<brect.x+brect.width;++c){
-				Point2f ptf = Point2f(c,r);
+				cv::Point2f ptf = cv::Point2f(c,r);
 				bool isin = is_in_rrect(vertices,ptf, rrect.angle);
 				if(isin){
 					//tmp_img.at<unsigned char>(r,c) = 255;
@@ -80,11 +80,11 @@ namespace graft_cv{
 		return cnt;		 
 	}
 	bool CForkDetectOptimal::is_in_rrect(
-		Point2f* ptf4,
-		Point2f ptf, 
+		cv::Point2f* ptf4,
+		cv::Point2f ptf,
 		float fAngle)
 	{
-		Point2f ptf4Vector[4];
+		cv::Point2f ptf4Vector[4];
 		int nQuadrant[4] = {0};
 		fAngle *= CV_PI/180 *(-1);
 

+ 4 - 4
fork_rs.h

@@ -2,7 +2,7 @@
 
 #include <opencv2\imgproc\imgproc.hpp>
 
-using namespace cv;
+//using namespace cv;
 
 namespace graft_cv{
 	// CForkDetectOptimalÀàʵÏÖÓÅ»¯
@@ -18,14 +18,14 @@ namespace graft_cv{
 		CForkDetectOptimal(int w, int h);
 		~CForkDetectOptimal();
 
-		double center_pt_index(const Mat& binimg, Point&cent, double cut_angle);
+		double center_pt_index(const cv::Mat& binimg, cv::Point&cent, double cut_angle);
 		void set_roi_size(int w, int h);
 		void get_roi_size(int &w, int &h);
 	private:
 		int m_roi_width;
 		int m_roi_height;
 
-		double roi_object_size(const Mat& binimg, RotatedRect &rrect);
-		bool is_in_rrect(Point2f* ptf4,Point2f ptf, float fAngle);
+		double roi_object_size(const cv::Mat& binimg, cv::RotatedRect &rrect);
+		bool is_in_rrect(cv::Point2f* ptf4, cv::Point2f ptf, float fAngle);
 	};
 };

+ 14 - 13
graft_cv_api.cpp

@@ -16,7 +16,8 @@
 extern CRITICAL_SECTION g_cs;
 namespace graft_cv
 {
-	char *g_version_str = "0.6.0";
+
+	char *g_version_str = "0.6.1";
 
 	//configure
 	string g_conf_file = "./gcv_conf.yml";	
@@ -42,7 +43,7 @@ namespace graft_cv
 	CScionCutPoint g_sc_cp = CScionCutPoint(g_cp,&g_logger);
 
 	//
-	map<string, Mat> g_img_cache;
+	map<string, cv::Mat> g_img_cache;
 	
 
 	//0 log path
@@ -158,7 +159,7 @@ namespace graft_cv
 			ifs.close();
 			memset(&g_cp,0,sizeof(ConfigParam));
 
-			FileStorage fs(conf, FileStorage::READ);
+			cv::FileStorage fs(conf, cv::FileStorage::READ);
 			conf_contrainer.read(fs["conf_parameters"]);	
 			fs.release();
 			g_conf_file = conf;
@@ -172,7 +173,7 @@ namespace graft_cv
 			memset(&g_cp,0,sizeof(ConfigParam));
 			
 			//read configures
-			FileStorage fs(g_conf_file, FileStorage::READ);
+			cv::FileStorage fs(g_conf_file, cv::FileStorage::READ);
 			conf_contrainer.read(fs["conf_parameters"]);	
 			fs.release();
 			
@@ -197,18 +198,18 @@ namespace graft_cv
 		CGCvConfig conf_contrainer = CGCvConfig();
 		conf_contrainer.setConfParam(&g_cp);
 		if(conf_file){
-			FileStorage fs(
+			cv::FileStorage fs(
 				conf_file,
-				FileStorage::WRITE
+				cv::FileStorage::WRITE
 				);
 			fs<<"conf_parameters";	
 			fs<<conf_contrainer;		
 			fs.release();	
 		}
 		else{
-			FileStorage fs(
+			cv::FileStorage fs(
 				g_conf_file, 
-				FileStorage::WRITE
+				cv::FileStorage::WRITE
 				);
 			fs<<"conf_parameters";	
 			fs<<conf_contrainer;		
@@ -223,13 +224,13 @@ namespace graft_cv
 	//5
 	void get_version(char* buf)
 	{			
-		strcpy(buf, g_version_str);
+		strcpy_s(buf, strlen(g_version_str)+1,g_version_str);
 	};
 	
 	//6
 	void cv_get_conf_file(char*buff)
 	{
-		strcpy(buff, g_conf_file.c_str());
+		strcpy_s(buff, g_conf_file.size()+1, g_conf_file.c_str());
 	};
 
 	//7
@@ -300,7 +301,7 @@ namespace graft_cv
 		try{
 			g_rs_cp.up_point_detect(
 				imginfo,
-				Mat(),
+				cv::Mat(),
 				posinfo, 
 				g_img_cache
 				);
@@ -328,7 +329,7 @@ namespace graft_cv
 		try{
 			g_rs_cp_reid.cut_point_reid(
 				imginfo,
-				Mat(),
+				cv::Mat(),
 				pre_img_id,
 				posinfo,
 				g_img_cache
@@ -359,7 +360,7 @@ namespace graft_cv
 		try{
 			g_sc_cp.up_point_detect(
 				imginfo,
-				Mat(),
+				cv::Mat(),
 				posinfo
 				);
 		}

+ 3 - 3
imstorage_manager.cpp

@@ -150,7 +150,7 @@ void CImStoreManager::restart_start_worker()
 }
 int CImStoreManager::setStoreDir(string& folder)
 {
-	int stat = access(folder.c_str(),0);
+	int stat = _access(folder.c_str(),0);
 	if (stat==0){
 		m_storeDir = folder;
 		g_thread_run=false;
@@ -175,12 +175,12 @@ void CImStoreManager::setStoreDays(int days)
 }
 bool CImStoreManager::is_valid_folder()
 {
-	int stat = access(m_storeDir.c_str(),0);
+	int stat = _access(m_storeDir.c_str(),0);
 	if(stat==0){return true;}
 	else{return false;}
 }
 
-int CImStoreManager::saveImage(Mat&img,string name_id)
+int CImStoreManager::saveImage(cv::Mat&img,string name_id)
 {	
 	if(!is_valid_folder()){return 1;}
 	if(img.empty()){return 1;}

+ 3 - 3
imstorage_manager.h

@@ -5,7 +5,7 @@
 #include <windows.h>
 #include <queue> 
 
-using namespace cv;
+//using namespace cv;
 using namespace std;
 //namespace graft_cv
 //{
@@ -13,7 +13,7 @@ using namespace std;
 typedef struct
 {
 	string img_name;
-	Mat image;
+	cv::Mat image;
 } ImgParam;
 
 typedef struct 
@@ -46,7 +46,7 @@ public:
 	void getStoreDir(string& folder);
 	void setStoreDays(int days);
 	//saveImage() return 0--ok, 1 -- invalid image or folder
-	int saveImage(Mat&img,string name_id);
+	int saveImage(cv::Mat&img,string name_id);
 	void restart_start_worker();
 
 

+ 49 - 49
optimal_angle.cpp

@@ -842,7 +842,7 @@ int CCotyledonAngle::angle_recognize(
 	)
 {
 	//clear opencv windows
-	if(m_cparam.image_show){destroyAllWindows();}
+	if(m_cparam.image_show){ cv::destroyAllWindows();}
 
 	clock_t t;
 	clock_t t0 = clock();	
@@ -864,7 +864,7 @@ int CCotyledonAngle::angle_recognize(
 			<<"\theight="<<imginfo->height;
 		m_pLogger->INFO(buff.str());
 	}
-	Mat img = imginfo2mat(imginfo);
+	cv::Mat img = imginfo2mat(imginfo);
 
 
 
@@ -884,7 +884,7 @@ int CCotyledonAngle::angle_recognize(
 		}
 	}
 	if(m_cparam.oa_y_flip){
-		flip(img,img,0);
+		cv::flip(img,img,0);
 		if(m_pLogger){				
 			m_pLogger->DEBUG(m_imgId+" oa_recognize image y fliped.");				
 		}
@@ -896,7 +896,7 @@ int CCotyledonAngle::angle_recognize(
 		}
 	}
 	if(m_cparam.image_show){
-		Mat tmp_b = img.clone();			
+		cv::Mat tmp_b = img.clone();
 		imshow_wait("oa_image", tmp_b);
 	}
 
@@ -905,20 +905,20 @@ int CCotyledonAngle::angle_recognize(
 	if(m_cparam.image_show){					
 		imshow_wait("oa_image_bin", m_binImg);
 	}
-	Mat img_median, img_base, img_open, img_xor;
+	cv::Mat img_median, img_base, img_open, img_xor;
 	cv::medianBlur(m_binImg,img_median, 5);	
 
-	Mat kernel = getStructuringElement(
-			MORPH_ELLIPSE,
-			Size( 2*m_cparam.oa_morph_radius + 1, 2*m_cparam.oa_morph_radius+1),
-			Point( m_cparam.oa_morph_radius, m_cparam.oa_morph_radius)
+	cv::Mat kernel = cv::getStructuringElement(
+		cv::MORPH_ELLIPSE,
+		cv::Size( 2*m_cparam.oa_morph_radius + 1, 2*m_cparam.oa_morph_radius+1),
+		cv::Point( m_cparam.oa_morph_radius, m_cparam.oa_morph_radius)
 			);  
-	morphologyEx(
+	cv::morphologyEx(
 		img_median,
 		img_base,
-		MORPH_CLOSE,
+		cv::MORPH_CLOSE,
 		kernel,
-		Point(-1,-1),
+		cv::Point(-1,-1),
 		1);
 
 	if(m_cparam.image_show){					
@@ -930,18 +930,18 @@ int CCotyledonAngle::angle_recognize(
 	int iter_open = 10;
 	
 	double leaf_area_th = (double)m_cparam.oa_min_leaf_area;
-	vector<vector<Point>> contours;
-	vector<Vec4i> hierarchy;
+	vector<vector<cv::Point>> contours;
+	vector<cv::Vec4i> hierarchy;
 	vector<t_leaf> leafs;
 
 	while( iter_open >0 && iter_open < 50){
 
-		morphologyEx(
+		cv::morphologyEx(
 			img_base,
 			img_open,
-			MORPH_OPEN,
+			cv::MORPH_OPEN,
 			kernel,
-			Point(-1,-1),
+			cv::Point(-1,-1),
 			iter_open);
 		if(m_cparam.image_show){
 			imshow_wait("img_base", img_base);
@@ -952,12 +952,12 @@ int CCotyledonAngle::angle_recognize(
 		contours.clear();
 		hierarchy.clear();
 		leafs.clear();
-		findContours(img_open,contours,hierarchy,RETR_EXTERNAL,CHAIN_APPROX_NONE);
+		findContours(img_open,contours,hierarchy, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_NONE);
 		for(int i=0;i<contours.size();++i){
 			double area = contourArea(contours[i]);
 			if (area < leaf_area_th){continue;}			
-			RotatedRect minrect_ellips = fitEllipse(contours[i]);
-			Moments moment = moments(contours[i]);
+			cv::RotatedRect minrect_ellips = fitEllipse(contours[i]);
+			cv::Moments moment = moments(contours[i]);
 			double centx = moment.m10 / moment.m00;
 			double centy = moment.m01 / moment.m00;
 
@@ -1033,17 +1033,17 @@ int CCotyledonAngle::angle_recognize(
 	rot_angle -= 180;//ÐèÒªÐýתµÄ½Ç¶È
 
 	//draw image
-	Mat ellipse_img = m_openImg.clone();
+	cv::Mat ellipse_img = m_openImg.clone();
 	for(size_t j=0; j<leafs.size(); ++j){
 		stringstream buff;
 		buff<<"wa="<<(float)((int)(leafs[j].minrect_ellips.angle*10.0)/10.0);	
-		Scalar color = Scalar(100);
+		cv::Scalar color = cv::Scalar(100);
 		if(j == min_err_idx){
 			color[0] = 180;
 			buff<<",rot="<<(float)((int)(rot_angle*10.0)/10.0);
 		}
 			
-		Point2f vertices[4];
+		cv::Point2f vertices[4];
 		leafs[j].minrect_ellips.points(vertices);
 		for (int i = 0; i < 4; i++)
 			line(ellipse_img, vertices[i], vertices[(i+1)%4], color);
@@ -1086,8 +1086,8 @@ int CCotyledonAngle::angle_recognize(
 	return 0;
 }
 double CCotyledonAngle::fit_error_ellipse(
-	RotatedRect& ellipse_rect,
-	vector<Point>& pts)
+	cv::RotatedRect& ellipse_rect,
+	vector<cv::Point>& pts)
 {
 	/*
 	  ref:https://blog.csdn.net/fangyan90617/article/details/89486331
@@ -1117,7 +1117,7 @@ double CCotyledonAngle::fit_error_ellipse(
 	return mean_err;	
 }
 void CCotyledonAngle::get_ellipse_param(
-	RotatedRect&ellipse_rect,
+	cv::RotatedRect&ellipse_rect,
 	float&A, 
 	float&B, 
 	float&C, 
@@ -1131,7 +1131,7 @@ void CCotyledonAngle::get_ellipse_param(
 	C = a * a * cos(theta) * cos(theta) + b * b * sin(theta) * sin(theta);
     F = (-1.0) * a * a * b * b;
 }
-void CCotyledonAngle::img_segment(Mat&img)
+void CCotyledonAngle::img_segment(cv::Mat&img)
 {
 	if(img.channels()!=1){
 		//color image ,bgr, for testing
@@ -1147,17 +1147,17 @@ void CCotyledonAngle::img_segment(Mat&img)
 	
 		b_img/= 255;*/
 
-		Mat img_hsv, b_img_hsv;		
-		cvtColor(
+		cv::Mat img_hsv, b_img_hsv;
+		cv::cvtColor(
 			img, 
 			img_hsv,
-			COLOR_BGR2HSV
+			cv::COLOR_BGR2HSV
 			);
 
-		inRange(
+		cv::inRange(
 			img_hsv,
-			Scalar(30 , 30, 30),
-			Scalar(75, 255, 255),
+			cv::Scalar(30 , 30, 30),
+			cv::Scalar(75, 255, 255),
 			b_img_hsv
 			);
 
@@ -1166,17 +1166,17 @@ void CCotyledonAngle::img_segment(Mat&img)
 		b_img = b_img.mul(b_img_hsv);	*/
 
 		//int morph_size = 1;
-		Mat kernel = getStructuringElement(
-			MORPH_RECT,
-			Size( 2*m_cparam.oa_morph_radius + 1, 2*m_cparam.oa_morph_radius+1),
-			Point( m_cparam.oa_morph_radius, m_cparam.oa_morph_radius)
+		cv::Mat kernel = getStructuringElement(
+			cv::MORPH_RECT,
+			cv::Size( 2*m_cparam.oa_morph_radius + 1, 2*m_cparam.oa_morph_radius+1),
+			cv::Point( m_cparam.oa_morph_radius, m_cparam.oa_morph_radius)
 			);  
-		morphologyEx(
+		cv::morphologyEx(
 			b_img_hsv,
 			m_binImg,
-			MORPH_CLOSE,
+			cv::MORPH_CLOSE,
 			kernel,
-			Point(-1,-1),
+			cv::Point(-1,-1),
 			m_cparam.oa_morph_iteration);
 		
 	}
@@ -1184,20 +1184,20 @@ void CCotyledonAngle::img_segment(Mat&img)
 		//from imginfo image, gray image 
 		//int morph_size = 1;	
 
-		Mat b_img;
+		cv::Mat b_img;
 		m_grayImg = img.clone();
-		double th = threshold(img, b_img, 255, 255,THRESH_OTSU);
-		Mat kernel = getStructuringElement( 
-			MORPH_RECT, 
-			Size( 2*m_cparam.oa_morph_radius + 1, 2*m_cparam.oa_morph_radius+1 ), 
-			Point( m_cparam.oa_morph_radius, m_cparam.oa_morph_radius)
+		double th = threshold(img, b_img, 255, 255, cv::THRESH_OTSU);
+		cv::Mat kernel = getStructuringElement(
+			cv::MORPH_RECT,
+			cv::Size( 2*m_cparam.oa_morph_radius + 1, 2*m_cparam.oa_morph_radius+1 ),
+			cv::Point( m_cparam.oa_morph_radius, m_cparam.oa_morph_radius)
 			);    
-		morphologyEx(
+		cv::morphologyEx(
 			b_img, 
 			m_binImg, 
-			MORPH_OPEN,
+			cv::MORPH_OPEN,
 			kernel,
-			Point(-1,-1),
+			cv::Point(-1,-1),
 			m_cparam.oa_morph_iteration
 			);
 	}	

+ 9 - 9
optimal_angle.h

@@ -7,7 +7,7 @@
 #include "imstorage_manager.h"
 
 using namespace std;
-using namespace cv;
+//using namespace cv;
 
 namespace graft_cv{
 
@@ -150,11 +150,11 @@ protected:
 
 
 	//all image size
-	Mat m_grayImg;
-	Mat m_binImg;
+	cv::Mat m_grayImg;
+	cv::Mat m_binImg;
 	int m_width;
 	int m_height;
-	Mat m_openImg; // for save	
+	cv::Mat m_openImg; // for save	
 
 	//·µ»ØÍ¼Æ¬£¬ÓÃÓÚµ÷ÊÔ
 	ImgInfo* m_pImginfoOpen;//fork-y, right-x
@@ -166,13 +166,13 @@ protected:
 		double area;
 		double centx;
 		double centy;		
-		RotatedRect minrect_ellips;
-		vector<Point> contours;
+		cv::RotatedRect minrect_ellips;
+		vector<cv::Point> contours;
 	} t_leaf;
 
-	void img_segment(Mat&img);
-	double fit_error_ellipse(RotatedRect&ellipse_rect,vector<Point>& pts);
-	void get_ellipse_param(RotatedRect&ellipse_rect,   //input
+	void img_segment(cv::Mat&img);
+	double fit_error_ellipse(cv::RotatedRect&ellipse_rect,vector<cv::Point>& pts);
+	void get_ellipse_param(cv::RotatedRect&ellipse_rect,   //input
 		float&A, float&B, float&C, float&F); //output
 	void clear_imginfo();
 };

+ 5 - 5
stdafx.cpp

@@ -1,8 +1,8 @@
-// stdafx.cpp : 只包括标准包含文件的源文件
-// demo.pch 将作为预编译头
-// stdafx.obj 将包含预编译类型信息
+// stdafx.cpp : source file that includes just the standard includes
+// graft_cv.pch will be the pre-compiled header
+// stdafx.obj will contain the pre-compiled type information
 
 #include "stdafx.h"
 
-// TODO: 在 STDAFX.H 中
-// 引用任何所需的附加头文件,而不是在此文件中引用
+// TODO: reference any additional headers you need in STDAFX.H
+// and not in this file

+ 4 - 4
stdafx.h

@@ -1,6 +1,6 @@
-// stdafx.h : 标准系统包含文件的包含文件,
-// 或是经常使用但不常更改的
-// 特定于项目的包含文件
+// stdafx.h : include file for standard system include files,
+// or project specific include files that are used frequently, but
+// are changed infrequently
 //
 
 #pragma once
@@ -12,4 +12,4 @@
 
 
 
-// TODO: 在此处引用程序需要的其他头文件
+// TODO: reference additional headers your program requires here

+ 3 - 3
targetver.h

@@ -1,8 +1,8 @@
 #pragma once
 
-// 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。
+// Including SDKDDKVer.h defines the highest available Windows platform.
 
-// 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将
-// WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。
+// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
+// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
 
 #include <SDKDDKVer.h>

+ 61 - 59
utils.cpp

@@ -7,11 +7,11 @@
 
 namespace graft_cv{
 
-	Mat imginfo2mat(ImgInfo* imginfo)
+	cv::Mat imginfo2mat(ImgInfo* imginfo)
 	{
 		assert(imginfo->data);
 		assert(imginfo->height>0 && imginfo->width>0);
-		Mat m = Mat(imginfo->height,imginfo->width,CV_8UC1);
+		cv::Mat m = cv::Mat(imginfo->height,imginfo->width,CV_8UC1);
 		for(int h=0; h<imginfo->height; ++h)
 		{
 			memcpy((void*)(m.ptr(h)),
@@ -21,7 +21,7 @@ namespace graft_cv{
 		return m;
 	};
 
-	ImgInfo* mat2imginfo(const Mat&img){
+	ImgInfo* mat2imginfo(const cv::Mat&img){
 		assert(img.channels()==1);
 		ImgInfo* imginfo = new ImgInfo();
 		imginfo->angle=0;
@@ -55,7 +55,7 @@ namespace graft_cv{
 	}
 
 	void image_set_bottom(
-		Mat& img,
+		cv::Mat& img,
 		unsigned char value,
 		int rows_cnt)
 	{
@@ -66,7 +66,7 @@ namespace graft_cv{
 		}
 	}
 	void image_set_top(
-		Mat& img,
+		cv::Mat& img,
 		unsigned char value,
 		int rows_cnt)
 	{
@@ -78,11 +78,11 @@ namespace graft_cv{
 	}
 
 	void image_draw_line(
-		Mat& img,
+		cv::Mat& img,
 		int x0,int y0,
 		int x1,int y1)
 	{
-		Point p0,p1;
+		cv::Point p0,p1;
 		if(x0==x1){
 			p0.x=x0;
 			p0.y=0;
@@ -99,18 +99,19 @@ namespace graft_cv{
 			p1.x=img.cols;
 			p1.y = (int)(b + k * p1.x);
 		}
-		line(img,p0,p1,Scalar(255,255,255));
+		cv::line(img,p0,p1, cv::Scalar(255,255,255));
 	
 	}
 	string currTime(){
 			char tmp[64];
-			time_t ptime;
-			time(&ptime);
+			struct tm ptime;
+			time_t time_seconds = time(0);
+			localtime_s(&ptime, &time_seconds);
 			strftime(
 				tmp, 
 				sizeof(tmp), 
 				"%Y-%m-%d %H:%M:%S",
-				localtime(&ptime)
+				&ptime
 				);
 			return tmp;
 		}
@@ -120,13 +121,14 @@ namespace graft_cv{
 	string getImgId(int im_type)
 	{
 		char tmp[64];
-		time_t ptime;
-		time(&ptime);
+		struct tm ptime;
+		time_t time_seconds = time(0);
+		localtime_s(&ptime, &time_seconds);
 		strftime(
 			tmp, 
 			sizeof(tmp), 
 			"%Y%m%d%H%M%S",
-			localtime(&ptime)
+			&ptime
 			);
 
 		unsigned int id_serial = ID_COUNTER % 100;	
@@ -153,7 +155,7 @@ namespace graft_cv{
 		}
 
 	void drawgrid(		
-			Mat&img,		
+			cv::Mat&img,		
 			int grid_col/*=50*/,
 			int grid_row/*=50*/,
 			int line_thick/*=2*/
@@ -162,17 +164,17 @@ namespace graft_cv{
 		if(img.empty()){return;}
 		//horizontal grid
 		for(int row=img.rows-1; row>=0; row-=grid_row){
-			line(img,Point(0,row),Point(img.cols-1,row),Scalar(100),line_thick);
+			cv::line(img, cv::Point(0,row), cv::Point(img.cols-1,row), cv::Scalar(100),line_thick);
 		}
 		//veritcal grid
 		for(int col=0; col<img.cols; col+=grid_col){
-			line(img,Point(col,0),Point(col,img.rows-1),Scalar(100),line_thick);
+			cv::line(img, cv::Point(col,0), cv::Point(col,img.rows-1), cv::Scalar(100),line_thick);
 		}
 
 	}
 	void hist2image(
 		vector<int>& hist, 
-		Mat&img, 
+		cv::Mat&img,
 		int aix, /*=1*/
 		int grid_col/*=50*/,
 		int grid_row/*=50*/
@@ -183,7 +185,7 @@ namespace graft_cv{
 		if( grid_row<10){grid_row=10;}
 		// aix = 0, column hist, aix=1, row histogtam
 		if (aix==0){
-			img = Mat::zeros(hist.size(),*maxit, CV_8UC1);
+			img = cv::Mat::zeros(hist.size(),*maxit, CV_8UC1);
 			drawgrid(img,grid_col, grid_row,1);
 			for(size_t i=0; i<hist.size();++i){
 				if(i>=img.rows){break;}
@@ -194,7 +196,7 @@ namespace graft_cv{
 			}
 		}
 		else{
-			img = Mat::zeros(*maxit,hist.size(), CV_8UC1);
+			img = cv::Mat::zeros(*maxit,hist.size(), CV_8UC1);
 			drawgrid(img,grid_col, grid_row,1);
 			for(size_t i=0; i<hist.size();++i){
 				int y = *maxit-hist[i]-1;
@@ -211,7 +213,7 @@ namespace graft_cv{
 	// axis == 0, statistic histogram for columns; 
 	// others, statistic histogram for rows
 	void mat_histogram(
-		Mat& img,	
+		cv::Mat& img,
 		std::vector<int>&hist,
 		int axis,
 		int r0, 
@@ -251,7 +253,7 @@ namespace graft_cv{
 	// others, statistic histogram for rows
 	// with weight
 	void mat_histogram_w(
-		Mat& img,	
+		cv::Mat& img,
 		std::vector<int>&hist,
 		int axis,
 		int r0, 
@@ -318,7 +320,7 @@ namespace graft_cv{
 	};
 
 	void mat_histogram_yfork(
-		Mat& img,	
+		cv::Mat& img,
 		std::vector<int>&hist,	
 		int r0, 
 		int r1	
@@ -948,7 +950,7 @@ namespace graft_cv{
 			if(mean>max_m){max_m = mean;}
 			reversed_mean.push_back(mean);
 		}
-		Mat tmp;
+		cv::Mat tmp;
 		hist2image_scale_line(reversed_mean,tmp,min_m,max_m,1.0,min_m,50,50);
 		imshow_wait("mean5",tmp);
 		return;
@@ -1177,7 +1179,7 @@ namespace graft_cv{
 		fork_y = hist.size() - max_idx_y;
 	};
 	void get_stem_y_fork_rs_update(
-		const Mat& bin_img,
+		const cv::Mat& bin_img,
 		int stem_x_padding,
 		int x0,
 		int x1,
@@ -1186,7 +1188,7 @@ namespace graft_cv{
 		int stem_dia,
 		bool image_show,
 		double cut_point_offset_ratio,
-		Point& fork_cent,
+		cv::Point& fork_cent,
 		double& max_radius,
 		double& stem_angle
 		)
@@ -1241,7 +1243,7 @@ namespace graft_cv{
 		// x = beta0 + beta1 * y
 		double r2 = r2index(cent_ys,cent_xs,0,cent_xs.size()-1, beta0, beta1);
 		double th = (double)stem_dia/2.0 + stem_x_padding;
-		Mat roi_img = bin_img.clone();
+		cv::Mat roi_img = bin_img.clone();
 
 		//提取兴趣区域图片
 		stem_angle = atan(beta1)*57.2957795130 + 90.0;
@@ -1270,22 +1272,22 @@ namespace graft_cv{
 		////////////////////////////////////////////////////////////
 		//
 		if(image_show){
-			Mat tmp = roi_img.clone();
-			Point p0((int)(beta0),0);
-			Point p1((int)((double)tmp.rows *beta1 +beta0),tmp.rows);
-			line(tmp,p0,p1,Scalar(128,0,0));
+			cv::Mat tmp = roi_img.clone();
+			cv::Point p0((int)(beta0),0);
+			cv::Point p1((int)((double)tmp.rows *beta1 +beta0),tmp.rows);
+			cv::line(tmp,p0,p1, cv::Scalar(128,0,0));
 
-			line(tmp,Point(cent_xs[0],cent_ys[0]),
-				Point(cent_xs.back(),cent_ys.back()),Scalar(128,0,0));
+			cv::line(tmp, cv::Point(cent_xs[0],cent_ys[0]),
+				cv::Point(cent_xs.back(),cent_ys.back()), cv::Scalar(128,0,0));
 	
 
 			imshow_wait("rs_bin_roi", tmp);	
 		}
 		///////////////////////////////////////////////////////////
 		//兴趣区域图片findContours
-		vector<vector<Point>> contours;
-		vector<Vec4i> hierarchy;
-		findContours(roi_img,contours,hierarchy,RETR_EXTERNAL,CHAIN_APPROX_NONE);
+		vector<vector<cv::Point>> contours;
+		vector<cv::Vec4i> hierarchy;
+		findContours(roi_img,contours,hierarchy, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_NONE);
 		//找到周长最长的区域作为目标区域
 		int max_length_idx = 0;
 		int max_length_val = contours[0].size();
@@ -1392,7 +1394,7 @@ namespace graft_cv{
 				xs.push_back(xi);
 				continue;
 			}
-			float d = pointPolygonTest( contours[max_length_idx], Point2f(x,r), true );			
+			float d = cv::pointPolygonTest( contours[max_length_idx], cv::Point2f(x,r), true );
 			if(d<0){
 				inner_max_radius.push_back(0.0);
 				nnindex.push_back(-1);
@@ -1449,9 +1451,9 @@ namespace graft_cv{
 		///////////////////////////////////////////////
 		//test
 		if(image_show){
-			Mat edge;
-			edge = Mat::zeros(roi_img.rows, roi_img.cols, CV_8UC1);
-			drawContours(edge, contours, -1, Scalar(255, 255, 0), 1);			
+			cv::Mat edge;
+			edge = cv::Mat::zeros(roi_img.rows, roi_img.cols, CV_8UC1);
+			cv::drawContours(edge, contours, -1, cv::Scalar(255, 255, 0), 1);
 			for(int r=0;r<xs.size();++r){
 				int c = xs[r];
 				if(c<0){continue;}
@@ -1462,19 +1464,19 @@ namespace graft_cv{
 				line(edge,Point(c,r),contours_serial[nnindex[r]],Scalar(128,0,0));
 				*/
 				int rad = int(inner_max_radius[r]);
-				line(edge,Point(c-rad,r),Point(c+rad,r),Scalar(80,0,0));		
+				cv::line(edge, cv::Point(c-rad,r), cv::Point(c+rad,r), cv::Scalar(80,0,0));
 			}
-			Point fork_cent_origin;
+			cv::Point fork_cent_origin;
 			fork_cent_origin.x = xs[max_idx];
 			fork_cent_origin.y =max_idx;
-			circle(edge,fork_cent_origin,3,Scalar(200,0,0));
-			circle(edge,fork_cent_origin,(int)(max_radius),Scalar(200,0,0));
+			cv::circle(edge,fork_cent_origin,3, cv::Scalar(200,0,0));
+			cv::circle(edge,fork_cent_origin,(int)(max_radius), cv::Scalar(200,0,0));
 
 			//circle(edge,Point(xs[opt_max_idx],opt_max_idx),5,Scalar(200,0,0));
 
-			circle(edge,fork_cent,3,Scalar(128,0,0));
-			circle(edge,fork_cent,(int)(max_radius),Scalar(128,0,0));
-			imshow_wait("rs_bin_roi_radius_circle", edge);	
+			cv::circle(edge,fork_cent,3, cv::Scalar(128,0,0));
+			cv::circle(edge,fork_cent,(int)(max_radius), cv::Scalar(128,0,0));
+			imshow_wait("rs_bin_roi_radius_circle", edge);
 		}
 		///////////////////////////////////////////////   
 
@@ -1569,17 +1571,17 @@ namespace graft_cv{
 
 	void imshow_wait(
 		const char* winname,
-		Mat&img, 
+		cv::Mat&img,
 		int waittype/*=-1*/
 		)
 	{	
-		namedWindow(winname, CV_WINDOW_NORMAL);
-		imshow(winname, img);
-		waitKey(waittype);
+		cv::namedWindow(winname, cv::WINDOW_NORMAL);
+		cv::imshow(winname, img);
+		cv::waitKey(waittype);
 	};
 
 	int get_stem_fork_right(
-		Mat&stem_img, 
+		cv::Mat&stem_img,
 		int stem_fork_y, 
 		int stem_x0, 
 		int stem_x1,
@@ -1656,7 +1658,7 @@ namespace graft_cv{
 	};
 
 	int get_stem_fork_left(
-		Mat&stem_img, 
+		cv::Mat&stem_img,
 		int stem_fork_y, 
 		int stem_x0, 
 		int stem_x1,
@@ -1705,7 +1707,7 @@ namespace graft_cv{
 	}
 
 	void get_stem_fork_xs(
-		Mat&stem_img, 
+		cv::Mat&stem_img,
 		int stem_fork_y, 
 		int stem_x0, 
 		int stem_x1,	
@@ -1756,7 +1758,7 @@ namespace graft_cv{
 
 	// 根据边缘上的一点,爬取下一点
 	void get_next_pt(
-		Mat& edge_img,
+		cv::Mat& edge_img,
 		gcv_point<int>&start_pt, 
 		gcv_point<int>&pre_pt, 	
 		gcv_point<int>&nxt_pt,//output
@@ -1803,21 +1805,21 @@ namespace graft_cv{
 	{
 		double oa = 0.0;
 		// fit quadratic function with opencv
-		Mat A = cv::Mat::zeros(cv::Size(3,xx.size()), CV_64FC1);
+		cv::Mat A = cv::Mat::zeros(cv::Size(3,xx.size()), CV_64FC1);
 		for(int i=0; i<xx.size();++i){
 			A.at<double>(i,0) = 1;
 			A.at<double>(i,1) = xx[i];
 			A.at<double>(i,2) = xx[i] * xx[i];
 		}
 
-		Mat b = cv::Mat::zeros(cv::Size(1,yy.size()), CV_64FC1);
+		cv::Mat b = cv::Mat::zeros(cv::Size(1,yy.size()), CV_64FC1);
 		for(int i = 0; i<yy.size(); ++i){
 			b.at<double>(i,0) = yy[i];
 		}
-		Mat c, d;
+		cv::Mat c, d;
 		c = A.t() * A;
 		d = A.t() * b;
-		Mat result = cv::Mat::zeros(cv::Size(1,3),CV_64FC1);
+		cv::Mat result = cv::Mat::zeros(cv::Size(1,3),CV_64FC1);
 		cv::solve(c,d,result);
 	
 

+ 24 - 24
utils.h

@@ -9,14 +9,14 @@
 #include "data_def_api.h"
 #include "data_def.h"
 
-using namespace cv;
+//using namespace cv;
 using namespace std;
 
 namespace graft_cv{
 
 	// convert ImgInfo to cv mat 
-	Mat imginfo2mat(ImgInfo*);
-	ImgInfo* mat2imginfo(const Mat&);
+	cv::Mat imginfo2mat(ImgInfo*);
+	ImgInfo* mat2imginfo(const cv::Mat&);
 	void imginfo_release(ImgInfo**);
 	bool isvalid(const ImgInfo*);
 	string currTime();
@@ -25,12 +25,12 @@ namespace graft_cv{
 	inline void throw_msg(string& msg);
 
 	// set bottom image rows_cnt rows to "value", for xiaoxu camera
-	void image_set_bottom(Mat& img,unsigned char value,int rows_cnt);
-	void image_set_top(	Mat& img,	unsigned char value,	int rows_cnt);
-	void image_draw_line(Mat& img,int x0,int y0,int x1,int y1);
+	void image_set_bottom(cv::Mat& img,unsigned char value,int rows_cnt);
+	void image_set_top(cv::Mat& img,	unsigned char value,	int rows_cnt);
+	void image_draw_line(cv::Mat& img,int x0,int y0,int x1,int y1);
 	// histogram
 	void mat_histogram(
-		Mat&, 
+		cv::Mat&,
 		std::vector<int>&hist,
 		int axis=0, 
 		int r0=-1, 
@@ -40,7 +40,7 @@ namespace graft_cv{
 		);
 	// weighted histogram
 	void mat_histogram_w(
-		Mat& img,	
+		cv::Mat& img,
 		std::vector<int>&hist,
 		int axis=0,
 		int r0=-1, 
@@ -50,7 +50,7 @@ namespace graft_cv{
 		bool asc_w=true //true---ascending weight with x/y coordinate, [0-1.0], false --- descending weight [1.0--0.0]
 	);
 	void mat_histogram_yfork(
-		Mat& img,	
+		cv::Mat& img,
 		std::vector<int>&hist,	
 		int r0, 
 		int r1	
@@ -59,7 +59,7 @@ namespace graft_cv{
 	// histogram to image	
 	void hist2image(
 		vector<int>& hist,
-		Mat&img,
+		cv::Mat&img,
 		int aix=1,
 		int grid_col=50,
 		int grid_row=50
@@ -68,7 +68,7 @@ namespace graft_cv{
 	template<class T>
 	void hist2image_line(
 	vector<T>& hist, 
-	Mat&img, 	
+		cv::Mat&img,
 	int grid_col/*=50*/,
 	int grid_row/*=50*/
 	)
@@ -89,7 +89,7 @@ namespace graft_cv{
 	template<class T>
 	void hist2image_scale_line(
 	vector<T>& hist, 
-	Mat&img, 	
+		cv::Mat&img,
 	T ymin,
 	T ymax,
 	T yratio,//数值像素比,一个像素代表的数值量
@@ -103,22 +103,22 @@ namespace graft_cv{
 	if( grid_row<10){grid_row=10;}	
 	int height =(int)((ymax-ymin)/yratio);
 	
-	img = Mat::zeros(height,hist.size(), CV_8UC1);
+	img = cv::Mat::zeros(height,hist.size(), CV_8UC1);
 	drawgrid(img,grid_col, grid_row,1);
 	for(size_t i=1; i<hist.size();++i){
 		int y_1 = height-(int)((hist[i-1]-ymin)/yratio);
 		int y_0 = height-(int)((hist[i]-ymin)/yratio);
-		line(img,Point(i-1,y_1),Point(i,y_0),Scalar(255));
+		cv::line(img, cv::Point(i-1,y_1), cv::Point(i,y_0), cv::Scalar(255));
 	}
 	int h1 = height-(int)((th-ymin)/yratio);
 	int h2 = height-(int)((1.0/th-ymin)/yratio);
-	line(img,Point(0,h1),Point(hist.size()-1,h1),Scalar(200));
-	line(img,Point(0,h2),Point(hist.size()-1,h2),Scalar(200));
+	cv::line(img, cv::Point(0,h1), cv::Point(hist.size()-1,h1), cv::Scalar(200));
+	cv::line(img, cv::Point(0,h2), cv::Point(hist.size()-1,h2), cv::Scalar(200));
 	
 };
 
 	void drawgrid(		
-		Mat&img,		
+		cv::Mat&img,
 		int grid_col=50,
 		int grid_row=50,
 		int line_thick=1
@@ -228,7 +228,7 @@ namespace graft_cv{
 	int& roi_max_y   //output
 	);
 	void get_stem_y_fork_rs_update(
-	const Mat& bin_img,
+	const cv::Mat& bin_img,
 	int stem_x_padding,
 	int x0,
 	int x1,
@@ -237,7 +237,7 @@ namespace graft_cv{
 	int stem_dia,
 	bool image_show,
 	double cut_point_offset_ratio,
-	Point& fork_cent,
+		cv::Point& fork_cent,
 	double& max_radius,
 	double& stem_angle
 	);
@@ -297,24 +297,24 @@ namespace graft_cv{
 	//);
 	void imshow_wait(
 		const char* winname, 
-		Mat&, 
+		cv::Mat&,
 		int waittype=-1
 		);
 
 	int get_stem_fork_right(
-		Mat&stem_img, 
+		cv::Mat&stem_img,
 		int stem_fork_y, 
 		int stem_x0, 
 		int stem_x1,
 		int detect_window);
 	int get_stem_fork_left(
-		Mat&stem_img, 
+		cv::Mat&stem_img,
 		int stem_fork_y, 
 		int stem_x0, 
 		int stem_x1,
 		int detect_window);
 	void get_stem_fork_xs(
-		Mat&stem_img, 
+		cv::Mat&stem_img,
 		int stem_fork_y, 
 		int stem_x0, 
 		int stem_x1,
@@ -325,7 +325,7 @@ namespace graft_cv{
 	);
 
 	void get_next_pt(
-	    Mat& edge_img,
+		cv::Mat& edge_img,
 	    gcv_point<int>&start_pt, 
 	    gcv_point<int>&pre_pt, 
 		gcv_point<int>&nxt_pt, //output