# How to use "FaceDetectorYN"

**URL:** <https://forum.opencv.org/t/how-to-use-facedetectoryn/7015>\
**Category:** C++\
**Tags:** dnn\
**Created:** [January 7, 2022, 6:23am UTC](https://forum.opencv.org/t/how-to-use-facedetectoryn/7015 "2022-01-07T06:23:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mvjohn100](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/mvjohn100/32/3919_2.png) [@mvjohn100](https://forum.opencv.org/u/mvjohn100)\
**Post date:** [January 7, 2022, 6:23am UTC](https://forum.opencv.org/t/how-to-use-facedetectoryn/7015/1 "2022-01-07T06:23:57Z")

</div>

Receiving the error FaceDetectorYN was not delcared in the scope.

tried to execute following C++ sample code

[https://docs.opencv.org/4.x/d0/dd4/tutorial\_dnn\_face.html](https://docs.opencv.org/4.x/d0/dd4/tutorial_dnn_face.html)

using OpenCV 4.5.3

for using OpenCV with extra modules. done the following too

```auto
$ cd <opencv_build_directory>
$ cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules <opencv_source_directory>
$ make -j5
$ sudo make install

```

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [January 7, 2022, 7:47am UTC](https://forum.opencv.org/t/how-to-use-facedetectoryn/7015/2 "2022-01-07T07:47:30Z")

</div>

you do not need any contrib modules for this,

but a [more recent opencv version](https://github.com/opencv/opencv/releases/tag/4.5.5) (4.5.3 does not have this class)

then, [try the sample here](https://github.com/opencv/opencv/blob/4.x/samples/dnn/face_detect.cpp)

---

<div class="post-metadata">

**Author:** ![mvjohn100](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/mvjohn100/32/3919_2.png) [@mvjohn100](https://forum.opencv.org/u/mvjohn100)\
**Post date:** [January 8, 2022, 6:13am UTC](https://forum.opencv.org/t/how-to-use-facedetectoryn/7015/3 "2022-01-08T06:13:47Z")

</div>

Still receiving following error. Tried new sample code mentioned by you

/home/john/Qt Applications/faceDetection2/main.cpp:74: error: ‘FaceDetectorYN’ was not declared in this scope  
…/faceDetection2/main.cpp: In function ‘int main(int, char\*\*)’:  
…/faceDetection2/main.cpp:74:9: error: ‘FaceDetectorYN’ was not declared in this scope  
Ptr detector = FaceDetectorYN::create(fd\_modelPath, “”, Size(320, 320), scoreThreshold, nmsThreshold, topK);

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [January 8, 2022, 7:56am UTC](https://forum.opencv.org/t/how-to-use-facedetectoryn/7015/4 "2022-01-08T07:56:45Z")

</div>

again, 4.5.3 does not have it, update
