甘肃建设局网站,丰都网站建设公司,网站基础代码html,桂电做网站的毕设容易过嘛相关库安装指导#xff1a;这里我们需要 opencv_python#xff0c;numpy#xff0c;matplotlib库#xff0c;另外我用的是python3.6.1版本。一般库大家都是用pip install命令安装的#xff0c;不过不知道为啥这里的opencv_python库总是抽风#xff0c;就是安装不了(起码我…相关库安装指导这里我们需要 opencv_pythonnumpymatplotlib库另外我用的是python3.6.1版本。一般库大家都是用pip install命令安装的不过不知道为啥这里的opencv_python库总是抽风就是安装不了(起码我周围都是这样)。所以以上哪个库如果下载不动啥的可以去这里下载海克斯科技传送门如果不知道下载哪个版本可以通过import pip; print(pip.pep425tags.get_supported())这条命令来查看你的python所支持的whl 文件类型(否则容易发生* is not a supported wheel on this platform错误)如图之后可以通过“import”对应的库来验证是否安装成功。python opencv实现提取png图像的像素信息并存储到txt文件中代码注意这里的文件路径要根据个人情况修改。import cv2import numpyimport pylabimport matplotlib.pyplot as pltimgfile input(请输入图片名)txtfile input(请输入存储文本文件名)img cv2.imread(C:/Users/Jake/Desktop/test01/imgfile,cv2.IMREAD_GRAYSCALE)print(图像的形状,返回一个图像的(行数,列数,通道数):,img.shape)print(图像的像素数目:,img.size)print(图像的数据类型:,img.dtype)#----------------------------------------------------------------------------In windows the COLOR-GRAYSCALE: Y 0.299R0.587G0.114B 测试是否三个通道的值是相同的。某些图像三通道值相同可以直接读灰度图来代替读单一通道。# sum 0# ans 0# for i in range(562):# for j in range(715):# if not(img[i][j][0] img[i][j][1] and img[i][j][1] img[i][j][2]):# sum 1# else:# ans 1# print(ans)# print(sum)#-----------------------------------------------------------------------------将图片数据写入txt文件格式:基础信息行号:像素值行号:像素值......fname open(C:/Users/Jake/Desktop/test01/txtfile,w)fname.write(图像的形状,返回一个图像的(行数,列数,通道数):str(img.shape)\n)#----1fname.write(图像的像素数目:str(img.size)\n)#----2fname.write(图像的数据类型:str(img.dtype)\n)#----3Xlenth img.shape[1]#图片列数Ylenth img.shape[0]#图片行数a 1#----4for i in range(Ylenth):fname.write(str(a) :\n)#----5for j in range(Xlenth):fname.write(str(img[i][j]) )a 1#----6fname.write(\n)fname.close()#---------------------------------------------------------------------------将txt文件中的数据读取进blist并显示为test图片框进行测试。注意进行测试前需要注释掉数据写入模块中标记的六行代码要不然读取会出错误。# blist []# split_char # with open(C:/Users/Jake/Desktop/test01/txtfile, r) as bf:# blist [b.strip().split(split_char) for b in bf]###从txt文件读入进来的值类型是char需要转换为int# for i in range(Ylenth):# for j in range(Xlenth):# blist[i][j] int(blist[i][j])## tlist numpy.array(blist)# plt.figure()# plt.imshow(tlist)# plt.axis(off) # 不显示坐标轴# pylab.show()#------------------------------------------------------------------------------将图片显示在image图片框cv2.imshow(image,img)cv2.waitKey(0)cv2.destroyAllWindows()#----------------------------------------------------------------------