代码拉取完成,页面将自动刷新
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()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
 马建仓 AI 助手
马建仓 AI 助手