MarekKowalski / FaceSwap

3D face swapping implemented in Python
MIT License
730 stars 206 forks source link

cv2.error: OpenCV(4.5.2-dev) :-1: error: (-5:Bad argument) in function 'pointPolygonTest' #31

Open jiapei100 opened 3 years ago

jiapei100 commented 3 years ago

Hi,

I'm actually testing FaceSwap with the following environment:

➜  FaceSwap lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.2 LTS
Release:    20.04
Codename:   focal
➜  FaceSwap python --version
Python 3.8.5
➜  FaceSwap pip show tensorflow
Name: tensorflow
Version: 2.6.0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: packages@tensorflow.org
License: Apache 2.0
Location: ~/.local/lib/python3.8/site-packages
Requires: google-pasta, flatbuffers, wrapt, opt-einsum, termcolor, h5py, keras-preprocessing, grpcio, numpy, wheel, absl-py, tensorflow-estimator, gast, astunparse, typing-extensions, protobuf, six, tensorboard, keras-nightly
Required-by: fawkes
➜  FaceSwap apt show opencv
Package: opencv
Version: 4.5.2-6
Status: install ok installed
Priority: extra
Section: checkinstall
Maintainer: root@myVision
Installed-Size: 252 MB
Provides: build
Download-Size: unknown
APT-Manual-Installed: yes
APT-Sources: /var/lib/dpkg/status
Description: Package created with checkinstall 1.6.3

However, I got the following ERROR message.

➜  FaceSwap python zad2.py 
pygame 2.0.1 (SDL 2.0.14, Python 3.8.5)
Hello from the pygame community. https://www.pygame.org/contribute.html
Press T to draw the keypoints and the 3D model
Press R to start recording to a video file
Loading network...
Input shape: (None, 1, 112, 112)
WARNING (theano.tensor.blas): We did not find a dynamic library in the library_dir of the library we use for blas. If you use ATLAS, make sure to compile it with dynamics library.
[ WARN:0] global ....../opencv/modules/videoio/src/cap_gstreamer.cpp (1081) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
Traceback (most recent call last):
  File "zad2.py", line 66, in <module>
    cameraImg = ImageProcessing.blendImages(renderedImg, cameraImg, mask)
  File "....../face/FaceSwap/FaceSwap-DAN-public/FaceSwap/ImageProcessing.py", line 17, in blendImages
    dists[i] = cv2.pointPolygonTest(hull, (maskPts[i, 0], maskPts[i, 1]), True)
cv2.error: OpenCV(4.5.2-dev) :-1: error: (-5:Bad argument) in function 'pointPolygonTest'
> Overload resolution failed:
>  - Can't parse 'pt'. Sequence item with index 0 has a wrong type
>  - Can't parse 'pt'. Sequence item with index 0 has a wrong type

Any suggestions?

Cheers Pei

GZaccaroni commented 3 years ago

Try with opencv-python 4.5.1.48

MarekKowalski commented 3 years ago

I understand that you are trying to run FaceSwap together with DAN. I've never tried running the latter on linux so it's hard to help. However, running FaceSwap with dlib landmarks should be fairly easy on any platform, have you tried that?

kwikwag commented 3 years ago

This is a problem with OpenCV 4.5.2. Better stick to 4.5.1 for now, or convert the point to a tuple of ints:

pt = tuple(int(x) for x in pt)

Reported here.