基于聚类的实时图像分割

 基于聚类的实时图像分割,我最近也是自己瞎玩,但是这样的情况比较糟糕,实时性差的不行不行的,问题比较多  接着需要优化方法和代码了

# Des:This is a machine learning 0f cluster program!
# Date:2020-3-12
# Author:Gaofeng 

import numpy as np
import PIL.Image as image
from sklearn.cluster import KMeans
import cv2

if __name__ == "__main__":
    try:
        capture=cv2.VideoCapture(0)  # 0是代表摄像头编号,只有一个的话默认为0
        while(True):
            ref,orinal_image=capture.read()
            data = []
            img = image.fromarray(cv2.cvtColor(orinal_image, cv2.COLOR_BGR2RGB))
            row, col = img.size
            for i in range(row):
                for j in range(col):
                    x,y,z = img.getpixel((i,j))
                    data.append([x/256.0, y/256.0, z/256.0])
            imgData = np.mat(data)
            label = KMeans(n_clusters=3).fit_predict(imgData)  
            label = label.reshape([row,col])
            pic_new =
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值