hrastnik / FaceSwap

Real-time FaceSwap application built with OpenCV and dlib

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to run this project?

crosofg opened this issue · comments

Can you please tell the execution steps required? And how to link OpenCV

Install OpenCV and dlib. Look up the instructions online.

I have opencv and dlib installed. I tried compiling by cding into the directory (after copying the two missing files), and running: g++ *.cpp

usr/local/src/FaceSwap-master# g++ .cpp
In file included from FaceDetectorAndTracker.cpp:1:0:
FaceDetectorAndTracker.h:49:5: error: ‘unique_ptr’ in namespace ‘std’ does not name a type
std::unique_ptrcv::VideoCapture m_camera;
^
FaceDetectorAndTracker.h:54:5: error: ‘unique_ptr’ in namespace ‘std’ does not name a type
std::unique_ptrcv::CascadeClassifier m_faceCascade;
^
FaceDetectorAndTracker.h:90:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
bool m_tracking = false;
^
FaceDetectorAndTracker.h:92:25: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
size_t m_numFaces = 0;
^
FaceDetectorAndTracker.h:94:63: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
const double m_tmMaxDuration = 2.0;
^
FaceDetectorAndTracker.cpp: In constructor ‘FaceDetectorAndTracker::FaceDetectorAndTracker(std::string, int, size_t)’:
FaceDetectorAndTracker.cpp:13:5: error: ‘m_camera’ was not declared in this scope
m_camera = std::make_uniquecv::VideoCapture(cameraIndex);
^
FaceDetectorAndTracker.cpp:13:16: error: ‘make_unique’ is not a member of ‘std’
m_camera = std::make_uniquecv::VideoCapture(cameraIndex);
^
FaceDetectorAndTracker.cpp:13:49: error: expected primary-expression before ‘>’ token
m_camera = std::make_uniquecv::VideoCapture(cameraIndex);
^
FaceDetectorAndTracker.cpp:20:5: error: ‘m_faceCascade’ was not declared in this scope
m_faceCascade = std::make_uniquecv::CascadeClassifier(cascadeFilePath);
^
FaceDetectorAndTracker.cpp:20:21: error: ‘make_unique’ is not a member of ‘std’
m_faceCascade = std::make_uniquecv::CascadeClassifier(cascadeFilePath);
^
FaceDetectorAndTracker.cpp:20:59: error: expected primary-expression before ‘>’ token
m_faceCascade = std::make_uniquecv::CascadeClassifier(cascadeFilePath);
^
FaceDetectorAndTracker.cpp: In member function ‘void FaceDetectorAndTracker::operator>>(cv::Mat&)’:
FaceDetectorAndTracker.cpp:52:9: error: ‘m_camera’ was not declared in this scope
if (m_camera->isOpened() == false)
^
FaceDetectorAndTracker.cpp:57:6: error: ‘m_camera’ was not declared in this scope
m_camera >> frame;
^
FaceDetectorAndTracker.cpp: In member function ‘std::vector<cv::Rect_ > FaceDetectorAndTracker::faces()’:
FaceDetectorAndTracker.cpp:75:22: error: ISO C++ forbids declaration of ‘face’ with no type [-fpermissive]
for (const auto& face : m_facesRects)
^
FaceDetectorAndTracker.cpp:75:29: error: range-based ‘for’ loops are not allowed in C++98 mode
for (const auto& face : m_facesRects)
^
FaceDetectorAndTracker.cpp:77:39: error: request for member ‘x’ in ‘face’, which is of non-class type ‘const int’
faces.push_back(cv::Rect(face.x * m_ratio.x, face.y * m_ratio.y, face.width * m_ratio.x, face.height * m_ratio.y));
^
FaceDetectorAndTracker.cpp:77:59: error: request for member ‘y’ in ‘face’, which is of non-class type ‘const int’
faces.push_back(cv::Rect(face.x * m_ratio.x, face.y * m_ratio.y, face.width * m_ratio.x, face.height * m_ratio.y));
^
FaceDetectorAndTracker.cpp:77:79: error: request for member ‘width’ in ‘face’, which is of non-class type ‘const int’
faces.push_back(cv::Rect(face.x * m_ratio.x, face.y * m_ratio.y, face.width * m_ratio.x, face.height * m_ratio.y));
^
FaceDetectorAndTracker.cpp:77:103: error: request for member ‘height’ in ‘face’, which is of non-class type ‘const int’
faces.push_back(cv::Rect(face.x * m_ratio.x, face.y * m_ratio.y, face.width * m_ratio.x, face.height * m_ratio.y));
^
FaceDetectorAndTracker.cpp: In member function ‘void FaceDetectorAndTracker::detect()’:
FaceDetectorAndTracker.cpp:86:5: error: ‘m_faceCascade’ was not declared in this scope
m_faceCascade->detectMultiScale(m_downscaledFrame, m_facesRects, 1.1, 3, 0,
^
FaceDetectorAndTracker.cpp:101:15: error: ‘face’ does not name a type
for (auto face : m_facesRects)
^
FaceDetectorAndTracker.cpp:111:5: error: expected ‘;’ before ‘m_faceRois’
m_faceRois.clear();
^
FaceDetectorAndTracker.cpp:111:22: error: could not convert ‘((FaceDetectorAndTracker
)this)->FaceDetectorAndTracker::m_faceRois.std::vector<Tp, Alloc>::clear<cv::Rect, std::allocator<cv::Rect > >()’ from ‘void’ to ‘bool’
m_faceRois.clear();
^
FaceDetectorAndTracker.cpp:112:5: error: expected primary-expression before ‘for’
for (const auto& face : m_facesRects)
^
FaceDetectorAndTracker.cpp:112:5: error: expected ‘)’ before ‘for’
FaceDetectorAndTracker.cpp:112:22: error: ISO C++ forbids declaration of ‘face’ with no type [-fpermissive]
for (const auto& face : m_facesRects)
^
FaceDetectorAndTracker.cpp:112:29: error: range-based ‘for’ loops are not allowed in C++98 mode
for (const auto& face : m_facesRects)
^
FaceDetectorAndTracker.cpp:114:72: error: no matching function for call to ‘FaceDetectorAndTracker::doubleRectSize(const int&, cv::Size&)’
m_faceRois.push_back(doubleRectSize(face, m_downscaledFrameSize));
^
FaceDetectorAndTracker.cpp:114:72: note: candidate is:
In file included from FaceDetectorAndTracker.cpp:1:0:
FaceDetectorAndTracker.h:40:21: note: static cv::Rect FaceDetectorAndTracker::doubleRectSize(const Rect&, const Size&)
static cv::Rect doubleRectSize(const cv::Rect &rect, const cv::Size &frameSize);
^
FaceDetectorAndTracker.h:40:21: note: no known conversion for argument 1 from ‘const int’ to ‘const Rect& {aka const cv::Rect_&}’
FaceDetectorAndTracker.cpp: In member function ‘void FaceDetectorAndTracker::track()’:
FaceDetectorAndTracker.cpp:133:21: error: ISO C++ forbids declaration of ‘roi’ with no type [-fpermissive]
const auto &roi = m_faceRois[i]; // roi
^
FaceDetectorAndTracker.cpp:133:39: error: invalid initialization of reference of type ‘const int&’ from expression of type ‘cv::Rect_’
const auto &roi = m_faceRois[i]; // roi
^
FaceDetectorAndTracker.cpp:136:55: error: invalid conversion from ‘int’ to ‘const cv::Range
’ [-fpermissive]
const cv::Mat &faceRoi = m_downscaledFrame(roi);
^
In file included from /usr/include/opencv2/core/core.hpp:4855:0,
from FaceDetectorAndTracker.h:3,
from FaceDetectorAndTracker.cpp:1:
/usr/include/opencv2/core/mat.hpp:381:12: error: initializing argument 1 of ‘cv::Mat cv::Mat::operator()(const cv::Range*) const’ [-fpermissive]
inline Mat Mat::operator()(const Range* ranges) const
^
FaceDetectorAndTracker.cpp:137:9: error: ‘m_faceCascade’ was not declared in this scope
m_faceCascade->detectMultiScale(faceRoi, m_tmpFacesRect, 1.1, 3, 0,
^
FaceDetectorAndTracker.cpp:138:26: error: request for member ‘width’ in ‘roi’, which is of non-class type ‘const int’
cv::Size(roi.width * 4 / 10, roi.height * 4 / 10),
^
FaceDetectorAndTracker.cpp:138:46: error: request for member ‘height’ in ‘roi’, which is of non-class type ‘const int’
cv::Size(roi.width * 4 / 10, roi.height * 4 / 10),
^
FaceDetectorAndTracker.cpp:139:26: error: request for member ‘width’ in ‘roi’, which is of non-class type ‘const int’
cv::Size(roi.width * 6 / 10, roi.width * 6 / 10));
^
FaceDetectorAndTracker.cpp:139:46: error: request for member ‘width’ in ‘roi’, which is of non-class type ‘const int’
cv::Size(roi.width * 6 / 10, roi.width * 6 / 10));
^
FaceDetectorAndTracker.cpp:163:48: error: request for member ‘x’ in ‘roi’, which is of non-class type ‘const int’
m_facesRects[i].x = minLoc.x + roi.x - m_faceTemplates[i].cols / 2;
^
FaceDetectorAndTracker.cpp:164:48: error: request for member ‘y’ in ‘roi’, which is of non-class type ‘const int’
m_facesRects[i].y = minLoc.y + roi.y - m_faceTemplates[i].rows / 2;
^
FaceDetectorAndTracker.cpp:186:38: error: request for member ‘x’ in ‘roi’, which is of non-class type ‘const int’
m_facesRects[i].x += roi.x;
^
FaceDetectorAndTracker.cpp:187:38: error: request for member ‘y’ in ‘roi’, which is of non-class type ‘const int’
m_facesRects[i].y += roi.y;
^
FaceSwapper.cpp: In member function ‘void FaceSwapper::swapFaces(cv::Mat&, cv::Rect&, cv::Rect&)’:
FaceSwapper.cpp:48:10: error: ‘refined_mask_ann’ does not name a type
auto refined_mask_ann = refined_masks(big_rect_ann);
^
FaceSwapper.cpp:49:10: error: ‘refined_mask_bob’ does not name a type
auto refined_mask_bob = refined_masks(big_rect_bob);
^
FaceSwapper.cpp:50:17: error: ‘refined_mask_ann’ was not declared in this scope
featherMask(refined_mask_ann);
^
FaceSwapper.cpp:51:17: error: ‘refined_mask_bob’ was not declared in this scope
featherMask(refined_mask_bob);
^
FaceSwapper.cpp: In member function ‘void FaceSwapper::getFacePoints(const cv::Mat&)’:
FaceSwapper.cpp:86:10: error: ‘getPoint’ does not name a type
auto getPoint = [&](int shape_index, int part_index) -> const cv::Point2i
^
FaceSwapper.cpp:92:34: error: ‘getPoint’ was not declared in this scope
points_ann[0] = getPoint(0, 0);
^
FaceSwapper.cpp: In member function ‘void FaceSwapper::pasteFacesOnFrame()’:
FaceSwapper.cpp:197:14: error: ‘frame_pixel’ does not name a type
auto frame_pixel = small_frame.row(i).data;
^
FaceSwapper.cpp:198:14: error: ‘faces_pixel’ does not name a type
auto faces_pixel = warpped_faces.row(i).data;
^
FaceSwapper.cpp:199:14: error: ‘masks_pixel’ does not name a type
auto masks_pixel = refined_masks.row(i).data;
^
FaceSwapper.cpp:203:18: error: ‘masks_pixel’ was not declared in this scope
if (*masks_pixel != 0)
^
FaceSwapper.cpp:205:18: error: ‘frame_pixel’ was not declared in this scope
*frame_pixel = ((255 - *masks_pixel) * (*frame_pixel) + (*masks_pixel) * (*faces_pixel)) >> 8; // divide by 256
^
FaceSwapper.cpp:205:92: error: ‘faces_pixel’ was not declared in this scope
*frame_pixel = ((255 - *masks_pixel) * (*frame_pixel) + (*masks_pixel) * (*faces_pixel)) >> 8; // divide by 256
^
FaceSwapper.cpp:210:13: error: ‘frame_pixel’ was not declared in this scope
frame_pixel += 3;
^
FaceSwapper.cpp:211:13: error: ‘faces_pixel’ was not declared in this scope
faces_pixel += 3;
^
FaceSwapper.cpp:212:13: error: ‘masks_pixel’ was not declared in this scope
masks_pixel++;
^
FaceSwapper.cpp: In member function ‘void FaceSwapper::specifiyHistogram(cv::Mat, cv::Mat, cv::Mat)’:
FaceSwapper.cpp:225:14: error: ‘current_mask_pixel’ does not name a type
auto current_mask_pixel = mask.row(i).data;
^
FaceSwapper.cpp:226:14: error: ‘current_source_pixel’ does not name a type
auto current_source_pixel = source_image.row(i).data;
^
FaceSwapper.cpp:227:14: error: ‘current_target_pixel’ does not name a type
auto current_target_pixel = target_image.row(i).data;
^
FaceSwapper.cpp:231:18: error: ‘current_mask_pixel’ was not declared in this scope
if (*current_mask_pixel != 0) {
^
FaceSwapper.cpp:232:37: error: ‘current_source_pixel’ was not declared in this scope
source_hist_int[0][*current_source_pixel]++;
^
FaceSwapper.cpp:236:37: error: ‘current_target_pixel’ was not declared in this scope
target_hist_int[0][*current_target_pixel]++;
^
FaceSwapper.cpp:242:13: error: ‘current_source_pixel’ was not declared in this scope
current_source_pixel += 3;
^
FaceSwapper.cpp:243:13: error: ‘current_target_pixel’ was not declared in this scope
current_target_pixel += 3;
^
FaceSwapper.cpp:244:13: error: ‘current_mask_pixel’ was not declared in this scope
current_mask_pixel++;
^
FaceSwapper.cpp:274:10: error: ‘binary_search’ does not name a type
auto binary_search = [&](const float needle, const float haystack[]) -> uint8_t
^
FaceSwapper.cpp:291:78: error: ‘binary_search’ was not declared in this scope
LUT[0][i] = binary_search(target_histogram[0][i], source_histogram[0]);
^
FaceSwapper.cpp:291:78: note: suggested alternative:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from /usr/include/opencv2/core/core.hpp:56,
from /usr/include/opencv2/imgproc/imgproc.hpp:50,
from FaceSwapper.h:3,
from FaceSwapper.cpp:1:
/usr/include/c++/4.8/bits/stl_algo.h:2730:5: note: ‘std::binary_search’
binary_search(_ForwardIterator __first, _ForwardIterator __last,
^
FaceSwapper.cpp:299:14: error: ‘current_mask_pixel’ does not name a type
auto current_mask_pixel = mask.row(i).data;
^
FaceSwapper.cpp:300:14: error: ‘current_target_pixel’ does not name a type
auto current_target_pixel = target_image.row(i).data;
^
FaceSwapper.cpp:303:18: error: ‘current_mask_pixel’ was not declared in this scope
if (*current_mask_pixel != 0)
^
FaceSwapper.cpp:305:18: error: ‘current_target_pixel’ was not declared in this scope
*current_target_pixel = LUT[0][*current_target_pixel];
^
FaceSwapper.cpp:311:13: error: ‘current_target_pixel’ was not declared in this scope
current_target_pixel += 3;
^
FaceSwapper.cpp:312:13: error: ‘current_mask_pixel’ was not declared in this scope
current_mask_pixel++;
^
In file included from main.cpp:3:0:
FaceDetectorAndTracker.h:49:5: error: ‘unique_ptr’ in namespace ‘std’ does not name a type
std::unique_ptrcv::VideoCapture m_camera;
^
FaceDetectorAndTracker.h:54:5: error: ‘unique_ptr’ in namespace ‘std’ does not name a type
std::unique_ptrcv::CascadeClassifier m_faceCascade;
^
FaceDetectorAndTracker.h:90:58: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
bool m_tracking = false;
^
FaceDetectorAndTracker.h:92:25: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
size_t m_numFaces = 0;
^
FaceDetectorAndTracker.h:94:63: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
const double m_tmMaxDuration = 2.0;
^
main.cpp: In function ‘int main()’:
main.cpp:19:18: error: ‘time_start’ does not name a type
auto time_start = cv::getTickCount();
^
main.cpp:25:18: error: ‘cv_faces’ does not name a type
auto cv_faces = detector.faces();
^
main.cpp:26:17: error: ‘cv_faces’ was not declared in this scope
if (cv_faces.size() == num_faces)
^
main.cpp:31:18: error: ‘time_end’ does not name a type
auto time_end = cv::getTickCount();
^
main.cpp:32:18: error: ‘time_per_frame’ does not name a type
auto time_per_frame = (time_end - time_start) / cv::getTickFrequency();
^
main.cpp:34:36: error: ‘time_per_frame’ was not declared in this scope
fps = (15 * fps + (1 / time_per_frame)) / 16;

Very interested in this project and would like little more guidance as well on setup.

There's more instructions in the README now