예제 #1
0
# coding:utf-8

import pandas as pd
from src import App
"""写入文件"""

# 写入excel
df = pd.read_excel(App.resource_file("data/excel-comp-sheetdata.xlsx"))

# 读取全部数据
all_data = pd.DataFrame(df)
print(all_data.loc[14, 'name'])
all_data.loc[14, 'name'] = 'McDermott PLCA'
all_data.to_excel('C:\\Users\\Administrator\\Desktop\\1.xlsx',
                  header=True,
                  index=False)
예제 #2
0
    canvas[:, :, :] = 255
    new_image = Image.fromarray(canvas)
    draw = ImageDraw.Draw(new_image)

    # 创建绘制对象
    font = ImageFont.truetype("consola.ttf", 10, encoding="unic")
    char_table = list("$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/|()1{}[]?-_+~<>i!lI;:,\"^`'. ")
    # font = ImageFont.truetype('simsun.ttc', 10)
    # char_table = list(u'新年快乐')

    # 开始绘制
    pix_count = 0
    table_len = len(char_table)
    for y in range(height):
        for x in range(width):
            if x % sample_step == 0 and y % sample_step == 0:
                draw.text((x * scale, y * scale), char_table[pix_count % table_len], pix[x, y], font)
                pix_count += 1

    # 保存
    if dst_img_file_path is not None:
        new_image.save(dst_img_file_path)

    print("used time : %d second, pix_count : %d" % ((int(time.time()) - start_time), pix_count))
    print(pix_count)
    new_image.show()

if __name__ == '__main__':
    image_file = App.resource_file("/img/wm.png")
    temp_file = App.temp_file("wm.png")
happyNewYear(image_file, temp_file)
예제 #3
0

def load_dict(file):
    """英文字典/usr/share/dict"""
    englist_dic = []
    with open(file, 'r', encoding='UTF-8') as ff:
        for line in ff.readlines():
            englist_dic.append(line.strip())

    return tuple(englist_dic)


if __name__ == "__main__":
    """由于都是相对较小的文件因此直接进行统计"""

    endict = load_dict(App.resource_file("linux.words"))
    print("englis dic len:", len(endict))
    count_dict = {}
    for dirpath, dirname, filenames in os.walk(u"C:\edocuments"):
        for filepath in filenames:
            f_n = os.path.join(dirpath, filepath)
            print("consume file =>", f_n)
            try:
                f_content = ''
                with open(f_n, 'r', encoding='UTF-8') as ff:
                    for line in ff.readlines():
                        f_content += line

                # 文章字符串前期处理

                f_content = trunNonalpha(f_content.lower())
예제 #4
0
ascii_char = list("$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/|()1{}[]?-_+~<>i!lI;:,\"^`'. ")


def get_char(r, g, b, alpha=256):
    if alpha == 0:
        return ' '
    length = len(ascii_char)
    gray = int(0.2126 * r + 0.7152 * g + 0.0722 * b)

    unit = (256.0 + 1) / length
    return ascii_char[int(gray / unit)]


if __name__ == '__main__':
    image_file = App.resource_file("/opencv/green-spiral.jpg")
    im = Image.open(image_file)
    pix = im.load()

    ims = Image.new("RGB", (im.width,im.height), (255, 255, 255))
    dr = ImageDraw.Draw(ims)
    font = ImageFont.truetype(os.path.join("fonts", "msyh.ttf"), 10)

    txt = ""
    for i in range(im.height):
        for j in range(im.width):
            char = get_char(*im.getpixel((j,i)))
            txt += char
            dr.text((j,i),char, pix[j, i], font)
        txt += '\n'
    with open("output.txt", 'w') as f:
예제 #5
0
# coding:UTF-8

import cv2
from src import App

img_file = App.resource_file("/opencv/timg.jpg")
im = cv2.imread(img_file, 0)

sobx = cv2.CreateImage(cv2.GetSize(im), cv2.IPL_DEPTH_16S, 1)
#Sobel with x-order=1
cv2.Sobel(im, sobx, 1, 0, 3)

soby = cv2.CreateImage(cv2.GetSize(im), cv2.IPL_DEPTH_16S, 1)
#Sobel withy-oder=1
cv2.Sobel(im, soby, 0, 1, 3)

cv2.Abs(sobx, sobx)
cv2.Abs(soby, soby)

result = cv2.CloneImage(im)
#Add the two results together.
cv2.Add(sobx, soby, result)

cv2.Threshold(result, result, 100, 255, cv2.CV_THRESH_BINARY_INV)

cv2.ShowImage('Image', im)
cv2.ShowImage('Result', result)

cv2.WaitKey(0)
예제 #6
0
# coding:UTF-8
# python3.x
"""Imagge是pillow库中一个非常重要的模块,提供了大量用于图像处理的方法
"""
from PIL import ImageGrab

from src import App

image_file = App.resource_file("/temp/test.jpg")

# 获取屏幕指定区域的图像
im = ImageGrab.grab((0, 0, 100, 200))
im.show()

# 或全屏截图
im = ImageGrab.grab()
im.show()
예제 #7
0
# coding:UTF-8

import numpy as np
from src import App
"""演示从文本中加载数据"""

file_name = App.resource_file("/data/npl/affinity_dataset.txt")
x = np.loadtxt(file_name)

n_samples, n_features = x.shape
print("This dataset has {0} samples and {1} features".format(
    n_samples, n_features))

# The names of the features, for your reference.
features = ["bread", "milk", "cheese", "apples", "bananas"]

# First, how many rows contain our premise: that a person is buying apples
num_apple_purchases = 0
for sample in x:
    if sample[3] == 1:  # This person bought Apples
        num_apple_purchases += 1
print("{0} people bought Apples".format(num_apple_purchases))