[英]Python: classify objects in images
camera = webcam; % Connect to the camera
nnet = alexnet; % Load the neural net
while true
picture = camera.snapshot; % Take a picture
picture = imresize(picture,[227,227]); % Resize the picture
label = classify(nnet, picture); % Classify the picture
image(picture); % Show the picture
title(char(label)); % Show the label
drawnow;
end
我在互联网上找到了这个matlab代码。 它显示一个窗口,其中包含来自网络摄像头的图片,并且非常快速地命名图片中的内容(“键盘”,“布特”,“铅笔”,“时钟”......)。 我想在python中做到这一点。 到目前为止我有这个:
import cv2
import sys
faceCascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
video_capture = cv2.VideoCapture(0)
while True:
ret, frame = video_capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.cv.CV_HAAR_SCALE_IMAGE
)
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
这是非常相似的,但只检测面部。 matlab代码使用alexnet。 我想这是一个基于imagenet数据的预训练网络( http://www.image-net.org/ )。 但它已不再可用。 我怎么能在python中这样做?
(这里有一个类似的问题,但它已经过了4年了,我认为现在有更新的技术)。
使用“tensorflow”软件包和预先培训的网络“vgg16”,解决方案非常简单。 请参阅https://github.com/machrisaa/tensorflow-vgg/blob/master/test_vgg16.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.