質問編集履歴
1
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,6 +8,76 @@
|
|
8
8
|
このことについて解決したいです。
|
9
9
|
|
10
10
|
|
11
|
+
### 該当のソースコード
|
12
|
+
|
13
|
+
```ここに言語名を入力
|
14
|
+
int main()
|
15
|
+
{
|
16
|
+
cv::Mat frame;
|
17
|
+
cv::VideoCapture cam(0);
|
18
|
+
if (!cam.isOpened()) //正常にカメラが起動できなければ終了
|
19
|
+
{
|
20
|
+
return -1;
|
21
|
+
}
|
22
|
+
|
23
|
+
cv::Mat XOR = { 0 };
|
24
|
+
|
25
|
+
//保存フォルダ指定
|
26
|
+
std::string path = "........";
|
27
|
+
//保存ファイル作成
|
28
|
+
time_t t1 = time(NULL); //現在の日時取得
|
29
|
+
struct tm local; //日時情報を格納する変数を用意する
|
30
|
+
localtime_s(&local, &t1); //ローカル日時を変数に格納する
|
31
|
+
|
32
|
+
//文字列への変換
|
33
|
+
char str[100];
|
34
|
+
strftime(str, sizeof(str), "%Y%m%d_%H%M%S.csv", &local);
|
35
|
+
std::string filepath = path + "rng_" + str;
|
36
|
+
std::cout << filepath << std::endl;
|
37
|
+
|
38
|
+
while (cam.read(frame))
|
39
|
+
{
|
40
|
+
cv::Mat gray;
|
41
|
+
cv::Mat adp_binary;
|
42
|
+
|
43
|
+
|
44
|
+
//グレースケール処理
|
45
|
+
cv::cvtColor(frame, gray, cv::COLOR_BGR2GRAY);
|
46
|
+
cv::imshow("gray", gray);
|
47
|
+
|
48
|
+
//適応的二値化処理
|
49
|
+
cv::adaptiveThreshold(gray, adp_binary, 255, cv::ADAPTIVE_THRESH_GAUSSIAN_C, cv:: THRESH_BINARY, 7, 0);
|
50
|
+
cv::imshow("adp_binaly", adp_binary);
|
51
|
+
|
52
|
+
cv::Mat XOR1 = adp_binary.reshape(0, 1);
|
53
|
+
int center = adp_binary.rows / 2;
|
54
|
+
|
55
|
+
cv::Mat cut_array1(XOR1, cv::Rect(center - 23, 0, XOR1.cols - adp_binary.cols, 1));
|
56
|
+
cv::Mat cut_array2(XOR1, cv::Rect(center + 18, 0, XOR1.cols - adp_binary.cols, 1));
|
57
|
+
cv::Mat cut_array3(XOR1, cv::Rect(center - 5, 0, XOR1.cols - adp_binary.cols, 1));
|
58
|
+
cv::Mat cut_array4(XOR1, cv::Rect(center + 7, 0, XOR1.cols - adp_binary.cols, 1));
|
59
|
+
|
60
|
+
bitwise_xor(cut_array1, cut_array2, cut_array1);
|
61
|
+
bitwise_xor(cut_array1, cut_array3, cut_array1);
|
62
|
+
bitwise_xor(cut_array1, cut_array4, cut_array1);
|
63
|
+
bitwise_xor(XOR, cut_array1, XOR);
|
64
|
+
|
65
|
+
cv::Mat tempXOR = XOR.reshape(0, adp_binary.rows - 1);
|
66
|
+
|
67
|
+
cv::imshow("XOR", tempXOR);
|
68
|
+
|
69
|
+
std::ofstream ofs;
|
70
|
+
ofs.open(filepath);
|
71
|
+
cv::Mat seq = tempXOR / 100;
|
72
|
+
|
73
|
+
ofs << cv::format(seq, cv::Formatter::FMT_CSV) << std::endl;
|
74
|
+
|
75
|
+
ofs.close();
|
76
|
+
cv::waitKey(100000);
|
77
|
+
}
|
78
|
+
return 0;
|
79
|
+
}
|
80
|
+
```
|
11
81
|
|
12
82
|
|
13
83
|
|