How can I change the prewiew resolution of the face detector scene? I change it to 600*300,but the face detector function doesn't work.
Closed this issue · 23 comments
How can I change the prewiew resolution of the face detector scene? I change it to 600*300,but the face detector function doesn't work.
Did you change the parameters inside DaiFaceDetector.cs?
Thanks for your reply, I changed the code in it :
void InitTexture()
{
colorTexture = new Texture2D(600, 300, TextureFormat.ARGB32, false);
}
and
protected override bool InitDevice()
{
// Need it for color camera preview
config.previewSizeWidth = 600;
config.previewSizeHeight = 300;
}
Is my operation incorrect ?
I changed it because the perspective is relatively small now, and I want to make it larger.
Hi ! did you changed also the image size inside the canvas? you need to change from square image to something like 1600x800 (same aspect ratio with the new config)
I tried, but it still doesn't work well.
Can you help me test it as I said? Thank you!
Hi @Mr-ider , I'm checking on my side. Notice that input shape to face detector model is 300x300, so if you want to use wide resolution, it's needed to reshape at some point to 300x300 as input for model
https://github.com/luxonis/depthai-unity/blob/main/src/predefined/FaceDetector.cpp
So in case you just changed the config of previewSize probably you're getting error message (editor log) saying that 600x300 is wrong input shape for the model and face detection is not working.
Think the best approach here is try to use any preview resolution you want and use ImageManip node to resize to 300x300 and link as input to NN
@Mr-ider Also notice, preview size is more about aspect ratio than resolution itself, because crop is happening in full resolution. So in this case, probably is needed a translation between the results on streched 300x300 to non-square ratio.
@gespona I may not know how to solve this problem as you mentioned. Our main purpose is to broaden the view of the OAK device. Is it the wrong way to change the preview resolution?
@gespona I don't know how to use the ImageManip node you mentioned specifically. Where should I change it in Unity? Can you help me give it a try.
@gespona The device has a large field of view, but the available range when using facial recognition is very small. I believe all developers who use facial recognition will encounter this problem, and I hope you can improve it. Thank you very much.
@Mr-ider Will modify the example and create a branch for you with imageManip. This node is part of the pipeline. In other words, is on the plugin side here: https://github.com/luxonis/depthai-unity/blob/main/src/predefined/FaceDetector.cpp
Hi @gespona ,That would be great,Looking forward to it very much! Thanks again : )
Hi @Mr-ider , yes some good progress, beside the initial approach is not really working as expected. That said, imageManip is the way to do it. Here some docs and code if you want to give a try. The idea is to use 600x300 image and use imageManip tiling to split in two images 300x300 (input shape of face detector) and combine results in the larger image
@Mr-ider check branch https://github.com/luxonis/depthai-unity/tree/face-detector-600300 in this branch face detector is using 600x300. As explained above I'm splitting in two images 300x300, using two face detectors and adding results in final 600x300.
Notice when face is in the middle of the image, you have two face detections. With the results inside unity, it's easy to merge both bounding boxes if you want only 1 bounding box all the time.
@Mr-ider I just pushed another branch https://github.com/luxonis/depthai-unity/tree/face-detector-aspect-ratio with much easier solution with 1 bounding box but wide fov.
@gespona That's great , after my testing, this has perfectly solved my problem. Thank you for your efforts in your busy schedule!
@gespona However, I just discovered a problem where the face can be detected within a range of 600 * 300 when the field of view increases. However, when the face moves to the edge of the screen, the Cube Character position will fly far away. I haven't found the reason yet. If you have time, please take a look.
@Mr-ider Hi, what I can see is if face is in the edge of image (left or right) and face ROI is start to stretch then there is some flick on depth, but in very tiny part of the image. Think the reason is because now using full width, when computing depth is using a small ROI but when face ROI is starting to stretch there is no buffer on the sides to keep depth compute consistent. My suggestion is you can control this inside Unity .. as flickering is happening on very tiny part of each edge .. you just can control and when face detection position is reaching that part, you can either skip, use previous depth, or simple remove that small areas ... makes sense?
Hi @Mr-ider ! I just updated the repo with the letterbox approach. I think this could be good default as you have all the field of view. Also I updated the way to compute depth and removed any flickering on the edge.
Closing this ticket. Reopen if needed.