Toybrick

标题: RK1808M0 在PC端运行 [打印本页]

作者: anqingcheng    时间: 2020-11-6 18:01
标题: RK1808M0 在PC端运行
import numpy as np
import cv2
import yolov3 as yolov
from rknn.api import RKNN

if __name__ == '__main__':


    capture = cv2.VideoCapture(0)  # VideoCapture 读取本地视频和打开摄像头
    height = capture.get(cv2.CAP_PROP_FRAME_HEIGHT)  # 计算视频的高
    width = capture.get(cv2.CAP_PROP_FRAME_WIDTH)  # 计算视频的宽

    print(height)
    print(width)

    # cv2.VideoWriter 保存摄像头视频            #VideoWriter_fourcc()输入四个字符代码即可得到对应的视频编码器
    out = cv2.VideoWriter("D:/demo.mp4", cv2.VideoWriter_fourcc('D', 'I', 'V', 'X'), 15,
                          (np.int(width), np.int(height)), True)
    # Create RKNN object
    rknn = RKNN()
    print('done')
    rknn.load_rknn(path='./yolov3_tiny.rknn')
    ret = rknn.init_runtime()
    if ret != 0:
         print('Init runtime environment failed')
         exit(ret)

    while True:
        ret, frame = capture.read()
        if ret is True:
            frame = cv2.flip(frame, 1)  # cv2.flip 图像翻转

            rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)  # cvtColor()颜色空间转换函数

            cv2.imshow("frame", rgb)
            x, y = rgb.shape[0:2]

            cv2.resize(rgb, (416, 416), rgb)
            #cv2.imwrite("aa.jpg",rgb);
            # Inference
            print('--> Running model')
            outputs = rknn.inference(inputs=[rgb])
            data = yolov.post_process(outputs)
            print(data)

            c = cv2.waitKey(10)
            if c == 27:
                break
        else:
            break
    cv2.destroyAllWindows()
    rknn.release()
    # perf
    print('--> Begin evaluate model performance')
    #perf_results = rknn.eval_perf(inputs=[img])
    print('done')


/home/gerrard/PycharmProjects/pythonProject/venv/bin/python /home/gerrard/PycharmProjects/pythonProject/yolov3_test.py
done
--> Running model
W [rknn_inputs_set:2063] warning: inputs[0] expected input len is 519168, but actual len is 921600!
(None, None, None)
W [rknn_inputs_set:2063] warning: inputs[0] expected input len is 519168, but actual len is 921600!
--> Running model
(None, None, None)
W [rknn_inputs_set:2063] warning: inputs[0] expected input len is 519168, but actual len is 921600!
--> Running model
(None, None, None)
W [rknn_inputs_set:2063] warning: inputs[0] expected input len is 519168, but actual len is 921600!
--> Running model

使用的是官方的./yolov3_tiny.rknn模型,但是一直识别失败!


作者: jefferyzhang    时间: 2020-11-7 09:52
失败日志是什么?
计算卡的rknn driver升级到最新的了么?
rknntoolkit和计算卡的drv版本是否匹配




欢迎光临 Toybrick (https://t.rock-chips.com/) Powered by Discuz! X3.3