1 Star 0 Fork 0

杨谨徽/代码托管

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
图像处理 1.64 KB
一键复制 编辑 原始数据 按行查看 历史
杨谨徽 提交于 2021-10-16 10:47 +08:00 . add 图像处理.py
import numpy as np
import cv2
ROWS = 512
COLS = 512
fin = open('E:\\.py\\BMP.bmp')
print(fin)
print("... Load input image")
img = np.fromfile(fin, dtype = np.uint8, count = ROWS * COLS)
print("Dimension of the old image array: ", img.ndim)
print("Size of the old image array: ", img.size)
img.shape = (img.size // COLS, COLS)
print("New dimension of the array:", img.ndim)
print("----------------------------------------------------")
print(" The 2D array of the original image is: \n", img)
print("----------------------------------------------------")
print("The shape of the original image array is: ", img.shape)
print
img.shape # 输出:(512, 512, 3)
# 使用line函数划线(改变矩阵数值进而改变色块数值达到划线效果)起点和终点的坐标
ptStart = (0, 510)
ptEnd = (512, 510)
point_color = (0, 0, 0) # BGR
thickness = 3
lineType = 4
cv2.line(img, ptStart, ptEnd, point_color, thickness, lineType)
ptStart = (0, 256)
ptEnd = (512, 256)
point_color = (0, 0, 0) # BGR
thickness = 3
lineType = 4
cv2.line(img, ptStart, ptEnd, point_color, thickness, lineType)
# 通过对矩阵的数值进行迭代处理得到黑线(自行设计)
i = 0
for i in range(0, 512):
if i < 512:
img[1][i] = 0
img[2][i] = 0
img[3][i] = 0
i += 1
else:
break
print(" The new 2D array of the original image is: \n", img) # 查看改变数值后的二维数组
cv2.namedWindow("image")
cv2.imshow('image', img)
cv2.waitKey(10000) # 显示 10000 ms 即 10s 后消失
cv2.destroyAllWindows()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/SHIBATORI/code-hosting.git
git@gitee.com:SHIBATORI/code-hosting.git
SHIBATORI
code-hosting
代码托管
master

搜索帮助