首页 > 编程知识 正文

色彩提取与重构图片,色彩的采集与重构作业图

时间:2023-05-06 12:53:44 阅读:59484 作者:1960

目录

镜像

shot.py

修改main.py

颜色提取

原理

准备安装软件包

生成缩略图

获得群集中心

镜像前的内容分别实现了散列平均和直方图镜像,以及pycharm的基本使用和逐帧提取,但这次将两者的内容结合起来,pycharm同时实现了逐帧提取和镜像

shot.py在此步骤中使用平均散列进行镜像,比较是否重复,并保存不重复的图像

导入c v2导入端口matplotlib.pyplotaspltimportos #平均散列算法defahash(img ) : #是8*8img=cv2.resize ) img,(8, 8 ) )按比例缩放到plize的hash_str为hash值,初始值为' s=0 hash_str='' #扫描累积相加像素和forIinrange(8) : for j in range(8) j] #求平均灰度avg=s/64 #灰度是生成平均值大于1相反为0的图像的混列值forIinrange(8) : for j in range(8) : if gray[i, j ) avg : hash _ str=hash _ str '1' else : hash _ str=hash _ str '0' return hash _ str # hash值比较sim=0defcmphash )扫描判定forIinrange(Len ) Hash1 ) ) : )不相等时n计数1,n最终相似度if hash1[i]!=hash2[ I ] : n=n1sim=1- n/64 returnsimdefgenframe () : image _ save='/users/MAC /桌面/courses/a adapt shot ' if not (OS.path.exists ) image_save ) :OS.mkdir ) image_save ) cap=cv2.videocapture ) GHz . ) cv2.im write ((/users/MAC/desktop/courstop ) ) ) ) 65 img1) #while(cap.isopened () : forinration img2=cap.read ) ) #cv2.imshow ) () ) ) img2) hasH1=ahash(img1) hash2=ahash ) img2) n=CMPhash ) has hash

from flask导入flask, render _ templateapp=flask (_ name _ () app.route ) )/shot ' (def shot ) ) : path=' static/hash ' file er filer ) ) print ) filename ) print ) type(filename ) ) ) print ) filename hist ' hist file=OS.list dir (path ) hist count=-4]针对列表中的元素返回return render _ template (shot.html ),filename=filename,framecount=framecount,hist file=hile

颜色提取原理k均值聚类原理:对于给定样本集,根据样本之间距离的大小,将样本集划分为k个聚类。 尽量紧密地连接集群内的点,尽量增大集群之间的距离。

安装软件包准备安装Scipy

缩略图importnumpyasnpimportosfrompilimportimageimportmatplotlib.pyplotaspltos.chdir (r '/users/MAC /桌面/courses 生成chdir )的im=NP.array (image.open (lake.jpg ) )缩略图群集defcolorz ) filename,n=3) :img=image.open w*h ) PLT.axis ) off ) ) plt.show ) img ) plt.show ) ) points=[] for count,colorinimin

获取集群中心importos.pathfromflaskimportflask, render _ templatefrompilimportimageimportmatplotlib.pyplotaspltimportnumpyasnpfromscipy.cluster.vqimportvq,kmeans,wwww n=3) :img=image.open(filename ) img.thumbnail ) ) w,h=img.size w*h ) PLT.axis(off ) ) plt.show ) colorinimg.getcolors(w*h ) :points.append ) color ) returnpointsdefkmeanscolor(img, n ) :points=colorz ) ) n distortion=k means (centers=NP.array ) codebook, dype=float (returncentersos.chdir (r '/users/MAC/desktop/courses/ad/python/2021 11 05 ' ) points=colorz ) ) Fe=NP.array ) points,dtype=Float ) #群集必须为float或doublepoints ) Fe[0:10] ) book=的初始值print (类型) distortion=kmeans ) Fe,book ) codebook,distortion 2表示两个重心,同时代表iter参数print(codebook: (,codebook ) )集群中心ccenter dtype=int ) )必须启用并改变颜色,转换为整数print )的distortion(Fe=NP.Array(points ) PLT.Scatter ) Fe [ :0 ],FFE

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。