Пример #1
0
        def __init__(self, *args, **kwargs):
            wx.Panel.__init__(self, *args, **kwargs)

            vbox = wx.BoxSizer(wx.VERTICAL)

            im = ImageView(self, ID_IMAGE_VIEW, size=(400, 300))
            vbox.Add(im, 1, wx.EXPAND | wx.BOTTOM)
            self.image = im

            self.box_tool = RangeTool(im)
            self.box_tool.direction = 0
            self.box_tool.active = True
            self.crosshair = Crosshair(im)

            c = wx.CheckBox(self, ID_HRANGE, 'Horizontal Range')
            vbox.Add(c, 0, wx.EXPAND | wx.BOTTOM, 5)

            c = wx.CheckBox(self, ID_VRANGE, 'Vertical Range')
            vbox.Add(c, 0, wx.EXPAND | wx.BOTTOM, 5)

            c = wx.CheckBox(self, ID_MULTIPLE, 'Multiple')
            vbox.Add(c, 0, wx.EXPAND)

            self.Bind(EVT_RANGE_ACTION_CHANGED, self.OnRangeActionChanged)
            self.Bind(EVT_RANGE_CHANGED, self.OnRangeChanged)
            self.Bind(EVT_COORDS, self.OnCoords)
            self.Bind(wx.EVT_CHECKBOX, self.OnCheck)

            self.SetSizerAndFit(vbox)
    def init_ui(self) -> None:
        """Initializes the application's Graphical User Interface.
        """

        # Create necessary layouts
        h_layout = QHBoxLayout()
        left_v_layout = QVBoxLayout()
        right_v_layout = QVBoxLayout()
        h_layout.addLayout(left_v_layout)
        h_layout.addLayout(right_v_layout)

        # Create and setup descriptive label, buttons, and combo box
        welcome_label = QLabel(
            "Welcome to the OCR (Optical Character Recognition) Translator App. "
            "Use this app to translate the text contained in images!")
        welcome_label.setWordWrap(True)
        take_pic_btn = QPushButton("Take a Picture")
        take_pic_btn.clicked[bool].connect(self.__take_picture)
        slct_img_btn = QPushButton("Select an Existing Image")
        slct_img_btn.clicked[bool].connect(self.__select_existing_image)
        translate_img_btn = QPushButton("Translate Text in Image")
        translate_img_btn.clicked[bool].connect(self.__translate_image_text)
        select_target_language_box = QComboBox()
        select_target_language_box.addItems(
            ['English', 'Spanish', 'French', 'German', 'Chinese', 'Turkish'])
        select_target_language_box.currentIndexChanged.connect(
            lambda x: self.__set_target_language(select_target_language_box))

        # Initialize ImageView instance to display image
        self.imageView = ImageView(QImage())

        # Add appropriate widgets to the left and right vertical layouts
        left_v_layout.addWidget(welcome_label)
        left_v_layout.addWidget(select_target_language_box)
        left_v_layout.addWidget(take_pic_btn)
        left_v_layout.addWidget(slct_img_btn)
        left_v_layout.addWidget(translate_img_btn)
        right_v_layout.addWidget(self.imageView)

        # setup and show window
        self.setLayout(h_layout)
        self.setWindowTitle("OCR Translator App")
        self.show()
Пример #3
0
from image_view import ImageView, handle_quit
from camera import Camera

iv0 = ImageView("Cam0")
iv1 = ImageView("Cam1")
iv2 = ImageView("Cam2")

cm0 = Camera(0)
cm1 = Camera(1)

while True:
	iv0.showImage(cm0.getImage())
	iv1.showImage(cm1.getImage())
	#iv2.showImage(cm2.getImage())
	handle_quit()
class TranslatorGUI(QWidget):
    """Subclass of QWidget that serves as the main window and interface for the application.

    :type self.imageCaptureDelegate: ImageCapture
    :var self.imageCaptureDelegate: Uses OpenCV to access webcam and take pictures with it.

    :type self.translateDelegate: ImageTranslator
    :var self.translateDelegate: Delegate that handles requests to Google's Cloud Vision/Translate APIs

    :type self.imageView: ImageView
    :var self.imageView: The object that displays the image and handles drawing translated words and their frames.
    """
    def __init__(self) -> None:
        super().__init__()
        self.init_ui()
        self.imageCaptureDelegate = ImageCapture()
        self.translateDelegate = ImageTranslator()

    def init_ui(self) -> None:
        """Initializes the application's Graphical User Interface.
        """

        # Create necessary layouts
        h_layout = QHBoxLayout()
        left_v_layout = QVBoxLayout()
        right_v_layout = QVBoxLayout()
        h_layout.addLayout(left_v_layout)
        h_layout.addLayout(right_v_layout)

        # Create and setup descriptive label, buttons, and combo box
        welcome_label = QLabel(
            "Welcome to the OCR (Optical Character Recognition) Translator App. "
            "Use this app to translate the text contained in images!")
        welcome_label.setWordWrap(True)
        take_pic_btn = QPushButton("Take a Picture")
        take_pic_btn.clicked[bool].connect(self.__take_picture)
        slct_img_btn = QPushButton("Select an Existing Image")
        slct_img_btn.clicked[bool].connect(self.__select_existing_image)
        translate_img_btn = QPushButton("Translate Text in Image")
        translate_img_btn.clicked[bool].connect(self.__translate_image_text)
        select_target_language_box = QComboBox()
        select_target_language_box.addItems(
            ['English', 'Spanish', 'French', 'German', 'Chinese', 'Turkish'])
        select_target_language_box.currentIndexChanged.connect(
            lambda x: self.__set_target_language(select_target_language_box))

        # Initialize ImageView instance to display image
        self.imageView = ImageView(QImage())

        # Add appropriate widgets to the left and right vertical layouts
        left_v_layout.addWidget(welcome_label)
        left_v_layout.addWidget(select_target_language_box)
        left_v_layout.addWidget(take_pic_btn)
        left_v_layout.addWidget(slct_img_btn)
        left_v_layout.addWidget(translate_img_btn)
        right_v_layout.addWidget(self.imageView)

        # setup and show window
        self.setLayout(h_layout)
        self.setWindowTitle("OCR Translator App")
        self.show()

    def __take_picture(self) -> None:
        """Launches image capture window, allows user to take image, then loads it.
        """

        image_file_name = self.imageCaptureDelegate.capture_image()
        self.__load_image(image_file_name)

    def __select_existing_image(self) -> None:
        """Launches file dialog box, allows user to select an existing image, then loads it.
        """

        file_dialog = QFileDialog()
        image_file_name = file_dialog.getOpenFileName()
        self.__load_image(image_file_name[0])

    def __set_target_language(self, box: QComboBox) -> None:
        """Sets the target language for translation requests based on the currently selected value in the combo box.
        """

        self.translateDelegate.set_target_language(box.currentText())

    def __translate_image_text(self) -> None:
        """Requests OCR translation from self.translateDelegate, and triggers drawing of translation.
        """

        data = QByteArray()
        buffer = QBuffer(data)
        self.imageView.get_current_image().save(buffer, 'JPG')

        word_boxes = self.translateDelegate.translate_image_text(data.data())
        self.imageView.draw_word_boxes(word_boxes)

    def __load_image(self, file_name: str) -> None:
        """Triggers display of image in self.imageView

        :param file_name: the file name of the image to be loaded.
        """

        self.imageView.set_image(QImage(file_name))
Пример #5
0
    def __init__(self, parent, callback=None,
                 size=(-1, -1), black=False):
        ImageView.__init__(self, parent, size=size, black=black)

        self.callback = callback
        self.interval = IntervalTimer(0.07, self.player)
Пример #6
0
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(837, 538)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout.setObjectName("verticalLayout")
        self.gridLayout = QtWidgets.QGridLayout()
        self.gridLayout.setObjectName("gridLayout")
        self.label_5 = QtWidgets.QLabel(self.centralwidget)
        self.label_5.setObjectName("label_5")
        self.gridLayout.addWidget(self.label_5, 0, 1, 1, 1)
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setObjectName("label_3")
        self.gridLayout.addWidget(self.label_3, 0, 0, 1, 1)
        self.sentiment_min = QtWidgets.QLineEdit(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.sentiment_min.sizePolicy().hasHeightForWidth())
        self.sentiment_min.setSizePolicy(sizePolicy)
        self.sentiment_min.setObjectName("sentiment_min")
        self.gridLayout.addWidget(self.sentiment_min, 1, 1, 1, 1)
        self.label_9 = QtWidgets.QLabel(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.label_9.sizePolicy().hasHeightForWidth())
        self.label_9.setSizePolicy(sizePolicy)
        self.label_9.setObjectName("label_9")
        self.gridLayout.addWidget(self.label_9, 0, 3, 1, 1)
        self.price_min = QtWidgets.QLineEdit(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.price_min.sizePolicy().hasHeightForWidth())
        self.price_min.setSizePolicy(sizePolicy)
        self.price_min.setObjectName("price_min")
        self.gridLayout.addWidget(self.price_min, 1, 0, 1, 1)
        self.label_4 = QtWidgets.QLabel(self.centralwidget)
        self.label_4.setObjectName("label_4")
        self.gridLayout.addWidget(self.label_4, 2, 0, 1, 1)
        self.label_10 = QtWidgets.QLabel(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.label_10.sizePolicy().hasHeightForWidth())
        self.label_10.setSizePolicy(sizePolicy)
        self.label_10.setObjectName("label_10")
        self.gridLayout.addWidget(self.label_10, 2, 3, 1, 1)
        self.sentiment_max = QtWidgets.QLineEdit(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.sentiment_max.sizePolicy().hasHeightForWidth())
        self.sentiment_max.setSizePolicy(sizePolicy)
        self.sentiment_max.setObjectName("sentiment_max")
        self.gridLayout.addWidget(self.sentiment_max, 3, 1, 1, 1)
        self.label_6 = QtWidgets.QLabel(self.centralwidget)
        self.label_6.setObjectName("label_6")
        self.gridLayout.addWidget(self.label_6, 2, 1, 1, 1)
        self.label_8 = QtWidgets.QLabel(self.centralwidget)
        self.label_8.setObjectName("label_8")
        self.gridLayout.addWidget(self.label_8, 2, 2, 1, 1)
        self.label_7 = QtWidgets.QLabel(self.centralwidget)
        self.label_7.setObjectName("label_7")
        self.gridLayout.addWidget(self.label_7, 0, 2, 1, 1)
        self.price_max = QtWidgets.QLineEdit(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.price_max.sizePolicy().hasHeightForWidth())
        self.price_max.setSizePolicy(sizePolicy)
        self.price_max.setObjectName("price_max")
        self.gridLayout.addWidget(self.price_max, 3, 0, 1, 1)
        self.filter_keyword = QtWidgets.QLineEdit(self.centralwidget)
        self.filter_keyword.setObjectName("filter_keyword")
        self.gridLayout.addWidget(self.filter_keyword, 1, 3, 1, 1)
        self.search_by_keyword = QtWidgets.QPushButton(self.centralwidget)
        self.search_by_keyword.setObjectName("search_by_keyword")
        self.gridLayout.addWidget(self.search_by_keyword, 1, 4, 1, 1)
        self.filter_product = QtWidgets.QComboBox(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.filter_product.sizePolicy().hasHeightForWidth())
        self.filter_product.setSizePolicy(sizePolicy)
        self.filter_product.setEditable(True)
        self.filter_product.setObjectName("filter_product")
        self.gridLayout.addWidget(self.filter_product, 1, 2, 1, 1)
        self.filter_brand = QtWidgets.QComboBox(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.filter_brand.sizePolicy().hasHeightForWidth())
        self.filter_brand.setSizePolicy(sizePolicy)
        self.filter_brand.setEditable(True)
        self.filter_brand.setObjectName("filter_brand")
        self.gridLayout.addWidget(self.filter_brand, 3, 2, 1, 1)
        self.show_people = QtWidgets.QPushButton(self.centralwidget)
        self.show_people.setObjectName("show_people")
        self.gridLayout.addWidget(self.show_people, 3, 3, 1, 2)
        self.verticalLayout.addLayout(self.gridLayout)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.submit = QtWidgets.QPushButton(self.centralwidget)
        self.submit.setObjectName("submit")
        self.horizontalLayout_2.addWidget(self.submit)
        spacerItem = QtWidgets.QSpacerItem(377, 20,
                                           QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_2.addItem(spacerItem)
        self.quit = QtWidgets.QPushButton(self.centralwidget)
        self.quit.setObjectName("quit")
        self.horizontalLayout_2.addWidget(self.quit)
        self.verticalLayout.addLayout(self.horizontalLayout_2)
        self.message = QtWidgets.QLabel(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.message.sizePolicy().hasHeightForWidth())
        self.message.setSizePolicy(sizePolicy)
        self.message.setMinimumSize(QtCore.QSize(0, 20))
        self.message.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.message.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.message.setText("")
        self.message.setObjectName("message")
        self.verticalLayout.addWidget(self.message)
        self.splitter = QtWidgets.QSplitter(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.splitter.sizePolicy().hasHeightForWidth())
        self.splitter.setSizePolicy(sizePolicy)
        self.splitter.setOrientation(QtCore.Qt.Horizontal)
        self.splitter.setObjectName("splitter")
        self.wordcloud = ImageView(self.splitter)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.wordcloud.sizePolicy().hasHeightForWidth())
        self.wordcloud.setSizePolicy(sizePolicy)
        self.wordcloud.setObjectName("wordcloud")
        self.histogram = ImageView(self.splitter)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.histogram.sizePolicy().hasHeightForWidth())
        self.histogram.setSizePolicy(sizePolicy)
        self.histogram.setObjectName("histogram")
        self.verticalLayout.addWidget(self.splitter)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        spacerItem1 = QtWidgets.QSpacerItem(40, 20,
                                            QtWidgets.QSizePolicy.Expanding,
                                            QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem1)
        self.save_results = QtWidgets.QPushButton(self.centralwidget)
        self.save_results.setEnabled(False)
        self.save_results.setObjectName("save_results")
        self.horizontalLayout.addWidget(self.save_results)
        self.show_results = QtWidgets.QPushButton(self.centralwidget)
        self.show_results.setObjectName("show_results")
        self.horizontalLayout.addWidget(self.show_results)
        self.verticalLayout.addLayout(self.horizontalLayout)
        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
        MainWindow.setTabOrder(self.price_min, self.price_max)
        MainWindow.setTabOrder(self.price_max, self.sentiment_min)
        MainWindow.setTabOrder(self.sentiment_min, self.filter_keyword)
        MainWindow.setTabOrder(self.filter_keyword, self.sentiment_max)
Пример #7
0
from image_view import ImageView, handle_quit
from camera import Camera

iv0 = ImageView("Cam0")
iv1 = ImageView("Cam1")
iv2 = ImageView("Cam2")

cm0 = Camera(0)
cm1 = Camera(1)

while True:
    iv0.showImage(cm0.getImage())
    iv1.showImage(cm1.getImage())
    #iv2.showImage(cm2.getImage())
    handle_quit()
Пример #8
0
from image_view import ImageView, handle_quit
import cv2
import time
import numpy as np

iv = ImageView("test")
img = np.zeros((640, 480, 3), np.uint8)

pressing = False
tuples = []  # (x, y, t)


def mouseHook(event, x, y, flags, param):
    global pressing, tuples, img, iv
    if event == cv2.EVENT_LBUTTONDOWN:
        pressing = True

    elif event == cv2.EVENT_MOUSEMOVE:
        if pressing:
            tuples.append((x, y, time.time()))
            cv2.rectangle(img, (x - 1, y - 1), (x + 1, y + 1), (255, 0, 0))

    elif event == cv2.EVENT_LBUTTONUP:
        pressing = False

    else:
        return

    iv.showImage(img)