1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
class TestWidget(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.scene = QtGui.QGraphicsScene()
self.view = QtGui.QGraphicsView(self.scene)
self.view.setBackgroundBrush(QtGui.QBrush(QtCore.Qt.darkGray))
self.button = QtGui.QPushButton("Do test")
layout = QtGui.QVBoxLayout()
layout.addWidget(self.button)
layout.addWidget(self.view)
self.setLayout(layout)
self.width = 100
self.height = 200
self.button.clicked.connect(self.do_test)
def do_test(self):
# an empty image
fname = "C:\Users\Guillaume\Qt\workspaceQt\Test\Pics\molThreeClean.bmp"
image = data.imread(fname, True, None)#data.camera()
theta = np.linspace(-np.pi / 2, np.pi / 2, 180)
out,angles,d = hough(image, None)
# precompute the sin and cos of the angles
cos_theta = np.cos(theta)
sin_theta = np.sin(theta)
yl = []
xl = []
for x in xrange(self.width):
yl = d[x]/np.sin(angles[x]) - x/np.tan(angles[x])
print " value yl", yl
print "value xl",d[x]/np.cos(angles[x]) - yl * np.sin(angles[x])
# yl.append()
# xl.append(d[x]/np.cos(angles[x]) - yl * np.sin(angles[x]))
#
# pm = QtGui.QPixmap(self.width,self.height)
# pm.fill(QtCore.Qt.transparent)
# p = QtGui.QPainter(pm)
#
# for i in xrange(self.width):
# p.setPen(QtGui.QColor(QtCore.Qt.black))
# p.drawPoint(xl[i],yl[i])
#
#
# p.end()
# print "loop end"
# pixmap = QtGui.QPixmap(self.width,self.height)
# p = QtGui.QPainter(pixmap)
# p.drawPixmap(0,0,pm)
# p.end()
#
#
# print "display in run"
# self.display_image(pixmap)
self.plot(image)
def plot(self,image):
out,angles,d = hough(image, None)
plt.subplot(1, 2, 1)
plt.imshow(image, cmap=plt.cm.gray)
plt.title('Input image')
plt.subplot(1, 2, 2)
plt.imshow(out, cmap=plt.cm.bone,
extent=(d[0], d[-1],
np.rad2deg(angles[0]), np.rad2deg(angles[-1])))
plt.title('Hough transform')
plt.xlabel('Angle (degree)')
plt.ylabel('Distance (pixel)')
plt.subplots_adjust(wspace=0.4)
plt.show()
def display_image(self, pixMap):
self.scene.clear()
self.scene.setSceneRect(0,0,self.width,self.height)
self.scene.addPixmap(pixMap)
self.scene.update()
self.save_image(pixMap.toImage())
def save_image(self,img):
img.save("C:\Users\xxx\Qt\workspaceQt\Test\Pics\Savings\skeletons\molThreeCleanSkull.bmp","BMP",-1)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
widget = TestWidget()
widget.resize(640, 480)
widget.show()
sys.exit(app.exec_()) |
Partager