adrianiainlam / facial-landmarks-for-cubism

Extracts facial landmarks from webcam (provided by OpenSeeFace) and converts to Live2D Cubism SDK parameters
MIT License
63 stars 10 forks source link

good work! do you have a version supporting windows? #5

Closed 1234269 closed 1 year ago

adrianiainlam commented 2 years ago

The current version on master is designed for Unix-like environments only due to its use of <sys/socket.h> to communicate with OpenSeeFace. You could try Cygwin. It may work but I haven't tried it myself.

The old version using dlib should be more or less cross-platform compatible. See section "Supporting environments" in the README for more details.

If you would like to try either of the options above, and encounter any problems, feel free to post them here and I'll do my best to help.

Arkueid commented 1 year ago

I tried replacing \<sys/socket.h> with \, which was mentioned in the article, and facial_landmark_detector worked well on windows. Changes be like:

#ifdef _WINDOWS
    #include <WinSock2.h>
    #include <ws2tcpip.h>
    #include <basetsd.h>
    typedef SSIZE_T ssize_t;
    typedef unsigned short unint16_t;
#else  //for linux
    #include <sys/socket.h>
    #include <arpa/inet.h>
    #include <unistd.h>
#endif

...

FacialLandmarkDetector::FacialLandmarkDetector(std::string cfgPath)
    : m_stop(false)
{
    parseConfig(cfgPath);

#ifdef _WINDOWS  //WinSock2 should be initialized before using
    WSADATA wsaData;
    if (WSAStartup(MAKEWORD(2, 2), &wsaData)!=0)
    {
        return;
    }
#endif

...

FacialLandmarkDetector::~FacialLandmarkDetector()
{
#ifdef _WINDOWS
    closesocket(m_sock);
#else 
    close(m_sock);
#endif
}

...

void FacialLandmarkDetector::mainLoop(void)
{
    while (!m_stop)
    {
        // Read UDP packet from OSF
        static const int nPoints = 68;
        static const int packetFrameSize = 8 + 4 + 2 * 4 + 2 * 4 + 1 + 4 + 3 * 4 + 3 * 4
                                         + 4 * 4 + 4 * 68 + 4 * 2 * 68 + 4 * 3 * 70 + 4 * 14;

        static const int landmarksOffset = 8 + 4 + 2 * 4 + 2 * 4 + 1 + 4 + 3 * 4 + 3 * 4
                                         + 4 * 4 + 4 * 68;
#ifdef _WINDOWS  //not sure why unint8_t does not work
        char buf[packetFrameSize];
#else
        uint8_t buf[packetFrameSize];
#endif

...
adrianiainlam commented 1 year ago

@Arkueid Thank you for your contribution! I have added your changes, and credited you in README.md and in the commit message.