소스 검색

Add my files

Add polygons, etc
Hussein 13 년 전
부모
커밋
ee7d2b0160
3개의 변경된 파일195개의 추가작업 그리고 0개의 파일을 삭제
  1. 76 0
      LabelMe2.py
  2. 40 0
      shape.py
  3. 79 0
      ui_LabelME.py

+ 76 - 0
LabelMe2.py

@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+
+
+import re
+from PyQt4.QtCore import *
+from PyQt4.QtGui import *
+import ui_LabelME
+from shape import *
+
+MAC = "qt_mac_set_native_menubar" in dir()
+
+
+class LabelMeWindow(QMainWindow,
+        ui_LabelME.Ui_MainWindow):
+
+    def __init__(self, text, parent=None):
+        super(LabelMeWindow, self).__init__(parent)
+        self.__text = unicode(text)
+        self.__index = 0
+        
+        self.pic=QPixmap()
+        t=self.pic.load('me2.jpg')
+        self.shapes=[]
+        self.counter=0
+        sp=shape('one',QColor(0,255,0))
+        self.shapes.append(sp)
+        
+        self.setupUi(self)
+        self.dockWidget.setVisible(False)
+        
+    def text(self):
+
+        return self.__text
+
+
+    def paintEvent(self, event):
+
+       for shape in self.shapes:
+        	qpt = QPainter()
+        	qpt.begin(self)
+       	 	shape.drawShape(qpt)
+       	 	qpt.end()
+        
+           
+    
+  
+            
+   
+        
+        
+    def mousePressEvent(self, ev):
+        index=self.counter
+        if ev.button()==1:
+        
+        	self.shapes[index].addPoint(ev.pos())
+        if ev.button()==2:
+        	self.shapes[index].setFill(True)
+        	self.counter=index+1
+        	self.shapes.append(shape('one',QColor(0,255,0)))
+        	
+        self.repaint()
+
+
+if __name__ == "__main__":
+    import sys
+
+    text = "text"
+
+    
+
+    app = QApplication(sys.argv)
+    form = LabelMeWindow(text)
+    
+    form.show()
+    app.exec_()
+

+ 40 - 0
shape.py

@@ -0,0 +1,40 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+
+
+import sys, random
+from PyQt4.QtGui import *
+from PyQt4.QtCore import *
+
+class shape(object):
+    
+    def __init__(self ,label,color):
+    	self.label=label
+    	self.points=[]
+    	self.color=color
+    	self.fill=False
+    def getLabel(self):
+    	return label
+    	
+    def setLabel(self,label):
+    	self.label=label
+    
+    def setFill(self,fillB):
+    	self.fill=fillB
+    def addPoint(self,point):
+    	self.points.append(point)
+    	
+    def drawShape(self,painter):
+    	
+    	if len(self.points) >0 :
+    		pen=QPen(self.color)
+    		painter.setPen(pen)
+    		prePoint=self.points[0]
+    		path=QPainterPath()
+    		path.moveTo(prePoint.x(),prePoint.y())
+    		for point in self.points:
+    			path.lineTo(point.x(),point.y())
+    		painter.drawPath(path)
+    	if self.fill:
+    		painter.fillPath(path,Qt.red)

+ 79 - 0
ui_LabelME.py

@@ -0,0 +1,79 @@
+# -*- coding: utf-8 -*-
+
+# Form implementation generated from reading ui file '/Users/hussein/Desktop/LabelME/LabelME.ui'
+#
+# Created: Sun Oct  2 07:41:13 2011
+#      by: PyQt4 UI code generator 4.8.5
+#
+# WARNING! All changes made in this file will be lost!
+
+from PyQt4 import QtCore, QtGui
+
+try:
+    _fromUtf8 = QtCore.QString.fromUtf8
+except AttributeError:
+    _fromUtf8 = lambda s: s
+
+class Ui_MainWindow(object):
+    def setupUi(self, MainWindow):
+        MainWindow.setObjectName(_fromUtf8("MainWindow"))
+        MainWindow.resize(780, 568)
+        MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
+        self.centralwidget = QtGui.QWidget(MainWindow)
+        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
+        self.dockWidget = QtGui.QDockWidget(self.centralwidget)
+        self.dockWidget.setEnabled(True)
+        self.dockWidget.setGeometry(QtCore.QRect(100, 200, 381, 101))
+        self.dockWidget.setFloating(False)
+        self.dockWidget.setFeatures(QtGui.QDockWidget.NoDockWidgetFeatures)
+        self.dockWidget.setAllowedAreas(QtCore.Qt.NoDockWidgetArea)
+        self.dockWidget.setWindowTitle(QtGui.QApplication.translate("MainWindow", "Add Label", None, QtGui.QApplication.UnicodeUTF8))
+        self.dockWidget.setObjectName(_fromUtf8("dockWidget"))
+        self.dockWidgetContents = QtGui.QWidget()
+        self.dockWidgetContents.setObjectName(_fromUtf8("dockWidgetContents"))
+        self.lineEdit = QtGui.QLineEdit(self.dockWidgetContents)
+        self.lineEdit.setGeometry(QtCore.QRect(80, 10, 221, 22))
+        self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
+        self.pushButton_3 = QtGui.QPushButton(self.dockWidgetContents)
+        self.pushButton_3.setGeometry(QtCore.QRect(140, 40, 114, 32))
+        self.pushButton_3.setText(QtGui.QApplication.translate("MainWindow", "OK", None, QtGui.QApplication.UnicodeUTF8))
+        self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
+        self.label = QtGui.QLabel(self.dockWidgetContents)
+        self.label.setGeometry(QtCore.QRect(20, 10, 62, 16))
+        self.label.setText(QtGui.QApplication.translate("MainWindow", "Label", None, QtGui.QApplication.UnicodeUTF8))
+        self.label.setObjectName(_fromUtf8("label"))
+        self.dockWidget.setWidget(self.dockWidgetContents)
+        self.WPicture = QtGui.QWidget(self.centralwidget)
+        self.WPicture.setGeometry(QtCore.QRect(10, 10, 691, 491))
+        self.WPicture.setObjectName(_fromUtf8("WPicture"))
+        MainWindow.setCentralWidget(self.centralwidget)
+        self.menubar = QtGui.QMenuBar(MainWindow)
+        self.menubar.setGeometry(QtCore.QRect(0, 0, 780, 22))
+        self.menubar.setObjectName(_fromUtf8("menubar"))
+        self.menuFile = QtGui.QMenu(self.menubar)
+        self.menuFile.setTitle(QtGui.QApplication.translate("MainWindow", "File", None, QtGui.QApplication.UnicodeUTF8))
+        self.menuFile.setObjectName(_fromUtf8("menuFile"))
+        MainWindow.setMenuBar(self.menubar)
+        self.statusbar = QtGui.QStatusBar(MainWindow)
+        self.statusbar.setObjectName(_fromUtf8("statusbar"))
+        MainWindow.setStatusBar(self.statusbar)
+        self.toolBar = QtGui.QToolBar(MainWindow)
+        self.toolBar.setMinimumSize(QtCore.QSize(32, 32))
+        self.toolBar.setWindowTitle(QtGui.QApplication.translate("MainWindow", "toolBar", None, QtGui.QApplication.UnicodeUTF8))
+        self.toolBar.setMovable(True)
+        self.toolBar.setAllowedAreas(QtCore.Qt.AllToolBarAreas)
+        self.toolBar.setObjectName(_fromUtf8("toolBar"))
+        MainWindow.addToolBar(QtCore.Qt.LeftToolBarArea, self.toolBar)
+        MainWindow.insertToolBarBreak(self.toolBar)
+        self.actionClose = QtGui.QAction(MainWindow)
+        self.actionClose.setText(QtGui.QApplication.translate("MainWindow", "Close", None, QtGui.QApplication.UnicodeUTF8))
+        self.actionClose.setObjectName(_fromUtf8("actionClose"))
+        self.menuFile.addAction(self.actionClose)
+        self.menubar.addAction(self.menuFile.menuAction())
+
+        self.retranslateUi(MainWindow)
+        QtCore.QMetaObject.connectSlotsByName(MainWindow)
+
+    def retranslateUi(self, MainWindow):
+        pass
+