我們之前搞到了xml檔案,這裡不想多說咧,直接啪嗒啪嗒,上**
coding:utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
# __author__ = 'f s'
# __date__ = '2018/7/28'
# __desc__ = 人臉檢測小例子,以圓圈圈出人臉
#import cv2.cv as cv
import cv2
import numpy as np
import socket
import time
import sy
sfrom pil import image
from cv2 import videocapture
cap = cv2.videocapture(0)
bycap.set(3,320)# set width
cap.set(4,240)# set height
server_ip = "192.168.4.1"
server_port = 8888
print("starting socket: tcp...")
server_addr = (server_ip, server_port)
socket_tcp = socket.socket(socket.af_inet, socket.sock_stream)
print("starting socket: tcp...")
server_addr = (server_ip, server_port)
socket_tcp = socket.socket(socket.af_inet, socket.sock_stream)
# 待檢測的路徑
face_cascade = cv2.cascadeclassifier(r'/home/pi/desktop/opencv-master/data/haarcascades_cuda/haarcascade_frontalface_alt.xml')
signal_cascade = cv2.cascadeclassifier(r'/home/pi/desktop/cascade.xml')
while true:
try:
print("connecting to server @ %s:%d..." %(server_ip, server_port))
socket_tcp.connect(server_addr)
break
except exception:
print("can't connect to server, try it latter!")
time.sleep(1)
continue
print("receiving package...")
while (true) :
ret,frame = cap.read()
frame = cv2.flip(frame,-1)# flip camera vertically
gray=frame
#gray = cv2.cvtcolor(frame, cv2.color_bgr2gray)
# 探測中的人臉
faces = face_cascade.detectmultiscale(
gray,
scalefactor = 1.20,
minneighbors = 4,
minsize = (4,4),
flags = 0
)asigns = signal_cascade.detectmultiscale(
gray,
scalefactor = 1.20,
minneighbors = 4,
minsize = (4,4),
flags = 0
)if len(faces) > 0:
print "發現個人臉!".format(len(faces))
try:
if len(faces) == 1 : sa
socket_tcp.send("frolef")
elif len(faces) == 2 :
socket_tcp.send("backwa")
else :
print("wrongg")
time.sleep(1)
except exception:
socket_tcp.close()
socket_tcp = none
sys.exit(1)
if len(signs) > 0:
print "發現個signs!".format(len(signs))
try:
if len(signs) == 1 :
socket_tcp.send("threee")
else :
print("wrongg")
time.sleep(1)
except exception:
socket_tcp.close()
socket_tcp = none
sys.exit(1)
for(x,y,w,h) in faces:
# cv2.rectangle(gray,(x,y),(x+w,y+w),(0,255,0),2)
#if w > 50 and h > 50 :
cv2.circle(gray,((x+x+w)/2,(y+y+h)/2),w/2,(0,255,0),2)
print x,y,w,h
for(x,y,w,h) in signs:
# cv2.rectangle(gray,(x,y),(x+w,y+w),(0,255,0),2)
#if w > 50 and h > 50 :
cv2.circle(gray,((x+x+w)/2,(y+y+h)/2),w/2,(0,255,0),2)
print x,y,w,h
cv2.imshow("find faces!",gray)
k = cv2.waitkey(30)
if k ==27:# press 'esc' to quit
break
cap.release()
cv2.destroyallwindows()
樹莓派基於分類器的識別環保標誌(一)
首先,樹莓派的系統映象安裝和和分盤網上均有詳細教程這裡不再列舉。要說明的是在樹莓派上opencv安裝是可以非常簡單的,除了wget到原始碼解壓縮以後編譯,自然就是我們只需要幾條指令的apt方式安裝了 sudo apt get update sudo apt get upgrade 這步我沒執行,耗時...
樹莓派基於python的pwm產生
import rpi.gpio as gpio 匯入gpio口驅動模組 import time 匯入時間模組 pwm pin 18 定義pwm輸出引腳 gpio.setmode gpio.bcm 定義樹莓派gpio引腳以bcm方式編號 gpio.setup pwm pin,gpio.out 使能gp...
基於SVM分類器的動作識別系統
摘 要 動作識別領域近年來隨著動作採集技術的成熟而高速發展,因其無需借助任何 計算機系統的傳統輸入裝置就能夠準確識別出使用者意圖,對三維動作資料進行資料 處理與挖掘的技術,現已廣泛運用到了計算機動畫 遊戲 新型人機互動和智慧型家居控制等領域。支援向量機 support vector machine,...