example.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "opencv2/core.hpp"
  2. #include "opencv2/imgproc.hpp"
  3. #include "opencv2/highgui.hpp"
  4. #include "opencv2/videoio.hpp"
  5. #include <iostream>
  6. using namespace cv;
  7. using namespace std;
  8. void drawText(Mat & image);
  9. int main()
  10. {
  11. cout << "Built with OpenCV " << CV_VERSION << endl;
  12. Mat image;
  13. VideoCapture capture;
  14. capture.open(0);
  15. if(capture.isOpened())
  16. {
  17. cout << "Capture is opened" << endl;
  18. for(;;)
  19. {
  20. capture >> image;
  21. if(image.empty())
  22. break;
  23. drawText(image);
  24. imshow("Sample", image);
  25. if(waitKey(10) >= 0)
  26. break;
  27. }
  28. }
  29. else
  30. {
  31. cout << "No capture" << endl;
  32. image = Mat::zeros(480, 640, CV_8UC1);
  33. drawText(image);
  34. imshow("Sample", image);
  35. waitKey(0);
  36. }
  37. return 0;
  38. }
  39. void drawText(Mat & image)
  40. {
  41. putText(image, "Hello OpenCV",
  42. Point(20, 50),
  43. FONT_HERSHEY_COMPLEX, 1, // font face and scale
  44. Scalar(255, 255, 255), // white
  45. 1, LINE_AA); // line thickness and type
  46. }