图片坐标提取软件/图片坐标点和像素点颜色提取软件/图片坐标获取工具/Python图片坐标获取源码/图片像素坐标获取软件/查看图片点XY坐标(完全开源)

这篇具有很好参考价值的文章主要介绍了图片坐标提取软件/图片坐标点和像素点颜色提取软件/图片坐标获取工具/Python图片坐标获取源码/图片像素坐标获取软件/查看图片点XY坐标(完全开源)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

该软件使用python写的,可以提取像素点的坐标还有也能获取像素点的16进制数据RGB565和RGB888(RGB888仅最新的源码才支持),可以单点坐标也可以按键坐标,甚至可以使用简单的左右键配合使用,自动复制到粘贴板,如果图片太大或者太小,也支持图片缩小放大,但是软件会对像素进行处理不建议这么干。        

该软件支持现有常用格式的bmp、jpg、gif和png等格式,也可以自定义xy复制到粘贴板的比例。

程序已经打包成exe文件可直接双击运行

如果需要自己修改,使用pyinstaller -F -w  指令来完成打包

打包步骤是打开cmd窗口,输入:pip install pyinstaller(安装pyinstaller,已经安装可跳过)

其他第三方库安装命令:

安装opencv : pip install opencv-python

安装pillow:pip install pillow

安装ny库:pip install numpy

安装pyperclip库:pip install pyperclip

然后输入pyinstaller -F -w 【文件路径】

例如:pyinstaller -F -w C:\\Users\MSN\Desktop\11\PythonApplication1.py

如果openCV无法打包则可以尝试使用此指令:pyinstaller -F -w C:\\Users\MSN\Desktop\11\ImageToolsv1.8.py --hidden-import opencv-python

也可以参考此链接Python PyInstaller安装和使用教程(详解版) (biancheng.net)

运行平台已经测试过win7,win8,win10,Win11都能运行(V1.7版本以下,V1.9以上可能需要单独下载各自系统的exe文件)

以下是最新完整工程源码和exe执行文件链接(最新更新2022.12.28):

像素点坐标提取源码/Python提取图片坐标/Python图片坐标获取源码-Python文档类资源

最新打包好的最新的exe,更好的GUI布局,支持窗口自由放大缩小(最新更新2022.12.28):

Python图片像素点坐标提取工具/Python提取图片坐标软件/迪文图片坐标获取工具

在后面的版本中有些第三方库存在系统兼容性问题,因此对windows各版本单独生成了独立的exe可执行文件,在以下的百度网盘链接中,源码维持不变

exe文件在以下链接(推荐上面的下载方式支持开源,或者点赞评论不做白嫖怪)(2023.04.05做出修改):

百度网盘链接:https://pan.baidu.com/s/1aoE8RcjAgMZQ7BJ9zaKe1Q?pwd=a8b1 
提取码:a8b1

相比于第一版,后期更新支持如下

1、支持RGB888和RGB565

2、支持图片自由放大缩小(快捷键ctrl+鼠标滚轮)

3、新增图片复位

4、最大化不会gui布局错误

5、修复部分bug

6、图片放大缩小算法由近邻法修改为面积插值法

如有相关问题可联系:QQ:1257784610

以下是最新更新展示

图片坐标拾取工具,Python,图片坐标提取,python,单片机,stm32,arm,图像处理

 文章来源地址https://www.toymoban.com/news/detail-608106.html

 通过此处可修改开的图片格式

 

图片坐标拾取工具,Python,图片坐标提取,python,单片机,stm32,arm,图像处理

 

自动获取功能:

鼠标左键单击:        单点坐标
鼠标左键按下移动:    按键坐标
鼠标滚轮单击:        像素颜色
鼠标右键按下并移动:    切图坐标

按键坐标就是一个矩形坐标:(左上角X坐标,左上角Y坐标,右下角X坐标,右下Y坐标)

切图坐标就是一个矩形坐标+放的坐标:(左上角X坐标,左上角Y坐标,右下角X坐标,右下Y坐标,左上角X坐标,左上角Y坐标)(此功能适合嵌入式贴图编程)

单点坐标就是一个点坐标:(X坐标,Y坐标)

Ctrl+鼠标上下滚轮可以缩小放大图片

像素颜色是16进制的RGB565和RGB888,默认是RGB565

自动复制是指操作后坐标数据自动拷贝到粘贴板上

转换系数是指:比如我需要把800*600的图坐标放大为1024*768,就往里面输入1024/768 = 1.28,输入1.28并且点击设置xy系数就能获取比例放大的坐标信息,注意这个不会修改图片的任何信息,要保持原来的就输入1,算法是:显示的X坐标 = 获取的X坐标*X比例系数     

        例如:800 * 1.28 = 1024

把自动获取取消后,单击就是对应的坐标

软件也支持图片快捷键ctrl+鼠标滚轮进行缩小放大,但是不建议缩太小和放太大,除非你的电脑配置顶天,同时此功能会影响最大像素值的大小,放大缩小越多,误差会越大,请慎重使用 

 

图片坐标拾取工具,Python,图片坐标提取,python,单片机,stm32,arm,图像处理

下面的都是源码(旧源码),但是由于时间仓促并没有对代码进行整理,不然的话可以更简洁,由于工作使用的都是C语言,因此代码逻辑很像C语言,如果哪天我有空我会对代码进行整理,编译软件我用的是微软的VS2022,也可以使用Python 3.10版本的IDLE进行编程以下是代码所需的库,有特殊需求的可以自己修改源码 

最新的源码可以自己去上面的链接中获取,如果不用RGB888的话,旧版的也够用了       

以下是代码所需库  

from asyncio.windows_events import NULL
import tkinter as tk
import pyperclip
from PIL import Image
from PIL import ImageTk
from tkinter import filedialog
import sys

以下是程序所需宏定义,像素数单双都行

sys.setrecursionlimit(100000) #设置递归深度
#像素数必须为双数
Start_x = 1
Start_y = 1
End_x = 2
End_y = 2
YRadioVar = 1.0000
XRadioVar = 1.0000
Image



        以下是Python新增创建组件和窗口的代码

ws = tk.Tk()
ws.title('Guides QQ:1257784610')
ws.geometry('1100x700+888+444')
pw1=tk.PanedWindow(ws,orient=tk.HORIZONTAL,width = 100,height = 100,sashrelief='groove') # 创建横向分割面板
pw1.pack(fill=tk.BOTH,expand=True) # 尺寸扩展到整个窗体
frame = tk.Frame(pw1 ,width = 900,height = 700)
ws.update_idletasks()
get_fp = filedialog.askopenfilename(filetypes = [("BMP",".bmp"),("PNG",".png"), ("GIF",".gif"),("JPG",".jpg")])


ws.title('Guides QQ:1257784610    '+str(get_fp))
image = Image.open(get_fp)
#获取图片像素点大小
high = image.height   #高度
width = image.width  #宽度
#print(high,width)
if (high%2) != 0:
    high = high-1
if (width%2) != 0:
    width = width-1
canvas=tk.Canvas(
    frame,
    
    bg='#4A7A8C',
    width=100,
    height=100,
    scrollregion=(2,2,width+3,high+3)     #  2改为0会导致光标和画布有点偏移,取消滚动功能就正常
    )
canvas.imagecolor = image.convert('RGB')
canvas.src_strlist = canvas.imagecolor.load()
R,G,B = canvas.src_strlist[1, 1]
px = str(hex((R>>3)<<11 | (G>>2)<<5 | B>>3))
#垂直
vertibar=tk.Scrollbar(
    frame,
    orient=tk.VERTICAL
    )
vertibar.pack(side=tk.RIGHT,fill=tk.Y)
vertibar.config(command=canvas.yview)
#水平
horibar=tk.Scrollbar(    
    frame,
    orient=tk.HORIZONTAL
    )
horibar.pack(side=tk.BOTTOM,fill=tk.X)
horibar.config(command=canvas.xview)
canvas.config(
    xscrollcommand=horibar.set, 
    yscrollcommand=vertibar.set
    )
canvas.img_avatar  = ImageTk.PhotoImage(image)
#imgLabel = tk.Label(frame ,image = photo)
#imgLabel.pack()
tk.canvasimage = canvas.create_image(float(width/2)+2,float(high/2)+2 , image=canvas.img_avatar ) #此处加2是为了全部显示
tk.rectangle1 = canvas.create_rectangle(0, 0 , 1 , 1 , outline = "red")

canvas.bind("<B1-Motion>" , B1_Motion)#鼠标事件
canvas.bind("<B3-Motion>" , B3_Motion)#鼠标事件
canvas.bind("<Button-1>" , Mouse_dowm)#鼠标事件
canvas.bind("<Button-3>" , Mouse_RIGHT_dowm)#鼠标事件
canvas.bind("<Button-2>" , Mouse_Middle_dowm)#鼠标事件
#ws.bind("<Configure>", adjust_scrollregion)
canvas.pack(expand=True,side=tk.LEFT,fill=tk.BOTH)
####################################################
v = tk.IntVar()
v.set(5)
v1 = tk.IntVar()
v1.set(1)
Coordinate = tk.StringVar()
Xradio1 = tk.StringVar()
Yradio1 = tk.StringVar()
pw2=tk.PanedWindow(pw1,orient=tk.VERTICAL,width = 100,height = 100,sashrelief='groove')
#pw2.pack(fill=tk.BOTH,expand=True) # 尺寸扩展到整个窗体
frame1 = tk.Frame(pw2)
frame2 = tk.Frame(pw2)
textLabel = tk.Label(frame1  ,text = '出现BUG请重启')
textLabel.grid(column = 0 , row = 0)
Coordinateout = tk.Entry(frame1 , width = 30 ,  text = Coordinate  , state = "readonly" , exportselection = 1)
Coordinateout.grid(column = 0 , row = 1)



LANGS= [("按键坐标" , 1),
        ("切图坐标" , 2),
        ("单点坐标" , 3),
        ("像素颜色" , 4),
        ("自动获取" , 5)]
for lang ,num in LANGS:
    b= tk.Radiobutton(frame2 , text = lang , variable = v , value = num )
    b.pack(fill =tk.X)

button6 = tk.Button(frame2 , text = "打开图片"  , command = OpenPicture)
button6.pack()
button7 = tk.Checkbutton(frame2 , text = "自动复制" , variable= v1)
button7.pack()

tk.Label(frame2 , text = '请输入X转换系数,默认为1').pack()

X_Radio = tk.Entry(frame2 , width = 20 ,  textvariable = 1, text = Xradio1   , exportselection = 1)
X_Radio.pack()
Xradio1.set(1)
tk.Label(frame2 , text = '请输入Y转换系数,默认为1').pack()

Y_Radio = tk.Entry(frame2 , width = 20 ,  textvariable = 1,text = Yradio1   , exportselection = 1)
Y_Radio.pack()
Yradio1.set(1)
button8 = tk.Button(frame2 , text = "设置XY系数"  , command = XYRadio_Set)
button8.pack()

#######################################################


pw1.add(frame) # pw1加入fr1组件
pw1.add(pw2) # pw1加入pw2组件
 
pw2.add(frame1) # pw2加入fr2组件
pw2.add(frame2) # pw2加入fr3组件

ws.mainloop()

以下是鼠标左键按下滑动事件调用的回调函数代码

def B1_Motion(event):
    global End_x
    global End_y
    radioup , raduodown = vertibar.get() 
    radioxleft , radioxright = horibar.get()
    #End_x,End_y = ((canvas.canvasx(event.x)+width * radioxleft)-2 ), ((canvas.canvasx(event.y) + high * radioup)-2) #-2才是对上像素
    End_x,End_y = ((event.x+width * radioxleft)-2 ), ((event.y + high * radioup)-2) #-2才是对上像素
    #canvas.delete(tk.ALL)


    if End_x<0 :
        End_x = 0;
    if End_y <0:
        End_y = 0;

    if End_x > width :
        End_x = width;
    if End_y > high:
        End_y = high;
        
    canvas.delete(tk.rectangle1)  
    tk.rectangle1 = canvas.create_rectangle(Start_x+2, Start_y+2 , End_x +2, End_y +2, outline = "red")#矫正显示矩形刚好对上光标
    
    if v.get() == 1 or v.get() == 5:
        result = str(int(Start_x*XRadioVar))+','+str(int(Start_y*YRadioVar))+','+str(int(End_x*XRadioVar))+','+str(int(End_y*YRadioVar))
        Coordinate.set(str(result))
        if v1.get() == 1:
            pyperclip.copy(result)
    elif v.get() == 2:
        result = str(int(Start_x*XRadioVar))+','+str(int(Start_y*YRadioVar))+','+str(int(End_x*XRadioVar))+','+str(int(End_y*YRadioVar))+','+str(int(Start_x*XRadioVar))+','+str(int(Start_y*YRadioVar))
        Coordinate.set(str(result))
        if v1.get() == 1:
            pyperclip.copy(result)
    canvas.update()

以下是鼠标右键按下滑动事件调用的回调函数代码

def B3_Motion(event):
    global End_x
    global End_y
    radioup , raduodown = vertibar.get() 
    radioxleft , radioxright = horibar.get()
    #End_x,End_y = ((canvas.canvasx(event.x)+width * radioxleft)-2 ), ((canvas.canvasx(event.y) + high * radioup)-2) #-2才是对上像素
    End_x,End_y = ((event.x+width * radioxleft)-2 ), ((event.y + high * radioup)-2) #-2才是对上像素
    if End_x<0 :
        End_x = 0;
    if End_y <0:
        End_y = 0;

    if End_x > width :
        End_x = width;
    if End_y > high:
        End_y = high;
    canvas.delete(tk.rectangle1)  
    tk.rectangle1 = canvas.create_rectangle(Start_x+2, Start_y+2 , End_x +2, End_y +2, outline = "red")#矫正显示矩形刚好对上光标
    result = str(int(Start_x*XRadioVar))+','+str(int(Start_y*YRadioVar))+','+str(int(End_x*XRadioVar))+','+str(int(End_y*YRadioVar))+','+str(int(Start_x*XRadioVar))+','+str(int(Start_y*YRadioVar))
    Coordinate.set(str(result))
    if v1.get() == 1:
        pyperclip.copy(result)
    '''canvas.src_strlist = canvas.imagecolor.load()
    R,G,B = canvas.src_strlist[End_x, End_y]
    px = str(hex((R>>3)<<11 | (G>>2)<<5 | B>>3))
    Coordinate.set(px)
    print(px)'''
    canvas.update()

以下是鼠标左键按下事件调用的回调函数代码

def Mouse_dowm(event):
    global Start_x
    global Start_y
    radioup , raduodown = vertibar.get() 
    radioxleft , radioxright = horibar.get()
    Start_x,Start_y = ((event.x+width * radioxleft)-2 ), ((event.y + high * radioup)-2)
    #canvas.create_oval(x1 , y1, x2, y2, fill = "red")
    if Start_x<0 :
        Start_x = 0;
    if Start_y <0:
        Start_y = 0;

    if Start_x > width :
        Start_x = width;
    if Start_y > high:
        Start_y = high;

    result = str(int(Start_x*XRadioVar))+','+str(int(Start_y*YRadioVar))
    if v.get() == 3 or v.get() == 5:
        Coordinate.set(str(result))
        if v1.get() == 1:
            pyperclip.copy(result)
    elif v.get() == 4 :
        
        if Start_x<width and Start_y<high:
            canvas.src_strlist = canvas.imagecolor.load()
            R,G,B = canvas.src_strlist[Start_x, Start_y]
            px = str(hex((R>>3)<<11 | (G>>2)<<5 | B>>3))
            Coordinate.set(px)
            if v1.get() == 1:
                pyperclip.copy(px)
    canvas.update()

以下是鼠标滚轮键按下事件调用的回调函数代码

def Mouse_Middle_dowm(event):
    global Start_x
    global Start_y
    radioup , raduodown = vertibar.get() 
    radioxleft , radioxright = horibar.get()
    Start_x,Start_y = ((event.x+width * radioxleft)-2 ), ((event.y + high * radioup)-2)
    #canvas.create_oval(x1 , y1, x2, y2, fill = "red")
    if Start_x<0 :
        Start_x = 0;
    if Start_y <0:
        Start_y = 0;

    if Start_x > width :
        Start_x = width;
    if Start_y > high:
        Start_y = high;

    if Start_x<width and Start_y<high:
        canvas.src_strlist = canvas.imagecolor.load()
        R,G,B = canvas.src_strlist[Start_x, Start_y]
        px = str(hex((R>>3)<<11 | (G>>2)<<5 | B>>3))
        Coordinate.set(px)
        if v1.get() == 1:
            pyperclip.copy(px)
    canvas.update()

以下是鼠标右键按下事件调用的回调函数代码

def Mouse_RIGHT_dowm(event):
    global Start_x
    global Start_y
    radioup , raduodown = vertibar.get() 
    radioxleft , radioxright = horibar.get()
    Start_x,Start_y = ((event.x+width * radioxleft)-2 ), ((event.y + high * radioup)-2)
    #canvas.create_oval(x1 , y1, x2, y2, fill = "red")
    if Start_x<0 :
        Start_x = 0;
    if Start_y <0:
        Start_y = 0;

    if Start_x> width :
        Start_x = width;
    if Start_y > high:
        Start_y = high;
    result = str(int(Start_x*XRadioVar))+','+str(int(Start_y*YRadioVar))
    Coordinate.set(str(result))
    canvas.update()

以下是打开图片路径并读取调用的回调函数代码

def OpenPicture():
    global high
    global width
    global R
    global G
    global B
    global px
    #canvas.delete(tk.canvasimage)
    get_fp = filedialog.askopenfilename(filetypes = [("BMP",".bmp"),("PNG",".png"), ("GIF",".gif"),("JPG",".jpg")])
    image = Image.open(get_fp)
    ws.title('Guides QQ:1257784610    '+str(get_fp))
    #获取图片像素点大小
    high = image.height   #高度
    width = image.width  #宽度
    #canvas.delete("all")
    
    #print(high,width)
    if (high%2) != 0:
        high = high-1
    if (width%2) != 0:
        width = width-1
    
    canvas.img_avatar = ImageTk.PhotoImage(image)
    canvas.imagecolor = image.convert('RGB')
    canvas.config(
        width=100,
        height=100,
       scrollregion=(2,2,width+3,high+3) )    #  2改为0会导致光标和画布有点偏移,取消滚动功能就正常 ,此为画布元祖坐标,这里重定画布大小)
    tk.canvasimage = canvas.create_image(float(width/2)+2,float(high/2)+2 , image=canvas.img_avatar ) #此处加2是为了全部显示
    #canvas.after(image=photo)
    #canvas.configure(image = photo)
    
    canvas.itemconfig(tk.canvasimage, image=canvas.img_avatar)
    canvas.update()
    return

以下是XY坐标按键系数调用回调函数代码

def XYRadio_Set():
    global YRadioVar
    global XRadioVar
    XRadioVar = float(X_Radio.get())
    YRadioVar = float(Y_Radio.get())

最新源码在此全部粘贴

from asyncio.windows_events import NULL
import tkinter as tk
import cv2 as cv
import numpy as np
import pyperclip
from PIL import Image
from PIL import ImageTk
from tkinter import filedialog
import sys
sys.setrecursionlimit(100000) #设置递归深度


class Callback():

    def __init__(self):
        self.image = NULL
        self.Start_x = 1
        self.Start_y = 1
        self.End_x = 2
        self.End_y = 2
        self.high = 0
        self.width = 0
        self.px = NULL
        self.get_fp = NULL
        self.R = 0
        self.G = 0
        self.B = 0
        self.rectangle1 = NULL
        self.YRadioVar = 1.0000
        self.XRadioVar = 1.0000
        self.zoomRadioVar = 1.0000
        self.Win_height = 700
        self.Win_width = 1100
        self.Win_heightbuffer = 700
        self.Win_widthbuffer = 1100
        self.YSetRadioVar = 1.0000
        self.XSetRadioVar = 1.0000
    def Mouse_Left_dowm(self,event):
        radioup , raduodown = vertibar.get() 
        radioxleft , radioxright = horibar.get()
        self.Start_x,self.Start_y = ((event.x+self.width * radioxleft) -2), ((event.y + self.high * radioup)-2)
        #canvas.create_oval(x1 , y1, x2, y2, fill = "red")
        if self.Start_x<0 :
            self.Start_x = 0;
        if self.Start_y <0:
            self.Start_y = 0;

        if self.Start_x > self.width :
            self.Start_x = self.width;
        if self.Start_y > self.high:
            self.Start_y = self.high;

        result = str(int(self.Start_x*self.XRadioVar))+','+str(int(self.Start_y*self.YRadioVar))
        if v.get() == 3 or v.get() == 5:
            Coordinate.set(str(result))
            if v1.get() == 1:
                pyperclip.copy(result)
        elif v.get() == 4 :
        
            if self.Start_x<self.width and self.Start_y<self.high:
                #canvas.src_strlist = canvas.imagecolor.load()
                #self.R,self.G,self.B = canvas.src_strlist[self.Start_x, self.Start_y]
                self.R,self.G,self.B = self.image.getpixel((self.Start_x,self.Start_y))
                if RGB888Flag.get() == 1:
                    self.px = str(hex((self.R<<16) | (self.G<<8)| self.B))
                else :
                    self.px = str(hex((self.R>>3)<<11 | (self.G>>2)<<5 | self.B>>3))
                Coordinate.set(self.px)
                if v1.get() == 1:
                    pyperclip.copy(self.px)
        return
    def Mouse_Middle_dowm(self,event):
        radioup , raduodown = vertibar.get() 
        radioxleft , radioxright = horibar.get()
        self.Start_x,self.Start_y = ((event.x+self.width * radioxleft)-2), ((event.y + self.high * radioup)-2)
        #canvas.create_oval(x1 , y1, x2, y2, fill = "red")
        if self.Start_x<0 :
            self.Start_x = 0;
        if self.Start_y <0:
            self.Start_y = 0;

        if self.Start_x > self.width :
            self.Start_x = self.width;
        if self.Start_y > self.high:
            self.Start_y = self.high;

        if self.Start_x<self.width and self.Start_y<self.high:
            self.R,self.G,self.B = self.image.getpixel((self.Start_x,self.Start_y))
            if RGB888Flag.get() == 1:
                self.px = str(hex((self.R<<16) | (self.G<<8)| self.B))
            else :
                self.px = str(hex((self.R>>3)<<11 | (self.G>>2)<<5 | self.B>>3))
            Coordinate.set(self.px)
            if v1.get() == 1:
                pyperclip.copy(self.px)
        return

    def Mouse_RIGHT_dowm(self,event):
        radioup , raduodown = vertibar.get() 
        radioxleft , radioxright = horibar.get()
        self.Start_x,self.Start_y = ((event.x+self.width * radioxleft)-2 ), ((event.y + self.high * radioup)-2)
        #canvas.create_oval(x1 , y1, x2, y2, fill = "red")
        if self.Start_x<0 :
            self.Start_x = 0;
        if self.Start_y <0:
            self.Start_y = 0;

        if self.Start_x> self.width :
            self.Start_x = self.width;
        if self.Start_y > self.high:
            self.Start_y = self.high;
        result = str(int(self.Start_x*self.XRadioVar))+','+str(int(self.Start_y*self.YRadioVar))
        Coordinate.set(str(result))
        return
    def B1MotionEvent(self,event):
        radioup , raduodown = vertibar.get() 
        radioxleft , radioxright = horibar.get()
        #self.End_x,self.End_y = ((canvas.canvasx(event.x)+self.width * radioxleft)-2 ), ((canvas.canvasx(event.y) + self.high * radioup)-2) #-2才是对上像素
        self.End_x,self.End_y = ((event.x+self.width * radioxleft)-2 ), ((event.y + self.high * radioup)-2) #-2才是对上像素
        #canvas.delete(tk.ALL)


        if self.End_x<0 :
            self.End_x = 0;
        if self.End_y <0:
            self.End_y = 0;

        if self.End_x > self.width :
            self.End_x = self.width;
        if self.End_y > self.high:
            self.End_y = self.high;
        
        canvas.delete(self.rectangle1)  
        self.rectangle1 = canvas.create_rectangle(self.Start_x, self.Start_y , self.End_x , self.End_y , outline = "red")
    
        if v.get() == 1 or v.get() == 5:
            result = str(int(self.Start_x*self.XRadioVar))+','+str(int(self.Start_y*self.YRadioVar))+','+str(int(self.End_x*self.XRadioVar))+','+str(int(self.End_y*self.YRadioVar))
            Coordinate.set(str(result))
            if v1.get() == 1:
                pyperclip.copy(result)
        elif v.get() == 2:
            result = str(int(self.Start_x*self.XRadioVar))+','+str(int(self.Start_y*self.YRadioVar))+','+str(int(self.End_x*self.XRadioVar))+','+str(int(self.End_y*self.YRadioVar))+','+str(int(self.Start_x*self.XRadioVar))+','+str(int(self.Start_y*self.YRadioVar))
            Coordinate.set(str(result))
            if v1.get() == 1:
                pyperclip.copy(result)
        '''canvas.src_strlist = canvas.imagecolor.load()
        self.R,self.G,self.B = canvas.src_strlist[self.End_x, self.End_y]
        self.px = str(hex((self.R>>3)<<11 | (self.G>>2)<<5 | self.B>>3))
        Coordinate.set(self.px)
        print(self.px)'''
        return
    def B3MotionEvent(self,event):
        radioup , raduodown = vertibar.get() 
        radioxleft , radioxright = horibar.get()
        #self.End_x,self.End_y = ((canvas.canvasx(event.x)+self.width * radioxleft)-2 ), ((canvas.canvasx(event.y) + self.high * radioup)-2) #-2才是对上像素
        self.End_x,self.End_y = ((event.x+self.width * radioxleft)-2 ), ((event.y + self.high * radioup)-2) #-2才是对上像素
        if self.End_x<0 :
            self.End_x = 0;
        if self.End_y <0:
            self.End_y = 0;

        if self.End_x > self.width :
            self.End_x = self.width;
        if self.End_y > self.high:
            self.End_y = self.high;
        canvas.delete(self.rectangle1)  
        self.rectangle1 = canvas.create_rectangle(self.Start_x, self.Start_y , self.End_x , self.End_y , outline = "red")
        result = str(int(self.Start_x*self.XRadioVar))+','+str(int(self.Start_y*self.YRadioVar))+','+str(int(self.End_x*self.XRadioVar))+','+str(int(self.End_y*self.YRadioVar))+','+str(int(self.Start_x*self.XRadioVar))+','+str(int(self.Start_y*self.YRadioVar))
        Coordinate.set(str(result))
        if v1.get() == 1:
            pyperclip.copy(result)
        '''canvas.src_strlist = canvas.imagecolor.load()
        self.R,self.G,self.B = canvas.src_strlist[self.End_x, self.End_y]
        self.px = str(hex((self.R>>3)<<11 | (G>>2)<<5 | self.B>>3))
        Coordinate.set(self.px)
        print(self.px)'''
        return
    def zoomin_Picture(self):
        image1 = self.image
        RadioVar = self.zoomRadioVar
        try:  # 捕获异常
            #self.image = Image.open(self.get_fp)
            self.image = cv.imdecode(np.fromfile(self.get_fp,dtype = np.uint8),-1)
            if self.zoomRadioVar <10:
                self.zoomRadioVar = self.zoomRadioVar+0.1
        
            #self.image = self.image.resize((int(self.image.size[0]/self.zoomRadioVar), int(self.image.size[1]/self.zoomRadioVar)), 3 )# Image.LANCZOS) Resampling.
            self.image = cv.resize(self.image ,(0,0),fx = self.zoomRadioVar, fy = self.zoomRadioVar, interpolation = cv.INTER_AREA )
            #elif self.zoomRadioVar>3 and self.zoomRadioVar<=10:
            #    self.zoomRadioVar = self.zoomRadioVar-1
            #resized_image = ImageTk.Photoimage(self.image)
            #self.high = cv.height
            #self.width = cv.width 
            #Yradio1.set(self.XSetRadioVar)
            #Xradio1.set(self.YSetRadioVar)
            self.image = cv.cvtColor(self.image, cv.COLOR_BGR2RGBA)#转换颜色从BGR到RGBA
            self.image = Image.fromarray(self.image)#将图像转换成Image对象
    
            self.high = self.image.height   #高度
            self.width = self.image.width  #宽度
            #print(self.width,self.high , self.zoomRadioVar)
            if (self.high%2) != 0:
                self.high = self.high-1
            if (self.width%2) != 0:
                self.width = self.width-1
        


    
            canvas.img_avatar = ImageTk.PhotoImage(self.image)
            self.image = self.image.convert('RGB')
            canvas.config(
                width=100,
                height=100,
                scrollregion=(0,0,self.width,self.high)  )   
            #tk.canvasimage = canvas.create_image(float(self.width/2),float(self.high/2) , self.image=canvas.img_avatar )
            tk.canvasimage = canvas.create_image(self.width/2,self.high/2 , image=canvas.img_avatar ) 
            #canvas.after(image=photo)
            #canvas.configure(image = photo)
    
            canvas.itemconfig(tk.canvasimage, image=canvas.img_avatar)
            canvas.update()
        except OverflowError:  # 处理异常
            self.zoomRadioVar = RadioVar
            self.image = image1
        self.XRadioVar = self.XSetRadioVar/self.zoomRadioVar
        self.YRadioVar = self.YSetRadioVar/self.zoomRadioVar


        return
    def zoomout_Picture(self):
        image1 = self.image
        RadioVar = self.zoomRadioVar
        try:  # 捕获异常
            self.image = cv.imdecode(np.fromfile(self.get_fp,dtype = np.uint8),-1)
            if self.zoomRadioVar>0.1:
                self.zoomRadioVar = self.zoomRadioVar-0.1
            #elif self.zoomRadioVar>=3  and self.zoomRadioVar<10:
            #   self.zoomRadioVar = self.zoomRadioVar+1
            self.image = cv.resize(self.image ,(0,0),fx = self.zoomRadioVar, fy = self.zoomRadioVar, interpolation = cv.INTER_AREA )
            #elif self.zoomRadioVar>3 and self.zoomRadioVar<=10:
            #    self.zoomRadioVar = self.zoomRadioVar-1
            #resized_image = ImageTk.Photoimage(self.image)
            #self.high = cv.height
            #self.width = cv.width 
            #Yradio1.set(self.XSetRadioVar)
            #Xradio1.set(self.YSetRadioVar)
            self.image = cv.cvtColor(self.image, cv.COLOR_BGR2RGBA)#转换颜色从BGR到RGBA
            self.image = Image.fromarray(self.image)#将图像转换成Image对象
        
            self.high = self.image.height   #高度
            self.width = self.image.width  #宽度
                #print(self.width,self.high , self.zoomRadioVar)
            if (self.high%2) != 0:
                self.high = self.high-1
            if (self.width%2) != 0:
                self.width = self.width-1
            


        
            canvas.img_avatar = ImageTk.PhotoImage(self.image)
            self.image = self.image.convert('RGB')
            canvas.config(
                    width=100,
                    height=100,
                    scrollregion=(0,0,self.width,self.high)  )   
            #tk.canvasimage = canvas.create_image(float(self.width/2),float(self.high/2) , image=canvas.img_avatar )
            tk.canvasimage = canvas.create_image(self.width/2,self.high/2 , image=canvas.img_avatar ) 
            #canvas.after(image=photo)
            #canvas.configure(image = photo)
        
            canvas.itemconfig(tk.canvasimage, image=canvas.img_avatar)
            canvas.update()
        except cv.error:  # 处理异常
            self.zoomRadioVar = RadioVar
            self.image = image1    
        self.XRadioVar = self.XSetRadioVar/self.zoomRadioVar
        self.YRadioVar = self.YSetRadioVar/self.zoomRadioVar
        return

    def onMouseWheel(self,event):
        if event.delta>0:
            self.zoomin_Picture()
        else :
            self.zoomout_Picture()
    def OpenPicture(self):
        fp = self.get_fp
        #canvas.delete(tk.canvasimage)
        try:  # 捕获异常
            self.get_fp = filedialog.askopenfilename(filetypes = [("BMP",".bmp"),("JPG",".jpg"),("PNG",".png"), ("GIF",".gif")])
            self.image = cv.imdecode(np.fromfile(self.get_fp,dtype = np.uint8),-1)
            ws.title('ImageToolsV1.9 技术反馈与支持QQ:1257784610     '+str(self.get_fp))
            #获取图片像素点大小
            #canvas.delete("all")

            self.image = cv.resize(self.image ,(0,0),fx = self.zoomRadioVar, fy = self.zoomRadioVar, interpolation = cv.INTER_AREA )
            self.image = cv.cvtColor(self.image, cv.COLOR_BGR2RGBA)#转换颜色从BGR到RGBA
            self.image = Image.fromarray(self.image)#将图像转换成Image对象
            #resized_image = ImageTk.Photoimage(self.image)
            self.high = self.image.height
            self.width = self.image.width 
            #print(self.high,self.width)
            if (self.high%2) != 0:
                self.high = self.high-1
            if (self.width%2) != 0:
                self.width = self.width-1

            canvas.img_avatar = ImageTk.PhotoImage(self.image)
            #canvas.imagecolor = self.image.convert('RGB')
            self.image = self.image.convert('RGB')
            canvas.config(
                width=100,
                height=100,
           scrollregion=(0,0,self.width,self.high)
               )   
            tk.canvasimage = canvas.create_image(float(self.width/2),float(self.high/2) , image=canvas.img_avatar )
            #canvas.after(image=photo)
            #canvas.configure(image = photo)
        
            canvas.itemconfig(tk.canvasimage, image=canvas.img_avatar)
            canvas.update()
        except AttributeError:  # 处理异常
            self.get_fp =fp
        except FileNotFoundError:  # 处理异常
            self.get_fp =fp 
        return

    def XYRadio_Set(self):
        self.XSetRadioVar = float(X_Radio.get())
        self.YSetRadioVar = float(Y_Radio.get())
        self.XRadioVar , self.YRadioVar = self.XSetRadioVar/self.zoomRadioVar,self.YSetRadioVar/self.zoomRadioVar
        return
    def adjust_windows(self,event):
        if (self.Win_heightbuffer !=ws.winfo_height()) or (self.Win_widthbuffer !=ws.winfo_width()):
            self.Win_heightbuffer , self.Win_widthbuffer = ws.winfo_height() , ws.winfo_width()
            pw1.update()
            pw1.sash_place(0,int(ws.winfo_width()-200),0)#放置中间的空间分割线
            #heightRadio , widthRadio= ws.winfo_height()/Win_height , ws.winfo_width()/Win_width
            #print(event.type)
            #print(event.widget)
    def Reset_Picture(self):
        self.image = cv.imdecode(np.fromfile(self.get_fp,dtype = np.uint8),-1)
        self.zoomRadioVar = 1.0
        self.XSetRadioVar = 1.0
        self.YSetRadioVar = 1.0
        self.XRadioVar = self.XSetRadioVar/self.zoomRadioVar
        self.YRadioVar = self.YSetRadioVar/self.zoomRadioVar
    
        '''interpolation:这个是指定插值的方式,图像缩放之后,肯定像素要进行重新计算的,就靠这个参数来指定重新计算像素的方式,有以下几种:
        INTER_NEAREST - 最邻近插值
        INTER_LINEAR - 双线性插值,如果最后一个参数你不指定,默认使用这种方法
        INTER_AREA - resampling using pixel area relation. It may be a preferred method for self.image decimation, as it gives moire’-free results. But when the self.image is zoomed, it is similar to the INTER_NEAREST method.
        INTER_CUBIC - 4x4像素邻域内的双立方插值
        INTER_LANCZOS4 - 8x8像素邻域内的Lanczos插值
        ————————————————
        版权声明:本文为CSDN博主「xidaoliang123」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
        原文链接:https://blog.csdn.net/xidaoliang/article/details/86504720'''
        self.image = cv.resize(self.image ,(0,0),fx = self.zoomRadioVar, fy = self.zoomRadioVar, interpolation = cv.INTER_AREA )
        #resized_image = ImageTk.Photoimage(self.image)
        self.image = cv.cvtColor(self.image, cv.COLOR_BGR2RGBA)#转换颜色从BGR到RGBA
        self.image = Image.fromarray(self.image)#将图像转换成Image对象
    
        self.high = self.image.height
        self.width = self.image.width 
        Yradio1.set(self.XSetRadioVar)
        Xradio1.set(self.YSetRadioVar)
    
        #print(self.width,self.high)
    
        #print(self.high,self.width)
        if (self.high%2) != 0:
            self.high = self.high-1
        if (self.width%2) != 0:
            self.width = self.width-1



    
        canvas.img_avatar = ImageTk.PhotoImage(self.image)
        self.image = self.image.convert('RGB')
        canvas.config(
            width=100,
            height=100,
           scrollregion=(0,0,self.width,self.high) )   
        tk.canvasimage = canvas.create_image(float(self.width/2),float(self.high/2) , image=canvas.img_avatar ) 
        #canvas.after(image=photo)
        #canvas.configure(image = photo)
    
        canvas.itemconfig(tk.canvasimage, image=canvas.img_avatar)
        canvas.update()
        return
ws = tk.Tk()
ws.title('ImageToolsV1.9 技术反馈与支持QQ:1257784610')
ws.geometry('1100x700')
pw1=tk.PanedWindow(ws,orient=tk.HORIZONTAL,width = 900,height = 700,sashrelief='groove') # 创建横向分割面板

pw1.pack(fill=tk.BOTH,expand=True) # 尺寸扩展到整个窗体
frame = tk.Frame(pw1 ,width = 900,height = 700)
ws.update_idletasks()

try:  # 捕获异常
    Function = Callback()
    Function.get_fp = filedialog.askopenfilename(filetypes = [("BMP",".bmp"),("JPG",".jpg"),("PNG",".png"), ("GIF",".gif")])
    
    ws.title('ImageToolsV1.9 技术反馈与支持QQ:1257784610   '+str(Function.get_fp))
    #image = Image.open(get_fp)
    Function.image = cv.imdecode(np.fromfile(Function.get_fp,dtype = np.uint8),-1)
    Function.image = cv.cvtColor(Function.image, cv.COLOR_BGR2RGBA)#转换颜色从BGR到RGBA
    Function.image = Image.fromarray(Function.image)#将图像转换成Image对象
    
    #获取图片像素点大小
    Function.high = Function.image.height   #高度
    Function.width = Function.image.width  #宽度
    #print(high,width)
    if (Function.high%2) != 0:
        Function.high = Function.high-1
    if (Function.width%2) != 0:
        Function.width = Function.width-1
    canvas=tk.Canvas(
        frame,
    
        bg='#4A7A8C',
        width=900,
        height=700,
        scrollregion=(0,0,Function.width,Function.high)    
        )
    #canvas.imagecolor = image.convert('RGB')#RGB模式
    Function.image = Function.image.convert('RGB')
    Function.R,Function.G,Function.B = Function.image.getpixel((0,0))
    #canvas.src_strlist = canvas.imagecolor.load()
    #R,G,B = canvas.src_strlist[1, 1]
    
    Function.px = str(hex((Function.R>>3)<<11 | (Function.G>>2)<<5 | Function.B>>3))
    #垂直滑动条
    vertibar=tk.Scrollbar(
        frame,
        orient=tk.VERTICAL
        )
    vertibar.pack(side=tk.RIGHT,fill=tk.Y)
    vertibar.config(command=canvas.yview)
    #水平滑动条
    horibar=tk.Scrollbar(    
        frame,
        orient=tk.HORIZONTAL
        )
    horibar.pack(side=tk.BOTTOM,fill=tk.X)
    horibar.config(command=canvas.xview)
    canvas.config(
        xscrollcommand=horibar.set, 
        yscrollcommand=vertibar.set
        )#配置滑动条
    canvas.img_avatar  = ImageTk.PhotoImage(Function.image)
    #imgLabel = tk.Label(frame ,image = photo)
    #imgLabel.pack()
    tk.canvasimage = canvas.create_image(float(Function.width/2),float(Function.high/2) , image=canvas.img_avatar ) #此处加2是为了全部显示
    #Function.rectangle1 = canvas.create_rectangle(0, 0 , 1 , 1 , outline = "red")

    canvas.pack(expand=True,side=tk.LEFT,fill=tk.BOTH)
    #ws.protocol( "WM_TAKE_FOCUS" , adjust_windows);



    ####################################################
    v = tk.IntVar()
    v.set(5)
    v1 = tk.IntVar()
    v1.set(1)
    RGB888Flag = tk.IntVar()
    RGB888Flag.set(0)
    Coordinate = tk.StringVar()
    Xradio1 = tk.StringVar()
    Yradio1 = tk.StringVar()
    pw2=tk.PanedWindow(pw1,orient=tk.VERTICAL,width = 200,height = 700,sashrelief='groove')
    pw2.pack() # 尺寸扩展到整个窗体
    frame1 = tk.Frame(pw2)
    frame2 = tk.Frame(pw2)
    textLabel = tk.Label(frame1  ,text = '出现BUG请重启')
    textLabel.pack(expand=False)
    Coordinateout = tk.Entry(frame1 , width = 30 ,  text = Coordinate  , state = "readonly" , exportselection = 1)
    #Coordinateout.grid(column = 0 , row = 1)
    Coordinateout.pack()

    
    LANGS= [("按键坐标" , 1),
            ("切图坐标" , 2),
            ("单点坐标" , 3),
            ("像素颜色" , 4),
            ("自动获取" , 5)]
    for lang ,num in LANGS:
        b= tk.Radiobutton(frame2 , text = lang , variable = v , value = num )
        b.pack(fill =tk.X)

    OpenPictureButton = tk.Button(frame2 , text = "打开图片"  , command = Function.OpenPicture,width = 10)
    OpenPictureButton.pack()
    Copybutton = tk.Checkbutton(frame2 , text = "自动复制" , variable= v1)
    Copybutton.pack()
    RGBModeButton = tk.Checkbutton(frame2 , text = "RGB888(565)" , variable= RGB888Flag)
    RGBModeButton.pack()
    tk.Label(frame2 , text = '请输入X转换系数,默认为1').pack()

    X_Radio = tk.Entry(frame2 , width = 20 ,  textvariable = 1, text = Xradio1   , exportselection = 1)
    X_Radio.pack()
    Xradio1.set(1)
    tk.Label(frame2 , text = '请输入Y转换系数,默认为1').pack()

    Y_Radio = tk.Entry(frame2 , width = 20 ,  textvariable = 1,text = Yradio1   , exportselection = 1)
    Y_Radio.pack()
    Yradio1.set(1)
    SetxyButton = tk.Button(frame2 , text = "设置XY系数"  , command = Function.XYRadio_Set ,width = 10)
    SetxyButton.pack()

    zoominButton = tk.Button(frame2 , text = "图片放大"  , command = Function.zoomin_Picture ,width = 10)
    zoominButton.pack()
    zoomoutButton = tk.Button(frame2 , text = "图片缩小"  , command = Function.zoomout_Picture,width = 10)
    zoomoutButton.pack()
    ResetButton = tk.Button(frame2 , text = "图片复位"  , command = Function.Reset_Picture,width = 10)
    ResetButton.pack()
    #canvas.bind("<Configure>", adjust_windows)#适应窗口
    pw1.bind("<Configure>", Function.adjust_windows)#适应窗口
    #pw2.bind("<Configure>", adjust_windows)#适应窗口
    canvas.bind("<B1-Motion>" , Function.B1MotionEvent)#鼠标左键按下并移动事件
    canvas.bind("<B3-Motion>" , Function.B3MotionEvent)#鼠标右键按下并移动事件
    canvas.bind("<Button-1>" , Function.Mouse_Left_dowm)#鼠标左键按下事件
    canvas.bind("<Button-3>" , Function.Mouse_RIGHT_dowm)#鼠标右键按下事件
    canvas.bind("<Button-2>" , Function.Mouse_Middle_dowm)#鼠标滚轮按下事件
    canvas.bind("<Control-MouseWheel>" , Function.onMouseWheel)#鼠标滚轮按下事件
    #######################################################


    pw1.add(frame) # pw1加入fr1组件
    pw2.add(frame1) # pw2加入fr2组件
    pw2.add(frame2) # pw2加入fr3组件
    pw1.add(pw2) # pw1加入pw2组件

    ws.mainloop()
except FileNotFoundError:  
    sys.exit()


 

 

 

到了这里,关于图片坐标提取软件/图片坐标点和像素点颜色提取软件/图片坐标获取工具/Python图片坐标获取源码/图片像素坐标获取软件/查看图片点XY坐标(完全开源)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包