该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
是这样的,本人小白一枚,最近有一个想法,想用python做上位机 C51做下位机做一台激光打印机,两个我都刚学不久,所以都不太了解,图像处理我用了抖动算法,效果也比较理想,但如何通过串口将图片发给下位机,真的做不出来,求大佬指点
附上编好的程序
import cv2 as cv
import serial
#读取图片
import numpy as np
cv.namedWindow('img')
def nothing(x):
pass
cv.createTrackbar('value','img',127,255,nothing)
while(True):
img = cv.imread("2.jpg", 0)
(imgHeight, imgWidth) = img.shape
value=cv.getTrackbarPos('value','img')
print('value:',value)
for i in range(0,imgHeight):
for j in range(0,imgWidth):
if img[i, j] > value:
err = img[i, j] - 255
img[i, j] = 255
else:
err = img[i, j]- 0
img[i, j] = 0
a = (err * 7) / 16
b = (err * 1) / 16
c = (err * 5) / 16
d = (err * 3) / 16
if (i!= (imgHeight-1))and(j != 0)and(j != (imgWidth-1)):
img[i + 0, j + 1] = img[i + 0, j + 1] + int(a)
img[i + 1, j + 1] = img[i + 1, j + 1] + int(b)
img[i + 1, j + 0] = img[i + 1, j + 0] + int(c)
img[i + 1, j - 1] = img[i + 1, j - 1] + int(d)
print(img)
print('change ok')
cv.imshow("img",img)
cv.waitKey(0)
print('button ok')
cv.imwrite("E://2.jpg",img)