cv2.imshow()和plt.show()不能一起工作 - Python opencv

时间:2013-11-06 13:51:33

标签: python opencv

我有这个脚本:

import numpy as np
import cv2
from matplotlib import pyplot as plt


im = cv2.imread('sun0016.bmp')
height, width, depth = im.shape
print height, width, depth
thresh = 132
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(imgray,(5,5),0)
edges = cv2.Canny(blur,thresh,thresh*2)
contours, hierarchy = cv2.findContours(edges,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
cnt = contours[0]
cv2.drawContours(im,contours,-1,(0,255,0),-1)

#centroid_x = M10/M00 and centroid_y = M01/M00
M = cv2.moments(cnt)
x = int(M['m10']/M['m00'])
y = int(M['m01']/M['m00'])
print x,y
print width/2.0,height/2.0
print width/2-x,height/2-y


cv2.circle(im,(x,y),1,(0,0,255),2)
cv2.putText(im,"x[px]    y[px]",(10,50), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,0,255))
cv2.putText(im,"center of Sun",(x,y), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,0,255))
cv2.putText(im,str(x)+","+str(y),(10,100), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,0,255))
cv2.circle(im,(width/2,height/2),1,(255,0,0),2)
cv2.putText(im,"center of image",(width/2,height/2), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,0,0))
cv2.putText(im,str(width/2)+","+str(height/2), (10,150), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,0,0))
cv2.putText(im,"difference:"+str(width/2-x)+","+str(height/2-y),(400,50),cv2.FONT_HERSHEY_SIMPLEX, 1, (0,255,255))

cv2.imshow('contour',im)

plt.hist(im.ravel(),255,[0,255])
plt.grid(True)

cv2.waitKey(0)
plt.show()

现在我想同时看到两个窗口,但不知道该怎么做。任何想法?现在我运行脚本我首先得到窗口“轮廓”,关闭后我得到窗口“直方图。”

由于

0 个答案:

没有答案