OpenCV 信号灯状态简单识别

#!/usr/bin/env python
#-*- coding:utf-8 -*- 
import cv2 
import numpy as  np  
import sys,os,shutil
import time
reload(sys)
sys.setdefaultencoding('utf8')
if __name__ == '__main__':
    object_pic = cv2.imread(sys.argv[1])
    rows, cols = object_pic.shape[:2]

    pic_0 = object_pic[0:int(rows*(1/3.0)),0:cols]
    pic_1 = object_pic[int(rows*(1/3.0)):int(rows*(2/3.0)),0:cols]
    pic_2 = object_pic[int(rows*(2/3.0)):rows,0:cols]

    pic_0 = cv2.cvtColor(pic_0,cv2.COLOR_BGR2HSV)
    cv2.imwrite("./pic_0.jpg",pic_0)
    pic_1 = cv2.cvtColor(pic_1,cv2.COLOR_BGR2HSV)
    cv2.imwrite("./pic_1.jpg",pic_1)
    pic_2 = cv2.cvtColor(pic_2,cv2.COLOR_BGR2HSV)
    cv2.imwrite("./pic_2.jpg",pic_2)

    H, S, V = cv2.split(pic_0)
    print np.array(V).sum()
    print "===================================="

    H, S, V = cv2.split(pic_1)
    print np.array(V).sum()

    print "===================================="

    H, S, V = cv2.split(pic_2)
    print np.array(V).sum()

你可能感兴趣的:(OpenCV 信号灯状态简单识别)