brightedgesexample.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2017, IBM Corporation, all rights reserved.
  14. // Third party copyrights are property of their respective owners.
  15. //
  16. // @Authors
  17. // Marc Fiammante marc.fiammante@fr.ibm.com
  18. //
  19. // Redistribution and use in source and binary forms, with or without modification,
  20. // are permitted provided that the following conditions are met:
  21. //
  22. // * Redistribution's of source code must retain the above copyright notice,
  23. // this list of conditions and the following disclaimer.
  24. //
  25. // * Redistribution's in binary form must reproduce the above copyright notice,
  26. // this list of conditions and the following disclaimer in the documentation
  27. // and/or other materials provided with the distribution.
  28. //
  29. // * The name of OpenCV Foundation or contributors may not be used to endorse or promote products
  30. // derived from this software without specific prior written permission.
  31. //
  32. // This software is provided by the copyright holders and contributors "as is" and
  33. // any express or implied warranties, including, but not limited to, the implied
  34. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  35. // In no event shall the OpenCV Foundation or contributors be liable for any direct,
  36. // indirect, incidental, special, exemplary, or consequential damages
  37. // (including, but not limited to, procurement of substitute goods or services;
  38. // loss of use, data, or profits; or business interruption) however caused
  39. // and on any theory of liability, whether in contract, strict liability,
  40. // or tort (including negligence or otherwise) arising in any way out of
  41. // the use of this software, even if advised of the possibility of such damage.
  42. //
  43. //M*/
  44. #include "opencv2/core/utility.hpp"
  45. #include "opencv2/imgproc.hpp"
  46. #include "opencv2/imgcodecs.hpp"
  47. #include "opencv2/highgui.hpp"
  48. #include <stdio.h>
  49. #include <iostream>
  50. #include "opencv2/ximgproc.hpp"
  51. using namespace cv;
  52. using namespace ximgproc;
  53. using namespace std;
  54. static void help()
  55. {
  56. printf("\nThis sample demonstrates BrightEdge detection\n"
  57. "Call:\n"
  58. " /.edge [image_name -- Default is ../data/ml.png]\n\n");
  59. }
  60. const char* keys =
  61. {
  62. "{help h||}{@image |../data/ml.png|input image name}"
  63. };
  64. int main(int argc, const char** argv)
  65. {
  66. CommandLineParser parser(argc, argv, keys);
  67. if (parser.has("help"))
  68. {
  69. help();
  70. return 0;
  71. }
  72. string filename = parser.get<string>(0);
  73. Mat image = imread(filename, IMREAD_COLOR);
  74. if (image.empty())
  75. {
  76. printf("Cannot read image file: %s\n", filename.c_str());
  77. help();
  78. return -1;
  79. }
  80. // Create a window
  81. // // " original ";
  82. namedWindow("Original");
  83. imshow("Original", image);
  84. // " absdiff ";
  85. Mat edge;
  86. BrightEdges(image, edge, 0); // No contrast
  87. namedWindow("Absolute Difference");
  88. imshow("Absolute Difference", edge);
  89. // " default contrast 1 ";
  90. BrightEdges(image, edge);
  91. namedWindow("Default contrast");
  92. imshow("Default contrast", edge);// Default contrast 1
  93. // " Contrast 5 \n";
  94. BrightEdges(image, edge, 5);
  95. namedWindow("Contrast 5");
  96. imshow("Contrast 5", edge);
  97. // " Contrast 10 \n";
  98. BrightEdges(image, edge, 10);
  99. namedWindow("Contrast 10");
  100. imshow("Contrast 10", edge);
  101. // "wait key ";
  102. waitKey(0);
  103. // "end ";
  104. return 0;
  105. }