featuresColor.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:recognizeFitExercise 作者: tyiannak 项目源码 文件源码
def getRGBS(img, PLOT = False):

    image = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)

    # grab the image channels, initialize the tuple of colors,
    # the figure and the flattened feature vector   
    features = []
    featuresSobel = []
    Grayscale = cv2.cvtColor(img, cv2.cv.CV_BGR2GRAY)
    histG = cv2.calcHist([Grayscale], [0], None, [16], [0, 256])
    histG = histG / histG.sum()
    features.extend(histG[:,0].tolist())


    grad_x = np.abs(cv2.Sobel(Grayscale, cv2.CV_16S, 1, 0, ksize = 3, scale = 1, delta = 0, borderType = cv2.BORDER_DEFAULT))
    grad_y = np.abs(cv2.Sobel(Grayscale, cv2.CV_16S, 0, 1, ksize = 3, scale = 1, delta = 0, borderType = cv2.BORDER_DEFAULT))
    abs_grad_x = cv2.convertScaleAbs(grad_x)
    abs_grad_y = cv2.convertScaleAbs(grad_y)
    dst = cv2.addWeighted(abs_grad_x,0.5,abs_grad_y,0.5,0)
    histSobel = cv2.calcHist([dst], [0], None, [16], [0, 256])
    histSobel = histSobel / histSobel.sum()
    features.extend(histSobel[:,0].tolist())

    Fnames = []
    Fnames.extend(["Color-Gray"+str(i) for i in range(8)])
    Fnames.extend(["Color-GraySobel"+str(i) for i in range(8)])

    return features, Fnames
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号