回答編集履歴

2

微修正

2023/05/22 07:25

投稿

episteme
episteme

スコア16614

test CHANGED
@@ -1,4 +1,4 @@
1
- たとえばこんなカンジですかね...
1
+ たとえばこんなカンジですかね...(画像はWebカメラから拾ってます)
2
2
  ```C++
3
3
  #include "opencv2/opencv.hpp"
4
4
  #include <cstdint>

1

微修正

2023/05/22 06:26

投稿

episteme
episteme

スコア16614

test CHANGED
@@ -15,10 +15,8 @@
15
15
  // Gray-scale に変換し
16
16
  cv::cvtColor(src_img, dst_img, cv::COLOR_BGR2GRAY);
17
17
  // 二値化して
18
- for ( cv::Mat_<uint8_t>::iterator it = dst_img.begin<uint8_t>();
18
+ std::for_each(dst_img.begin<uint8_t>(), dst_img.end<uint8_t>(),
19
- it != dst_img.end<uint8_t>(); ++it) {
20
- *it = (*it > 127) ? 255 : 0;
19
+ [](auto& pixcel) { pixcel = (pixcel > 127) ? 255 : 0;});
21
- }
22
20
  // ガウシアン・ブラーで平滑化して
23
21
  cv::GaussianBlur(dst_img, dst_img, cv::Size(101,101), 0);
24
22