#include "stdafx.h" #include "cv.h" void test() { printf("测试用例开始!\n"); cv::Mat img; cv::Mat thresholdImg; ReadImage("E:\\bin\\test.jpg", img); if (GetBinaryImage("E:\\bin\\test.jpg", 100, 255, thresholdImg)) { cv::Mat drawImg; img.copyTo(drawImg); DrawContours(thresholdImg, drawImg, true, false, 0, 0, false, 0, 0); if (!drawImg.empty()) { cv::imwrite("E:\\bin\\drawImg.jpg", drawImg); drawImg.release(); } cv::imwrite("E:\\bin\\thresholdImg.jpg", thresholdImg); thresholdImg.release(); } if (GetOTSUBinaryImage("E:\\bin\\test.jpg", 0, 255, thresholdImg)) { cv::imwrite("E:\\bin\\otsu-thresholdImg.jpg", thresholdImg); thresholdImg.release(); } if (GetAdaptiveBinaryImage("E:\\bin\\test.jpg", 100, thresholdImg)) { cv::imwrite("E:\\bin\\adpat-thresholdImg.jpg", thresholdImg); thresholdImg.release(); } if (GaussianBlur("E:\\bin\\test.jpg", cv::Size(15, 15), thresholdImg)) { cv::imwrite("E:\\bin\\gaussImg.jpg", thresholdImg); thresholdImg.release(); } if (Color2Gray("E:\\bin\\test.jpg", thresholdImg)) { cv::imwrite("E:\\bin\\grayImg.jpg", thresholdImg); thresholdImg.release(); } if (ReadImage("E:\\bin\\test.jpg", img)) { if (Color2Gray(img, thresholdImg)) { cv::Mat colorImg; if ( Gray2Color(thresholdImg, colorImg) ) { cv::imwrite("E:\\bin\\colorImg.jpg", colorImg); colorImg.release(); } cv::imwrite("E:\\bin\\grayImg2.jpg", thresholdImg); thresholdImg.release(); } if (ErodeImg(img, cv::MORPH_RECT, cv::Size(15,15), thresholdImg)) { cv::imwrite("E:\\bin\\ErodeImg.jpg", thresholdImg); thresholdImg.release(); } if (DilateImg(img, cv::MORPH_RECT, cv::Size(15, 15), thresholdImg)) { cv::imwrite("E:\\bin\\DilateImg.jpg", thresholdImg); thresholdImg.release(); } } CutPictures("E:\\bin\\test.jpg", cv::Rect(100, 100, 900, 800), "E:\\bin\\roi.jpg"); double matchVal; cv::Rect matchRect; MatchSingleImage("E:\\bin\\未选中1.png", "E:\\bin\\未选中.png", matchVal, matchRect); printf("匹配度:%lf, 坐标:[%d,%d,%d,%d]\n", matchVal, matchRect.x, matchRect.y, matchRect.width, matchRect.height); ////////////////////////////////////////////////////////////////////////// printf("测试用例结束!\n"); } void test2() { // 初始化gdiplus环境; InitGdiplus(); Gdiplus::Bitmap* img = NULL; if (GdiplusReadImage("E:\\bin\\test.jpg", &img)) { cv::Mat mat; GdiplusBitmap2Mat(img, mat); delete img; cv::imwrite("E:\\mat.jpg", mat); mat.release(); } // 关闭gdiplus环境; ShutGdiplus(); }