• GO 调用 python3 (基于ubuntu) 实现人脸识别


    本次用go 调用python3 足足花了两天的时间

    1、go协程中多次调用python函数

    (80条消息) Golang协程中调用Python3_可问春风丶的博客-CSDN博客_golang调用python3

    2、安装参考的链接

    (48条消息) go调用python3:go-python3包的使用_文杰@的博客-CSDN博客_go调用python

    3、如何在wsl的中安装ubuntu

    Windows Subsystem for Linux(简称WSL)是一个在Windows 10\11上能够运行原生Linux二进制可执行文件(ELF格式)的兼容层。它是由微软与Canonical公司合作开发,其目标是使纯正的Ubuntu、Debian等映像能下载和解压到用户的本地计算机,并且映像内的工具和实用工具能在此子系统上原生运行。

    操作系统:ubuntu20.04.5 (WSL)

    重复的部分我不赘述了。

    ====================初始化相关工作

    ubuntu20.04.5 需要 更新源,升级,并且安装桌面,安装桌面的目的是我在ubuntu下编译文档

    sudo apt update
    sudo apt-get upgrade
    sudo apt install ubuntu-desktop

    下载Xming-6-9-0-31-setup.exe,启动Xming

    环境变量默认DISPLAY是0.0

    vim ~/.bashrc

    export DISPLAY=:0.0
    source ~/.bashrc

    ====================下载编译器

    GoLand-2022.2.2(linux):goland的编译器

    Anaconda3-2020.11-Linux-x86_64(conda很好用不然我ptyhon整了半天很麻烦):安装python3.7,非常的重点只能安装3.7

    ====================安装过程

    conda create -n fs_py37 python=3.7
    conda activate fs_py37 :默认3.7为运行环境

    export PKG_CONFIG_PATH=/Users/xwj/opt/anaconda3/envs/fs_py37/lib/pkgconfig
    go get github.com/DataDog/go-python3 (使用go get的前提是安装了go1.16.xx

    sudo apt-get install pkg-config

    sudo apt-get install cmake gcc g++   :这个是为了python 安装dlib的库

    ======================我的项目结构

    python的代码==========

    import cv2
    import face_recognition
    def test(xx):
        print("ok   ============================")
        return "hilllllllllllllllll"

    def SayHello(xixi):
        #  导入待检测照片
        face_image1 = face_recognition.load_image_file(r"/home/kiki/testdata/images/3.jpg")
        #  进行人脸识别
        face_encoding1 = face_recognition.face_encodings(face_image1)
        #  得到识别数据
        face1 = face_encoding1[0]
        #face2 = face_encoding2[0]
        #  人脸数据比对
        result = face_recognition.compare_faces([face1],face1,tolerance=0.4)
        #  如果结果是同一人显示PASS,否则显示NO
        if result == [True]:
            name = "PASS"
        else:
            name = "NO"
        #  脸部区域绘图
        '''
        for (x1,y1,w1,h1)in face_encoding1:
            img1 = cv2.rectangle(face_image1,(y1,w1),(h1,x1),(255,0,0),2)  # 脸部框图绘制
            cv2.putText(face_image1,name,(y1-10,w1-10),cv2.FONT_HERSHEY_COMPLEX,0.8,(0,255,0),2)
        frame1 = cv2.cvtColor(face_image1,cv2.COLOR_BGR2RGB)
        '''
        #  脸部区域绘图
        print(name)
        #  结果显示
        #cv2.imshow("1",frame1)
        cv2.waitKey(0)

    if __name__ == '__main__':
       SayHello("ddd")

    安装python是非常麻烦的,尤其是这个库
    sudo apt-get install cmake gcc g++  

    pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python
    pip install -i https://pypi.tuna.tsinghua.edu.cn/simple face_recognition
    pip install -i https://pypi.tuna.tsinghua.edu.cn/simple dlib
    pip install -i https://pypi.tuna.tsinghua.edu.cn/simple cmake

    go的代码:引用的文档有完整的案例

    整个过程痛点,就是安装以及部署以及调试。

    为啥要用go + python

    主要是速度,开发的稳定性及实现效果的速度,go是稳定担当,python是算法模型的担当。

  • 相关阅读:
    C++中setfill,setw,setbase,setprecision的作用
    代码随想录-024-454.四数相加 II
    建立JDBC连接
    C++简单实现多态案例-制作饮品
    人工智能的未来———因果推理:Causal Inference: What If chapter2 A Randomized experiments 文章解读
    leetcode-合并二叉树-90
    最小花费——最短路
    Go 原生插件使用问题全解析
    R23C02版本正式发布 | 更智能、更稳定的菊风视频能力平台
    异步性能不如同步?通过压测讨论应该如何设置线程数
  • 原文地址:https://blog.csdn.net/gigizhongyan/article/details/126937700