質問編集履歴

2

変更のため

2018/02/14 07:03

投稿

kotetu
kotetu

スコア34

test CHANGED
File without changes
test CHANGED
@@ -50,7 +50,7 @@
50
50
 
51
51
  }
52
52
 
53
- return image;
53
+ return faces;
54
54
 
55
55
  }
56
56
 

1

内容の変更

2018/02/14 07:03

投稿

kotetu
kotetu

スコア34

test CHANGED
File without changes
test CHANGED
@@ -14,11 +14,15 @@
14
14
 
15
15
  ```C++
16
16
 
17
+ #include "opencv2/highgui.hpp"
18
+
19
+ #include "opencv2/imgproc.hpp"
20
+
17
- #include <opencv2/opencv.hpp>
21
+ #include "opencv2/opencv.hpp"
22
+
23
+ #include "opencv2/highgui/highgui.hpp"
18
24
 
19
25
  #include <iostream>
20
-
21
-
22
26
 
23
27
  using namespace std;
24
28
 
@@ -26,48 +30,62 @@
26
30
 
27
31
 
28
32
 
29
- Mat detectFaceInImage(Mat &image,string &cascade_file){
33
+ std::vector<cv::Rect> detectFaceInImage(Mat &image,string &cascade_file){//変更箇所
30
34
 
31
- CascadeClassifier cascade;
35
+ CascadeClassifier cascade;
32
36
 
33
- cascade.load(cascade_file);
37
+ cascade.load(cascade_file);
34
38
 
39
+
35
40
 
41
+ vector<Rect> faces;
36
42
 
37
- vector<Rect> faces;
43
+ cascade.detectMultiScale(image, faces, 1.1,3,0,Size(20,20));
38
44
 
39
- cascade.detectMultiScale(image, faces, 1.1,3,0,Size(20,20));
45
+
40
46
 
47
+ for (int i = 0; i < faces.size(); i++){
41
48
 
49
+ rectangle(image, Point(faces[i].x,faces[i].y),Point(faces[i].x + faces[i].width,faces[i].y + faces[i].height),Scalar(0,200,0),3,CV_AA);
42
50
 
43
- for (int i = 0; i < faces.size(); i++){
51
+ }
44
52
 
45
- rectangle(image, Point(faces[i].x,faces[i].y),Point(faces[i].x + faces[i].width,faces[i].y + faces[i].height),Scalar(0,200,0),3,CV_AA);
46
-
47
- }
48
-
49
- return image;
53
+ return image;
50
54
 
51
55
  }
52
56
 
53
57
 
54
58
 
55
- int main(int argc, char const *argv[]){
59
+ int main(int argc, const char *argv[])
56
60
 
57
- Mat image = imread(argv[1]);
61
+ {
58
62
 
59
- string filename = argv[2];
63
+ Mat image = imread(argv[1]);
60
64
 
61
- Mat detectFaceImage = detectFaceInImage(image, filename);
65
+ string filename = argv[2];
62
66
 
63
- imshow("detect face",detectFaceImage);
67
+ vector<cv::Rect> detectFaceImage = detectFaceInImage(image, filename);//変更箇所
64
68
 
65
- waitKey(0);
69
+ imshow("detect face",detectFaceImage);
66
70
 
71
+ waitKey(0);
67
72
 
73
+
68
74
 
69
- return 0;
75
+ return 0;
70
76
 
71
77
  }
72
78
 
73
79
  ```
80
+
81
+ これだとコンパイルが通るのは通るのですが、次のとおりになります。
82
+
83
+ ```C++
84
+
85
+ terminate called after throwing an instance of 'std::logic_error'
86
+
87
+ what(): basic_string::_S_construct null not valid
88
+
89
+ 中止 (コアダンプ)
90
+
91
+ ```