python 多进程同时实现骨架识别、文字识别和二维码识别

学习目标:

提示:骨架识别有别的依赖,没有参考价值。如果只是想实现多进程同时实现文字识别和二维码识别的可以随意看看。

python 多进程同时输入一张图,实现骨架识别、文字识别和二维码识别


学习内容:

输入的图像得既包含人 又包含二维码文字,我就随便网上找了个二维码,然后直接电脑截图了
在这里插入图片描述


代码:

import multiprocessing
import time
import util as cm
import argparse
import os
import easyocr
import cv2
import task2
import SkeletonTrackingImage
from skeletontracker import skeletontracker

def OCR(PATH):
    reader = easyocr.Reader(['ch_sim', 'en'], gpu=False)  # 只需要运行一次就可以将模型加载到内存中
    result = reader.readtext(PATH)
    print(result)
    for i in result:
        word = i[1]
        print(word)


def QR(PATH):
    frame = cv2.imread(PATH)
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    im = task2.decodeDisplay(gray)

    cv2.waitKey(5)
    cv2.imshow("Detect", im)
    cv2.waitKey(1000)
    print("SUCCESS QR DETECT!")
    cv2.destroyAllWindows()

def GetJoints(PATH):
    args = SkeletonTrackingImage.parser.parse_args()

    img = cv2.imread(PATH)
    skeletrack = skeletontracker()
    skeletons = skeletrack.track_skeletons(img)
    cm.render_result(skeletons, img, args.confidence_threshold)
    print("Detected skeletons: ", len(skeletons))
    print(skeletons)
    isSaved = cv2.imwrite("output.jpg", img)
    if isSaved:
        print("The result image is saved in: ", "output.jpg")
    else:
        print("Saving the result image failed for the given path: ", "output.jpg")

    if args.verbose:
        print(skeletons)

    if args.output_image:
        isSaved = cv2.imwrite(args.output_image, img)
        if isSaved:
            print("The result image is saved in: ", args.output_image)
        else:
            print("Saving the result image failed for the given path: ", args.output_image)

if __name__ == '__main__':
    start = time.clock()
    PATH="people+QR.jpg"
    OCR_process = multiprocessing.Process(target=OCR, args=(PATH,))
    QR_process = multiprocessing.Process(target=QR, kwargs={'PATH':PATH}) # target
    GetJoints_process = multiprocessing.Process(target=GetJoints, kwargs={'PATH': PATH})

    #启动进程
    OCR_process.start()
    QR_process.start()
    GetJoints_process.start()
    end = time.clock()
    print('Running test time: %s Seconds' % (end - start))



输出结果:

就是三个程序同时跑
QR输出:
在这里插入图片描述

[INFO] Found QRCODE barcode: http://weixin.qq.com/q/02laFq85IFfSD10000007b
SUCCESS QR DETECT!

OCR输出:

Using CPU. Note: This module is much faster with a GPU.
[([[447, 19], [469, 19], [469, 39], [447, 39]], '十', 0.9694064232314226), ([[548, 200], [614, 200], [614, 224], [548, 224]], 'J飞桨', 0.04646419104456546)]
十
J飞桨

骨架识别输出:
在这里插入图片描述

Initialising the Skeleton Tracking 
Detected skeletons:  1
[SkeletonKeypoints(joints=[Coordinate(x=159.10357666015625, y=151.125), Coordinate(x=165.5976104736328, y=180.375), Coordinate(x=139.6215057373047, y=183.625), Coordinate(x=136.37449645996094, y=222.625), Coordinate(x=146.11553955078125, y=261.625), Coordinate(x=185.07968139648438, y=180.375), Coordinate(x=185.07968139648438, y=222.625), Coordinate(x=172.0916290283203, y=255.125), Coordinate(x=149.362548828125, y=258.375), Coordinate(x=159.10357666015625, y=316.875), Coordinate(x=168.84461975097656, y=365.625), Coordinate(x=178.5856475830078, y=258.375), Coordinate(x=185.07968139648438, y=313.625), Coordinate(x=188.32669067382812, y=368.875), Coordinate(x=155.8565673828125, y=147.875), Coordinate(x=165.5976104736328, y=147.875), Coordinate(x=149.362548828125, y=147.875), Coordinate(x=172.0916290283203, y=147.875)], confidences=[0.8960610628128052, 0.8762086033821106, 0.8915107250213623, 0.8231115937232971, 0.927017092704773, 0.8750684261322021, 0.8468186855316162, 0.8317177295684814, 0.845022439956665, 0.9005998969078064, 0.8683494329452515, 0.7987264394760132, 0.8966251611709595, 0.9470148086547852, 0.8775635957717896, 0.8433065414428711, 0.7787574529647827, 0.7931344509124756], id=1, id_confirmed_on_cloud=False)]
The result image is saved in:  output.jpg

由于他们是同时进行的,所以运行栏里其实输出是三个程序杂糅在一起,如下图:
在这里插入图片描述
有空看看能不能把输出都集合在一张图上,好看一点。
6.12更新都集合在一张图上(用的单进程):

import multiprocessing
import time
import util as cm
import argparse
import os
import easyocr
import cv2
import task2
import SkeletonTrackingImage
from skeletontracker import skeletontracker

def OCR(frame):
    reader = easyocr.Reader(['ch_sim', 'en'], gpu=False)  # 只需要运行一次就可以将模型加载到内存中
    result = reader.readtext(frame)
    print(result)
    for i in result:
        word = i[1]
        print(word)


def QR(frame):
    #frame = cv2.imread(PATH)
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    img = task2.decodeDisplay(gray,frame)
    '''
    cv2.waitKey(5)
    cv2.imshow("Detect", im)
    cv2.waitKey(1000)
    print("SUCCESS QR DETECT!")
    '''
    return img
    #cv2.destroyAllWindows()

def GetJoints(frame):
    args = SkeletonTrackingImage.parser.parse_args()
    img = frame
    skeletrack = skeletontracker()
    skeletons = skeletrack.track_skeletons(img)
    cm.render_result(skeletons, img, args.confidence_threshold)
    print("Detected skeletons: ", len(skeletons))
    print(skeletons)
    isSaved = cv2.imwrite("output.jpg", img)
    '''
    if isSaved:
        print("The result image is saved in: ", "output.jpg")
    else:
        print("Saving the result image failed for the given path: ", "output.jpg")

    if args.verbose:
        print(skeletons)

    if args.output_image:
        isSaved = cv2.imwrite(args.output_image, img)
        if isSaved:
            print("The result image is saved in: ", args.output_image)
        else:
            print("Saving the result image failed for the given path: ", args.output_image)
    '''
    return img


if __name__ == '__main__':
    while True:
        camera = cv2.VideoCapture(0)
        ret, frame = camera.read()
        frame = cv2.imread("people+QR.jpg")
        im = GetJoints(frame)
        im = QR(im)
        OCR(frame)
        cv2.waitKey(5)
        cv2.imshow("Detect", im)
        cv2.waitKey(100)


    #start = time.clock()

    #PATH="people+QR.jpg"
    #OCR_process = multiprocessing.Process(target=OCR, args=(PATH,))
    #QR_process = multiprocessing.Process(target=QR, kwargs={'PATH':PATH}) # target
    #GetJoints_process = multiprocessing.Process(target=GetJoints, kwargs={'PATH': PATH})

    #启动进程
    #OCR_process.start()
    #QR_process.start()
    #GetJoints_process.start()
    #end = time.clock()
    #print('Running test time: %s Seconds' % (end - start))


  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值