Explorar o código

1、新增函数声明:Mat转gdi CBitmap和转Gdiplus::Bitmap对象;
2、在GDI+头文件声明前,必须重新定义max和min,否则会引用失败:
#ifndef min
#define min
#endif

#ifndef max
#define max
#endif

#include <gdiplus.h>

scbc.sat2 %!s(int64=5) %!d(string=hai) anos
pai
achega
62c5abab2c
Modificáronse 3 ficheiros con 33 adicións e 5 borrados
  1. 16 4
      cv/cv/cv.cpp
  2. 6 1
      cv/cv/cv.h
  3. 11 0
      cv/cv/framework.h

+ 16 - 4
cv/cv/cv.cpp

@@ -36,7 +36,9 @@ int main()
         else
         {
             // TODO: 在此处为应用程序的行为编写代码。
+#ifdef _DEBUG
 			test();
+#endif
         }
     }
     else
@@ -431,7 +433,7 @@ CV_API bool MatchSingleImage(cv::Mat& img, cv::Mat templImg, double& matchVal, c
 		1 表示完全相同,-1 表示两幅图像的亮度正好相反,0 表示两幅图像之间没有线性关系。
 	*/
 	cv::Mat resultImg;
-	cv::matchTemplate(img, templ, resultImg, cv::TM_CCOEFF_NORMED);
+	cv::matchTemplate(img, templImg, resultImg, cv::TM_CCOEFF_NORMED);
 	if (resultImg.empty())
 		return false;
 
@@ -448,8 +450,8 @@ CV_API bool MatchSingleImage(cv::Mat& img, cv::Mat templImg, double& matchVal, c
 	// 匹配区域,使用最大区域;
 	matchRect.x = lv_nMaxLoc.x;
 	matchRect.y = lv_nMaxLoc.y;
-	matchRect.width = templ.cols;
-	matchRect.height = templ.rows;
+	matchRect.width = templImg.cols;
+	matchRect.height = templImg.rows;
 
 #ifdef _DEBUG
 	// 在原图上框出模板位置;
@@ -457,7 +459,7 @@ CV_API bool MatchSingleImage(cv::Mat& img, cv::Mat templImg, double& matchVal, c
 	img.copyTo(showImg);
 	cv::rectangle(showImg,
 		cv::Point(lv_nMaxLoc.x, lv_nMaxLoc.y),
-		cv::Point(lv_nMaxLoc.x + templ.cols, lv_nMaxLoc.y + templ.rows),
+		cv::Point(lv_nMaxLoc.x + templImg.cols, lv_nMaxLoc.y + templImg.rows),
 		cv::Scalar(rand() % 255, rand() % 255, rand() % 255),
 		2,
 		cv::LINE_AA,
@@ -563,3 +565,13 @@ CV_API bool MatchSingleImage(std::string strImg, std::string strTmpImg, double&
 
 	return true;
 }
+
+CV_API bool Mat2Bitmap(cv::Mat& img, CBitmap& bitmap)
+{
+	return CV_API bool();
+}
+
+CV_API bool Mat2GdiplusBitmap(cv::Mat& img, Gdiplus::Bitmap& bitmap)
+{
+	return CV_API bool();
+}

+ 6 - 1
cv/cv/cv.h

@@ -61,11 +61,16 @@ CV_API bool CutPictures(std::string strImgPath, cv::Rect cvRect, std::string str
 // 如果drawImg空,则从函数内部使用binImg来克隆;
 CV_API bool DrawContours(cv::Mat& binImg, cv::Mat& drawImg, bool InternalContour, bool bPerimeter, long nMinPerimeter, long nMaxPerimeter, bool bArea, long nMinArea, long nMaxArea);
 
-//10、单个模板图片匹配
+// 12、单个模板图片匹配
 CV_API bool MatchSingleImage(cv::Mat& img, cv::Mat templImg, double& matchVal, cv::Rect& matchRect);
 CV_API bool MatchSingleImage(cv::Mat& img, std::string strTmpImg, double &matchVal, cv::Rect &matchRect);
 CV_API bool MatchSingleImage(std::string strImg, std::string strTmpImg, double& matchVal, cv::Rect& matchRect);
 
+// 13、将opencv Mat对象转为GDI Bitmap对象和GDI+ Bitmap对象;
+CV_API bool Mat2Bitmap(cv::Mat &img, CBitmap &bitmap);
+CV_API bool Mat2GdiplusBitmap(cv::Mat& img, Gdiplus::Bitmap& bitmap);
+
+
 // 待开发
 // 11、获取图片指定RGB颜色域的轮廓图像结果
 // 12、多个模板图片匹配

+ 11 - 0
cv/cv/framework.h

@@ -25,3 +25,14 @@
 #include <string>
 // 只需要包含一个头文件即可;
 #include "opencv2/opencv.hpp"
+
+//在引用gdi的相关头文件前,重新定义min、max;
+#ifndef min
+#define min
+#endif
+
+#ifndef max
+#define max
+#endif
+
+#include <gdiplus.h>