利用python+opencv让excel描绘照片

本文介绍如何使用Python结合OpenCV库在Excel中绘制照片,详细讲解了所需的环境配置和步骤。
摘要由CSDN通过智能技术生成
简介
通过读取图片的各个像素的颜色,填充到excel单元格中
环境
  • ubuntu 16.04 lts
  • excel 2016
  • python 2.7
  • opvencv 3.1
目录结构
.
├── excel_image.py
├── test.jpg
└── test.xlsx

代码解析
import cv2
from string import uppercase as AtoZ
from openpyxl import load_workbook
from openpyxl.styles import PatternFill

# 读取图片
image = cv2.imread("test.jpg")

# 载入Excel
wb = load_workbook(filename='test.xlsx')

# 活动的sheet获取
ws = wb.active

# 字母列表生成
# col_name = ['A', 'B', ...., 'Z']
col_name = list(AtoZ)

# excel列名生成
for i in xrange(len(image[0]) - 26):
    col_name.append(AtoZ[i // 26] + AtoZ[i % 26])

for col in xrange(len(image[0])):
    # 列的宽度调整
    ws.column_dimensions[col_name[col]].width = 0.3

for row in xrange(len(image)):
    # 行的高度调整
    ws.row_dimensions[row].height = 1.5

    for col in xrange(len(image[row])):
 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值