簡體   English   中英

Python:對圖像中的對象進行分類

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM