欢迎光临散文网 会员登陆 & 注册

python 读取图片信息写入文件

2020-03-10 14:56 作者:一心想当网红的李老师  | 我要投稿

# -*- coding: utf-8 -*-

"""

Created on Tue Mar 10 14:04:43 2020


@author: liyan

"""

import tkinter

from tkinter import *

from PIL import Image,ImageTk

from tkinter.filedialog import askopenfilename

import time

import CV2

import tkinter as tk

import array

import numpy as np



data=[]


def getposBgr(event, x, y, flags, param):

    if event==CV2.EVENT_LBUTTONDOWN:

        print("Bgr is", img[y, x])

        print(img[y, x])

        data.append(img[y, x])

        f=open('data.csv','a')

        f.write(data)

        f.close()


def openfile():

    file_path=askopenfilename()

    img = CV2.imread(file_path)

    HSV = CV2.cvtColor(img, CV2.COLOR_BGR2HSV)

    CV2.imshow('image', img)

    CV2.setMouseCallback("image", getposBgr)

    CV2.waitKey(0)

    CV2.destroyAllWindows()

       

top=tkinter.Tk()

Button1=tkinter.Button(top, text ="选择图片", command = openfile)

Button1.pack(padx=5) # 构建窗口

top.mainloop()


python 读取图片信息写入文件的评论 (共 条)

分享到微博请遵守国家法律