python mobilenet
Python MobileNet
2023-09-14 09:09:26 时间
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()
相关文章
- termux更改镜像源_pycharm自带python
- python要不要装pycharm-Python和pyCharm安装
- 浙江新增python编程_9月起,浙江省八年级新增Python编程课,未来编程是处理大数据的手段…「建议收藏」
- python电脑版微信-微信PC版的API接口 | 可通过Python调用微信功能
- python 遍历文件夹下所有图片
- python中dtype的使用规范_Python numpy.dtype() 使用实例
- python海龟作图红绿灯_海龟作图—用Python绘图
- Python抓取数据_python抓取游戏数据
- 【说站】python二分支结构如何理解
- h5 Python_python做h5网站
- Python udp编程_python socket udp
- Python保存json_python保存json文件
- 用python进行精细中文分句(基于正则表达式),HarvestText:文本挖掘和预处理工具
- python-Python与SQLite数据库-SQLite数据库的基本知识(二)
- python-Python与PostgreSQL数据库-使用Python执行PostgreSQL查询(一)
- 从Python连接Oracle数据库介绍(python连接oracle)
- 使用Python连接MySQL数据库,实现高效数据交互(python连接mysql)
- Linux Python:开启互联网新时代(linux python)