最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python實現(xiàn)書法碑帖圖片分割

 更新時間:2021年03月07日 08:38:17   作者:傅佑  
這篇文章主要為大家詳細介紹了python實現(xiàn)書法碑帖圖片分割,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了python實現(xiàn)書法碑帖圖片分割的具體代碼,供大家參考,具體內容如下

一、功能實現(xiàn)效果

1、選擇要分割的碑帖圖片

2、選擇碑帖圖像分割的行與列,本例的行為:5,列為:4。如何點擊“確定行列”

3、輸入對于碑帖的內容,點擊“確定分割”按鈕。

4、在輸出文件夾生成了單字版圖片,并對應內容命名。方便集字、創(chuàng)作與學習。

二、Python代碼實現(xiàn)

1、getimgdir.py

import wx
import os
from PIL import Image
import numpy as np
#import wx.grid
#import row_col
#row_col
#######################################################################################
app = wx.App() #wx.App()行創(chuàng)建了一個應用程序對象。每個 wx 程序都需要一個 .App() 對象
frame = wx.Frame(None, -1, '請選擇待分割的圖片文件') #wx.Frame()方法返回一個可以包含小部件的新窗口
frame.SetSize(0,0,600,300) #函數(shù)設置位置和大小(x(左),y(頂部),寬度,高度)
openFileDialog = wx.FileDialog(frame, "Open", "", "",
                   "all files (*.*)|*.*",
                    wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)

openFileDialog.ShowModal() #顯示窗口
src = openFileDialog.GetPath() #返回文件的完整路徑(如果選擇了一個)
np.savez('dir.npz', k_a=src)
openFileDialog.Destroy()

2、row_col.py

import wx
import numpy as np
import sys
import time
import os
class MyFrame(wx.Frame):
  ClickNum = 0
  def __init__(self):   #__init__(self) 是類的初始化方法,也稱構造方法,是一種特殊的魔法方法。__init__(self)在實例化后,會自動調用,而不用手動調用,所以一般把屬性設置在_init__()里。
    super().__init__(parent=None,title="圖像分割行數(shù)與列數(shù)",size=(500,730)) # 初始化窗口信息
    panel = wx.Panel(self)  #框架的父窗口。對于頂級窗口,這個值是None 。#創(chuàng)建面板
    #模塊1 選擇簽約主體
    self.Center()
    text1 = wx.StaticText(parent=panel,id=-1,pos=(10,7),label="圖像分割行數(shù):")
    list1 = ["1","2","3","4","5","6","7","8","9","10"]
    self.combobox1=wx.ComboBox(parent=panel,id=-1,pos=(100,5),value="5",choices=list1)#wx.ComboBox 默認它的文本框是可以修改的

    text2 = wx.StaticText(parent=panel, id=-1, pos=(250, 7), label="圖像分割列數(shù):")
    list2 = ["1","2","3","4","5","6","7","8","9","10"]
    self.combobox2 = wx.ComboBox(parent=panel, id=-1, pos=(350, 5), value="4",choices=list2) # wx.ComboBox 默認它的文本框是可以修改的

    datadir = np.load('dir.npz')
    imgdir = str(datadir['k_a'])
    copybookimg = wx.Bitmap(imgdir, wx.BITMAP_TYPE_ANY)
    img = wx.Image(imgdir)
    w1,h1 = copybookimg.GetSize()
    if h1>400:
     neww1 = (400*w1)/h1
     newh1 = 400
     img2=img.Scale(int(neww1),newh1)
     img2=wx.Bitmap(img2)
     self.image = wx.StaticBitmap(panel, -1, img2,pos=(10, 90))

    st1 = wx.StaticText(panel, -1, "字帖內容:", pos=(10, 505))


    self.txt1 = wx.TextCtrl(panel, -1, pos=(60, 530), size=(int(13.26*1+23.5), 140), style=wx.TE_MULTILINE)

    #提交模塊
    self.button = wx.Button(panel, -1, "確定行列", pos=(200, 40), size=(60, 30)) # 在面板上添加控件
    self.Bind(wx.EVT_BUTTON, self.OnClick, self.button) # 將回調函數(shù)與按鍵事件綁定


  def OnClick(self, event): # 回調函數(shù)事件
      self.button.SetLabel("提交成功") # 設置
      self.ClickNum += 1
      if self.ClickNum % 2 == 1: # 根據(jù)按下次數(shù)判斷
        self.button.SetLabel("已經(jīng)提交") # 修改按鍵的標簽
        a = self.combobox1.GetValue()
        b = self.combobox2.GetValue()
        np.savez('abc.npz', k_a=a, k_b=b)
        #time.sleep(0.1)
        self.Close()


class App(wx.App):
  def OnInit(self):
    frame = MyFrame()
    frame.Show()
    return True
app = App()
app.MainLoop()
#time.sleep(2)
#sys.exit(0)

3、row_col_show.py

import wx
import numpy as np
import threading
import time
from PIL import Image,ImageDraw
def draw_line(dir,a,b):
 im = Image.open(dir)
 draw = ImageDraw.Draw(im) #實例化一個對象
 #a #行 圖像的寬:im.size[0]
 #b #列 圖像的高:im.size[1]
 a=int(a)
 b=int(b)
 c=im.size[0]
 d=im.size[1]
 for i in range(a):
  draw.line((0, d*(i+1)/a) + (c,d*(i+1)/a), fill=128, width=5) #線的起點和終點,線寬
 for j in range(b):
  draw.line((c*(j+1)/b,0) + (c*(j+1)/b,d), fill=128, width=6)
 return(im.save("00.jpeg"))

class MyFrame(wx.Frame):
  ClickNum = 0

  def __init__(
      self): # __init__(self) 是類的初始化方法,也稱構造方法,是一種特殊的魔法方法。__init__(self)在實例化后,會自動調用,而不用手動調用,所以一般把屬性設置在_init__()里。
    super().__init__(parent=None, title="圖像分割行數(shù)與列數(shù)", size=(500, 730)) # 初始化窗口信息
    panel = wx.Panel(self) # 框架的父窗口。對于頂級窗口,這個值是None 。#創(chuàng)建面板
    # 模塊1 選擇簽約主體
    self.Center()
    data_a = np.load('abc.npz')
    split_row = int(data_a['k_a']) # 讀取行數(shù)
    split_col = int(data_a['k_b']) # 讀取列數(shù)

    text1 = wx.StaticText(parent=panel, id=-1, pos=(10, 7), label="圖像分割行數(shù):")
    list1 = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
    self.combobox1 = wx.ComboBox(parent=panel, id=-1, pos=(100, 5), value=str(split_row),
                   choices=list1) # wx.ComboBox 默認它的文本框是可以修改的

    text2 = wx.StaticText(parent=panel, id=-1, pos=(250, 7), label="圖像分割列數(shù):")
    list2 = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
    self.combobox2 = wx.ComboBox(parent=panel, id=-1, pos=(350, 5), value=str(split_col),
                   choices=list2) # wx.ComboBox 默認它的文本框是可以修改的
    datadir = np.load('dir.npz')
    imgdir = str(datadir['k_a'])
    copybookimg = wx.Bitmap(imgdir, wx.BITMAP_TYPE_ANY)
    #img = wx.Image(imgdir)
    draw_line(imgdir, str(split_row), str(split_col))
    img3 = wx.Image("00.jpeg")
    w1, h1 = copybookimg.GetSize()
    if h1 > 400:
      neww1 = (400 * w1) / h1
      newh1 = 400
      img2 = img3.Scale(neww1, newh1)
      img2 = wx.Bitmap(img2)
      self.image = wx.StaticBitmap(panel, -1, img2, pos=(10, 90))
    st1 = wx.StaticText(panel, -1, "字帖內容:", pos=(10, 505))
    for i in range(split_col):
      wx.StaticText(panel, -1, "第"+str(i+1)+"列:", pos=(10, 530+20*i))

    self.txt1 = wx.TextCtrl(panel, -1, pos=(60, 530), size=(13.26 * split_row + 23.5, split_col *20), style=wx.TE_MULTILINE)

    # 提交模塊
    self.button = wx.Button(panel, -1, "確定分割", pos=(400, 650), size=(60, 30)) # 在面板上添加控件
    self.Bind(wx.EVT_BUTTON, self.OnClick, self.button) # 將回調函數(shù)與按鍵事件綁定

  def OnClick(self, event): # 回調函數(shù)事件
    self.button.SetLabel("提交成功") # 設置
    self.ClickNum += 1
    if self.ClickNum % 2 == 1: # 根據(jù)按下次數(shù)判斷
      self.button.SetLabel("已經(jīng)提交") # 修改按鍵的標簽
      a = self.combobox1.GetValue()
      b = self.combobox2.GetValue()
      c = self.txt1.GetValue()
      np.savez('abc.npz', k_a=a, k_b=b, k_c=c) #k_c = c碑帖內容保存npz文件
      self.Close()
class App(wx.App):
  def OnInit(self):
    frame = MyFrame()
    frame.Show()
    return True
app = App()
app.MainLoop()

4、split_copybook.py

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

import wx
import os
from PIL import Image
import numpy as np
#import wx.grid
#import row_col
#row_col
#######################################################################################
data_a = np.load('dir.npz')
src=str(data_a['k_a'])#地址


def splitimage(src, rownum, colnum, dstpath): #分割圖像,(輸入圖片路徑,分割行數(shù),分割列數(shù),輸出圖片路徑)

  img = Image.open(src)
  src=src.replace('jpg','jpeg')

  print(src)
  #os.getcwd()
  w, h = img.size
  if rownum <= h and colnum <= w:
    print('原碑帖圖片信息: %sx%s, %s, %s' % (w, h, img.format, img.mode))
    print('

5、main.py

import os
os.system("python ./getimgdir.py")
os.system("python ./row_col.py")
os.system("python ./row_col_show.py")
os.system("python ./split_copybook.py")
os.unlink('00.jpeg')
os.unlink('abc.npz')
os.unlink('dir.npz')

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • Python WebSocket長連接心跳與短連接的示例

    Python WebSocket長連接心跳與短連接的示例

    這篇文章主要介紹了Python WebSocket長連接心跳與短連接的示例,幫助大家更好的理解和學習python,感興趣的朋友可以了解下
    2020-11-11
  • python cv2截取不規(guī)則區(qū)域圖片實例

    python cv2截取不規(guī)則區(qū)域圖片實例

    今天小編就為大家分享一篇python cv2截取不規(guī)則區(qū)域圖片實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • python DataFrame 取差集實例

    python DataFrame 取差集實例

    今天小編就為大家分享一篇python DataFrame 取差集實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-01-01
  • 如何通過python檢查文件是否被占用

    如何通過python檢查文件是否被占用

    這篇文章主要介紹了如何通過python檢查文件是否被占用,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-12-12
  • python實現(xiàn)的簡單RPG游戲流程實例

    python實現(xiàn)的簡單RPG游戲流程實例

    這篇文章主要介紹了python實現(xiàn)的簡單RPG游戲流程,實例分析了Python實現(xiàn)RPG游戲流程的常用判定技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-06-06
  • 使用Python進行中文繁簡轉換的實現(xiàn)代碼

    使用Python進行中文繁簡轉換的實現(xiàn)代碼

    這篇文章主要介紹了使用Python進行中文繁簡轉換的實現(xiàn)代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-10-10
  • Python圖像處理模塊ndimage用法實例分析

    Python圖像處理模塊ndimage用法實例分析

    這篇文章主要介紹了Python圖像處理模塊ndimage用法,結合實例形式分析了Python圖像處理模塊ndimage基本功能及常見的圖形運算操作實現(xiàn)技巧,需要的朋友可以參考下
    2019-09-09
  • django ListView的使用 ListView中獲取url中的參數(shù)值方式

    django ListView的使用 ListView中獲取url中的參數(shù)值方式

    這篇文章主要介紹了django ListView的使用 ListView中獲取url中的參數(shù)值方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03
  • Python對Excel進行處理的實操指南

    Python對Excel進行處理的實操指南

    這篇文章主要給大家介紹了關于Python對Excel進行處理的實操指南,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-03-03
  • Python 3.9的到來到底是意味著什么

    Python 3.9的到來到底是意味著什么

    本文主要介紹Python3.9的一些新特性比如說更快速的進程釋放,性能的提升,簡便的新字符串函數(shù),字典并集運算符以及更兼容穩(wěn)定的內部API,感興趣的朋友跟隨小編一起看看吧
    2020-10-10

最新評論

平遥县| 普陀区| 南丹县| 综艺| 澎湖县| 中山市| 静安区| 祁连县| 中宁县| 诏安县| 含山县| 永靖县| 长寿区| 丹寨县| 汝城县| 巍山| 金门县| 元阳县| 临湘市| 精河县| 安庆市| 洛宁县| 都江堰市| 赣榆县| 兴山县| 英德市| 江北区| 措美县| 新泰市| 宜阳县| 邯郸市| 枣庄市| 宜兰县| 中阳县| 巢湖市| 宁明县| 舒兰市| 原平市| 柯坪县| 洱源县| 碌曲县|