testcpp.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "stdafx.h"
  2. #include "cv.h"
  3. void test()
  4. {
  5. printf("测试用例开始!\n");
  6. cv::Mat img;
  7. cv::Mat thresholdImg;
  8. ReadImage("E:\\bin\\test.jpg", img);
  9. if (GetBinaryImage("E:\\bin\\test.jpg", 100, 255, thresholdImg))
  10. {
  11. cv::Mat drawImg;
  12. img.copyTo(drawImg);
  13. DrawContours(thresholdImg, drawImg, true, false, 0, 0, false, 0, 0);
  14. if (!drawImg.empty())
  15. {
  16. cv::imwrite("E:\\bin\\drawImg.jpg", drawImg);
  17. drawImg.release();
  18. }
  19. cv::imwrite("E:\\bin\\thresholdImg.jpg", thresholdImg);
  20. thresholdImg.release();
  21. }
  22. if (GetOTSUBinaryImage("E:\\bin\\test.jpg", 0, 255, thresholdImg))
  23. {
  24. cv::imwrite("E:\\bin\\otsu-thresholdImg.jpg", thresholdImg);
  25. thresholdImg.release();
  26. }
  27. if (GetAdaptiveBinaryImage("E:\\bin\\test.jpg", 100, thresholdImg))
  28. {
  29. cv::imwrite("E:\\bin\\adpat-thresholdImg.jpg", thresholdImg);
  30. thresholdImg.release();
  31. }
  32. if (GaussianBlur("E:\\bin\\test.jpg", cv::Size(15, 15), thresholdImg))
  33. {
  34. cv::imwrite("E:\\bin\\gaussImg.jpg", thresholdImg);
  35. thresholdImg.release();
  36. }
  37. if (Color2Gray("E:\\bin\\test.jpg", thresholdImg))
  38. {
  39. cv::imwrite("E:\\bin\\grayImg.jpg", thresholdImg);
  40. thresholdImg.release();
  41. }
  42. if (ReadImage("E:\\bin\\test.jpg", img))
  43. {
  44. if (Color2Gray(img, thresholdImg))
  45. {
  46. cv::Mat colorImg;
  47. if ( Gray2Color(thresholdImg, colorImg) )
  48. {
  49. cv::imwrite("E:\\bin\\colorImg.jpg", colorImg);
  50. colorImg.release();
  51. }
  52. cv::imwrite("E:\\bin\\grayImg2.jpg", thresholdImg);
  53. thresholdImg.release();
  54. }
  55. if (ErodeImg(img, cv::MORPH_RECT, cv::Size(15,15), thresholdImg))
  56. {
  57. cv::imwrite("E:\\bin\\ErodeImg.jpg", thresholdImg);
  58. thresholdImg.release();
  59. }
  60. if (DilateImg(img, cv::MORPH_RECT, cv::Size(15, 15), thresholdImg))
  61. {
  62. cv::imwrite("E:\\bin\\DilateImg.jpg", thresholdImg);
  63. thresholdImg.release();
  64. }
  65. }
  66. CutPictures("E:\\bin\\test.jpg", cv::Rect(100, 100, 900, 800), "E:\\bin\\roi.jpg");
  67. double matchVal;
  68. cv::Rect matchRect;
  69. MatchSingleImage("E:\\bin\\未选中1.png", "E:\\bin\\未选中.png", matchVal, matchRect);
  70. printf("匹配度:%lf, 坐标:[%d,%d,%d,%d]\n", matchVal, matchRect.x, matchRect.y, matchRect.width, matchRect.height);
  71. //////////////////////////////////////////////////////////////////////////
  72. printf("测试用例结束!\n");
  73. }
  74. void test2()
  75. {
  76. // 初始化gdiplus环境;
  77. InitGdiplus();
  78. Gdiplus::Bitmap* img = NULL;
  79. if (GdiplusReadImage("E:\\bin\\test.jpg", &img)) {
  80. cv::Mat mat;
  81. GdiplusBitmap2Mat(img, mat);
  82. delete img;
  83. cv::imwrite("E:\\mat.jpg", mat);
  84. mat.release();
  85. }
  86. // 关闭gdiplus环境;
  87. ShutGdiplus();
  88. }