您的位置:首页 > 编程语言 > Python开发

opencv-python图像水平投影

2016-12-26 20:25 435 查看
import cv2
import numpy as np
from matplotlib import pyplot as plt

img=cv2.imread('obama.png')
GrayImage=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret,thresh1=cv2.threshold(GrayImage,50,255,cv2.THRESH_BINARY)
print thresh1[0,0]
(x,y)=thresh1.shape
a = [0 for z in range(0, x)]
print a[0]
for i in range(0,x):
for j in range(0,y):
if  thresh1[i,j]==0:
a[i]=a[i]+1
thresh1[i,j]=255    #to be white
#print j
for i  in range(0,x):
for j in range(0,a[i]):
thresh1[i,j]=0

print x,y

cv2.imshow('img',thresh1)
cv2.waitKey(0)
cv2.destroyAllWindows()


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: