python mobile_python mobilenet

import time

from gluoncv import model_zoo, data, utils

import gluoncv as gcv

from gluoncv.utils import try_import_cv2

cv2 = try_import_cv2()

import mxnet as mx

#import cv2

# Load the model

net = gcv.model_zoo.get_model('ssd_512_mobilenet1.0_voc', pretrained=True)

#net = model_zoo.get_model('yolo3_darknet53_voc', pretrained=True)

# Compile the model for faster speed

net.hybridize()

#import cv2

def gstreamer_pipeline(

capture_width=1280,

capture_height=720,

display_width=1280,

display_height=720,

framerate=60,

flip_method=0,

):

return (

"nvarguscamerasrc ! "

"video/x-raw(memory:NVMM), "

"width=(int)%d, height=(int)%d, "

"format=(string)NV12, framerate=(fraction)%d/1 ! "

"nvvidconv flip-method=%d ! "

"video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! "

"videoconvert ! "

"video/x-raw, format=(string)BGR ! appsink"

% (

capture_width,

capture_height,

framerate,

flip_method,

display_width,

display_height,

)

)

cap = cv2.VideoCapture(gstreamer_pipeline(flip_method=0), cv2.CAP_GSTREAMER)

# Load the webcam handler

#cap = cv2.VideoCapture(0)

time.sleep(1) ### letting the camera autofocus

axes = None

NUM_FRAMES = 200 # you can change this

for i in range(NUM_FRAMES):

# Load frame from the camera

ret, frame = cap.read()

# Image pre-processing

frame = mx.nd.array(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)).astype('uint8')

rgb_nd, frame = gcv.data.transforms.presets.ssd.transform_test(frame, short=512, max_size=700)

# Run frame through network

class_IDs, scores, bounding_boxes = net(rgb_nd)

# Display the result

img = gcv.utils.viz.cv_plot_bbox(frame, bounding_boxes[0], scores[0], class_IDs[0], class_names=net.classes)

gcv.utils.viz.cv_plot_image(img)

# cv2.waitKey(1)

if cv2.waitKey(1) & 0xFF == ord('q'):

# 存储图片

cv2.imwrite("camera.jpeg", frame)

break

cap.release()

cv2.destroyAllWindows()

原文链接:https://blog.csdn.net/luoganttcc/article/details/105738319

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值