Exemple #1
0
    def __init__(self, parent=None):

        super(SpecifyTarget, self).__init__()

        self.setObjectName('specify_target')  # should be plugin name

        # ~ self.needsGraphicsView = True
        self.needsEventFilter = True
        self.fname = ''
        self.image = None
        self.targetImg = None

        # declare all parameter widgets below
        vbox1 = QVBoxLayout()
        hbox1 = QHBoxLayout()
        self.dblNumTargets = QDoubleSpinBox(objectName='dblNumTargets')
        self.dblNumTargets.setMinimum(1)
        self.dblNumTargets.setMaximum(5)
        self.dblNumTargets.setValue(1)
        self.dblNumTargets.setSingleStep(1)
        self.chkSaveTarget = QCheckBox('save target.png',
                                       objectName='chkSaveTarget')
        hbox1.addWidget(self.dblNumTargets)
        hbox1.addWidget(QLabel('num targets'))
        hbox1.addWidget(self.chkSaveTarget)

        labels = ['Rectangle', 'Square', 'Ellipse', 'Circle']
        groupBox1, self.bgrpShape = radio_filler('target shape', labels, 2)

        labels = ['opposite\ncorners', 'center\n-edge']
        groupBox2, self.bgrpDrawMethod = radio_filler('draw method', labels, 2)

        self.lblStatus = QLabel(wordWrap=True)
        groupBox2.layout().addWidget(self.lblStatus, 0, 2)

        self.bgrpShape.button(0).setChecked(True)
        self.bgrpDrawMethod.button(0).setChecked(True)

        self.bgrpShape.buttonClicked.connect(self.radio_handler)

        self.targetView = QGraphicsView()
        scene = QGraphicsScene()
        self.targetView.setScene(scene)
        # ~ vbox1.addLayout(hbox1)
        # ~ vbox1.addWidget(groupBox1)
        vbox1.addWidget(self.targetView)
        vbox1.addWidget(groupBox2)
        vbox1.setStretch(0, 3)
        vbox1.setStretch(1, 1)

        self.setLayout(vbox1)

        self.chkSaveTarget.setChecked(True)

        # class variables
        self.targetShape = None
        self.target = None
        self.begin = None
        self.end = None
        self.training = False
Exemple #2
0
    def __init__(self, parent=None):

        super(ImageLoader, self).__init__()

        self.Params = {}

        self.setObjectName('image_loader')  # should be plugin name

        self.isSource = True
        self.running = False
        self.grayScale = False
        self.outputBuffer = None

        self.grabber = Grabber()
        self.thread = QThread()
        self.grabber.moveToThread(self.thread)
        self.thread.started.connect(lambda: self.grabber.grab(
            img=self.outputBuffer, grayScale=self.grayScale))

        # declare all parameter widgets below
        vbox1 = QVBoxLayout()
        self.chkGrayScale = QCheckBox('Gray Scale')
        self.chkGrayScale.setObjectName('chkGrayScale')

        group_box, self.bgrpSource = radio_filler('Image Source',
                                                  ['File', 'Camera'], 2)
        # ~ print('init image_loader. bgrpSource parent ', self.bgrpSource.parent())
        self.bgrpSource.setParent(self)
        self.buttonGroupList.append(self.bgrpSource)
        # ~ print('self.bgrpSource.objectName()  ', self.bgrpSource.objectName())
        self.bgrpSource.buttonClicked.connect(self.radiohandler)
        # ~ bgrpSource.buttonClicked.connect(shambo)

        hbox2 = QHBoxLayout()
        lblFile = QLabel('File:')
        self.txtFile = QLineEdit()
        self.txtFile.setObjectName('txtFile')
        btnBrowseFile = QPushButton('Browse...')
        btnBrowseFile.clicked.connect(self.on_btnBrowseFile_clicked)
        hbox2.addWidget(lblFile)
        hbox2.addWidget(self.txtFile)
        hbox2.addWidget(btnBrowseFile)

        vbox1.addWidget(self.chkGrayScale)
        vbox1.addWidget(group_box)
        vbox1.addLayout(hbox2)

        self.setLayout(vbox1)
        # ~ widget.img = None
        for item in self.findChildren(QWidget):
            item.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)

        self.bgrpSource.button(1).setChecked(True)

        # ~ self.cap = cv.VideoCapture(0)
        self.timer = QTimer()
        self.timer.timeout.connect(self.grab)
Exemple #3
0
    def __init__(self, parent = None):
        
        super(CropCircle, self).__init__()
        
        
        self.setObjectName('crop_circle') # should be plugin name
           
        self.mask = None
        self.targetFname = ''
        
        # declare all parameter widgets below
        grid1 = QGridLayout()
        grid1.addWidget(QLabel('circles row'), 0, 0)
        self.spinCRow = QSpinBox(minimum = 1, objectName = 'spinCRow')
        grid1.addWidget(self.spinCRow,         0, 1)
        labels = ['black', 'white']
        groupBox1, self.bgrpBackground = radio_filler('Background Color', labels, 2)
        grid1.addWidget(groupBox1,  1, 0, 1, 2)

        self.setLayout(grid1)
Exemple #4
0
    def __init__(self, parent=None):

        super(Brightness, self).__init__()

        self.Params = {}

        self.setObjectName('brightness')  # should be plugin name

        # declare all parameter widgets below
        vbox1 = QVBoxLayout()

        labels = ['brightness/contrast', 'gamma correction']
        groupBox1, self.bgrpMethod = radio_filler('Method', labels, 1)
        self.buttonGroupList.append(self.bgrpMethod)
        self.bgrpMethod.buttonClicked.connect(self.radio_handler)

        self.stackedLayout = QStackedLayout()
        brightPage = QWidget()
        gammaPage = QWidget()

        vbox2 = QVBoxLayout()

        self.spinBrightness = QSpinBox()
        self.spinBrightness.setObjectName('spinBrightness')
        hbox1 = spinbox_slider(self.spinBrightness,
                               label='brightness',
                               orientation='horizontal',
                               min_=-127,
                               max_=127,
                               single_step=1,
                               default_value=0)

        self.spinContrast = QSpinBox()
        self.spinContrast.setObjectName('spinContrast')
        hbox2 = spinbox_slider(self.spinContrast,
                               label='contrast',
                               orientation='horizontal',
                               min_=-127,
                               max_=127,
                               single_step=1,
                               default_value=0)

        vbox2.addLayout(hbox1)
        vbox2.addLayout(hbox2)
        brightPage.setLayout(vbox2)

        self.dblGamma = QDoubleSpinBox()
        self.dblGamma.setObjectName('dblGamma')
        hbox3 = spinbox_slider(self.dblGamma,
                               label='gamma',
                               orientation='horizontal',
                               min_=0.1,
                               max_=10.,
                               single_step=.01,
                               default_value=1,
                               decimals=2,
                               log=True)
        # ~ self.dblGamma.setRange(.1,10.)
        # ~ self.dblGamma.setDecimals(2)
        # ~ self.dblGamma.setValue(1)
        # ~ self.dblGamma.setSingleStep(.01)
        # ~ self.dblGamma.setAccelerated(True)
        # ~ hbox3.addWidget(self.dblGamma)
        # ~ hbox3.addWidget(QLabel('gamma'))

        gammaPage.setLayout(hbox3)

        self.stackedLayout.addWidget(brightPage)
        self.stackedLayout.addWidget(gammaPage)

        vbox1.addWidget(groupBox1)
        vbox1.addLayout(self.stackedLayout)

        self.setLayout(vbox1)
        # ~ widget.img = None

        # set all sizepolicy s to preferred
        for item in self.findChildren(QWidget):
            item.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)

        # set brightness/contrast to default
        self.bgrpMethod.button(0).setChecked(True)
        self.stackedLayout.setCurrentIndex(0)
Exemple #5
0
    def __init__(self, parent=None):

        super(TemplateMatch, self).__init__()

        self.setObjectName('template_match')  # should be plugin name

        self.mask = None
        self.targetFname = ''

        # declare all parameter widgets below
        vbox1 = QVBoxLayout()
        label1 = QLabel(
            'only TM_SQDIFF and TM_CCORR_NORMED support masks (circles and ellipses)'
        )
        label1.setWordWrap(True)

        labels = [
            'TM_SQDIFF',  # 0
            'TM_SQDIFF_NORMED',  # 1
            'TM_CCORR',  # 2
            'TM_CCORR_NORMED',  # 3
            'TM_CCOEFF',  # 4
            'TM_CCOEFF_NORMED',  # 5
        ]
        groupBox1, self.bgrpMatchMethod = radio_filler('Match Method', labels,
                                                       2)
        self.bgrpMatchMethod.buttonClicked.connect(self.radio_handler)

        hbox1 = QHBoxLayout()
        tt = 'script row that contains specify_target for this match'
        self.spinTargetRow = QSpinBox(objectName='spinTargetRow')
        self.spinTargetRow.setToolTip(tt)
        hbox1.addWidget(self.spinTargetRow)
        hbox1.addWidget(QLabel('target row', toolTip=tt))

        hbox2 = QHBoxLayout()
        self.dblThreshold = QDoubleSpinBox(objectName='dblThreshold')

        self.groupInRegion = QGroupBox('inside region')
        self.groupInRegion.setObjectName('groupInRegion')
        self.groupInRegion.setCheckable(True)
        grid1 = QGridLayout()
        self.spinInside = QSpinBox(objectName='spinInside')
        self.spinInside.setMinimum(1)
        grid1.addWidget(QLabel('script row'), 0, 0)
        grid1.addWidget(self.spinInside, 0, 1)
        self.groupInRegion.setLayout(grid1)

        # set default method to cv.TM_CCOEFF_NORMED
        self.bgrpMatchMethod.button(cv.TM_CCOEFF_NORMED).setChecked(True)
        self.radio_handler()

        grid2 = QGridLayout()

        hbox2.addWidget(self.dblThreshold)
        hbox2.addWidget(QLabel('threshold'))
        grid2.addLayout(hbox2, 0, 0)
        grid2.addWidget(self.groupInRegion, 0, 1, 2, 1)

        self.lblResult = QLabel('score: ')
        grid2.addWidget(self.lblResult, 1, 0)

        # ~ vbox1.addWidget(label1)
        vbox1.addWidget(groupBox1)
        vbox1.addLayout(hbox1)
        vbox1.addLayout(grid2)
        vbox1.setStretch(0, 3)
        vbox1.setStretch(1, 1)
        vbox1.setStretch(2, 2)
        # ~ vbox1.addWidget(self.lblResult)

        self.setLayout(vbox1)
Exemple #6
0
    def __init__(self, parent=None):

        super(Morphology, self).__init__()

        self.setObjectName('morphology')  # should be plugin name

        # declare all parameter widgets below

        labels = [
            'Erode', 'Dilate', 'Open', 'Close', 'Gradient', 'TopHat',
            'BlackHat'
        ]
        tt = [
            'erodes away the boundaries of foreground object (Always try to keep foreground in white)',
            'makes the foreground fatter (Always try to keep foreground in white)',
            'erosion followed by dilation. It is useful in removing noise',
            '''Dilation followed by Erosion. It is useful in closing small holes inside
               the foreground objects (white), or small black points on the object.''',
            '''the difference between dilation and erosion of an image. The result will look
               like the outline of the object. ''',
            'the difference between input image and Opening of the image',
            'difference between the closing of the input image and input image.'
        ]
        #radio_filler(group_caption, labels, buttons_per_row = None, tool_tips = None):
        groupBox1, self.bgrpMorphMethod = radio_filler('Morphology Operation',
                                                       labels, 2, tt)

        self.bgrpMorphMethod.button(0).setChecked(True)

        # ~ widget.bgrpMorphMethod.buttonClicked.connect(lambda: radiohandler(widget))
        vbox1 = QVBoxLayout()

        hbox1 = QHBoxLayout()

        hbox2 = QHBoxLayout()
        self.dblKSize = QDoubleSpinBox(objectName='dblKSize',
                                       value=5,
                                       minimum=1,
                                       singleStep=2)
        # ~ self.dblKSize.setObjectName('dblKSize')
        # ~ self.dblKSize.setValue(5)
        # ~ self.dblKSize.setMinimum(1)
        # ~ self.dblKSize.setSingleStep(2)
        tt = '''kernel size. must be positive and odd'''
        self.dblKSize.setToolTip(tt)

        hbox3 = QHBoxLayout()
        self.dblIter = QDoubleSpinBox(objectName='dblIter',
                                      value=1,
                                      minimum=1,
                                      singleStep=1)
        hbox2.addWidget(QLabel('ksize'))
        hbox2.addWidget(self.dblKSize)
        hbox3.addWidget(QLabel('# iterations'))
        hbox3.addWidget(self.dblIter)

        labels = ['Rectangle', 'Circle', 'Cross']
        gbcap = 'Morphology Shape'
        groupBox2, self.bgrpMorphShape = radio_filler(gbcap, labels, 2)

        self.bgrpMorphShape.button(0).setChecked(True)

        vbox1.addLayout(hbox2)
        vbox1.addLayout(hbox3)
        vbox1.addWidget(groupBox2)
        vbox1.setStretch(0, 1)
        vbox1.setStretch(1, 1)
        vbox1.setStretch(2, 3)

        hbox1.addWidget(groupBox1)
        hbox1.addLayout(vbox1)

        self.setLayout(hbox1)
Exemple #7
0
    def __init__(self, parent=None):

        super(Binarize, self).__init__()

        self.Params = {}

        self.setObjectName('binarize')  # should be plugin name

        # declare all parameter widgets below
        vbox1 = QVBoxLayout()

        labels = ['Global', 'Adaptive', 'Adaptive Gaussian']
        groupBox1, self.bgrpMethod = radio_filler('Binarization Method',
                                                  labels)
        self.buttonGroupList.append(self.bgrpMethod)
        self.bgrpMethod.buttonClicked.connect(self.radio_handler)

        hbox1 = QHBoxLayout()
        self.chkInvert = QCheckBox('invert')
        self.chkInvert.setObjectName('chkInvert')
        self.chkInvert.setToolTip('swap black and white')
        self.dblMaxVal = QDoubleSpinBox()
        self.dblMaxVal.setObjectName('dblMaxVal')
        self.dblMaxVal.setRange(0., 255.)
        self.dblMaxVal.setValue(255)
        self.dblMaxVal.setToolTip(
            'Non-zero value assigned to the pixels for which the condition is satisfied '
        )
        hbox1.addWidget(self.chkInvert)
        hbox1.addWidget(self.dblMaxVal)
        hbox1.addWidget(QLabel('maxval'))

        self.stackedLayout = QStackedLayout()

        page0 = QWidget()  # global
        page1 = QWidget()  # adaptive, gaussian mean

        hboxp0 = QHBoxLayout()
        self.dblThresh = QDoubleSpinBox()
        self.dblThresh.setObjectName('dblThresh')
        self.dblThresh.setRange(0., 255.)
        self.dblThresh.setValue(127.)
        self.dblThresh.setDecimals(0.0)
        hboxp0.addWidget(self.dblThresh)
        hboxp0.addWidget(QLabel('Threshold'))
        page0.setLayout(hboxp0)

        hboxp2 = QHBoxLayout()
        self.dblKSize = QDoubleSpinBox()
        self.dblKSize.setObjectName('dblKSize')
        self.dblKSize.setRange(3., 31.)
        self.dblKSize.setSingleStep(2.0)
        self.dblKSize.setValue(11.0)
        self.dblKSize.setDecimals(0.0)
        self.dblKSize.lineEdit().setReadOnly(True)
        self.dblKSize.setToolTip(
            '''Size of a pixel neighborhood that is used to calculate a threshold
                                      value for the pixel: 3, 5, 7, and so on.'''
        )
        self.dblC = QDoubleSpinBox()
        self.dblC.setObjectName('dblC')
        self.dblC.setRange(-10., 10.)
        self.dblC.setSingleStep(1.0)
        self.dblC.setValue(2.0)
        self.dblC.setDecimals(0.0)
        self.dblC.setToolTip(
            '''Constant subtracted from the mean or weighted mean. Normally, 
                           it is positive but may be zero or negative as well.'''
        )

        hboxp2.addWidget(self.dblKSize)
        hboxp2.addWidget(QLabel('ksize'))
        hboxp2.addWidget(self.dblC)
        hboxp2.addWidget(QLabel('C'))
        page1.setLayout(hboxp2)

        self.stackedLayout.addWidget(page0)
        self.stackedLayout.addWidget(page1)

        vbox1.addWidget(groupBox1)
        vbox1.addLayout(hbox1)
        vbox1.addLayout(self.stackedLayout)

        self.setLayout(vbox1)

        # set all sizepolicy s to preferred
        for item in self.findChildren(QWidget):
            item.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)

        # set margins and spacing for all Layouts
        for item in self.findChildren(QLayout):
            item.setContentsMargins(0, 0, 0, 0)
            item.setSpacing(2)

        # set default method to Global
        self.bgrpMethod.button(0).setChecked(True)
        self.stackedLayout.setCurrentIndex(0)
Exemple #8
0
    def __init__(self, parent = None):
        
        super(Blur, self).__init__()
        
        self.setObjectName('blur') # should be plugin name
        
        # declare all parameter widgets below
        vbox1 = QVBoxLayout()
        vbox1.setSpacing(2)
        hbox1 = QHBoxLayout()
        hbox1.setSpacing(2)
            
        labels = ['box', 'Gaussian', 'Median', 'Bilateral']
        groupBox, self.bgrpBlurMethod = radio_filler('Blur Method', labels, 
                                buttons_per_row = 2, tool_tips = None)
        self.bgrpBlurMethod.buttonClicked.connect(self.radio_handler)
        
        self.stackedLayout = QStackedLayout()
        self.boxPage      = QWidget()
        self.gaussianPage = QWidget()
        self.medianPage   = QWidget()
        self.bilateralPage   = QWidget()
        
        gridLayout = QGridLayout()
        gridLayout.setSpacing(2)
        self.dblBoxKSize = QDoubleSpinBox()
        self.dblBoxKSize.setObjectName('dblBoxKSize')
        self.dblBoxKSize.setValue(5)
        self.dblBoxKSize.setMinimum(1)
        self.dblBoxKSize.setSingleStep(2)
        tt = '''blurring kernel size'''
        self.dblBoxKSize.setToolTip(tt)
        gridLayout.addWidget(QLabel('ksize'))
        gridLayout.addWidget(self.dblBoxKSize)
        self.boxPage.setLayout(gridLayout)
        
        gridLayout = QGridLayout()
        gridLayout.setSpacing(2)
        self.dblGaussianKSize = QDoubleSpinBox()
        self.dblGaussianKSize.setObjectName('dblGaussianKSize')
        self.dblGaussianKSize.setValue(5)
        self.dblGaussianKSize.setMinimum(1)
        self.dblGaussianKSize.setSingleStep(2)
        tt = '''blurring kernel size'''
        self.dblGaussianKSize.setToolTip(tt)
        self.dblSigma = QDoubleSpinBox()
        self.dblSigma.setObjectName('dblSigma')
        self.dblSigma.setValue(0)
        tt = '''Gaussian kernel standard deviation.  If sigma is zero, it is computed from ksize
                (see getGaussianKernel for details);'''
        self.dblSigma.setToolTip(tt)
        self.dblSigma.setSingleStep(.1)
        gridLayout.addWidget(QLabel('ksize'), 0, 0)
        gridLayout.addWidget(self.dblGaussianKSize, 0 , 1)
        gridLayout.addWidget(QLabel('sigma'), 1 ,0 )
        gridLayout.addWidget(self.dblSigma, 1, 1)
        self.gaussianPage.setLayout(gridLayout)
        
        gridLayout = QGridLayout()
        gridLayout.setSpacing(2)
        self.dblMedianKSize = QDoubleSpinBox()
        self.dblMedianKSize.setObjectName('dblMedianKSize')
        self.dblMedianKSize.setValue(5)
        self.dblMedianKSize.setMinimum(1)
        self.dblMedianKSize.setSingleStep(2)
        tt = '''aperture linear size; it must be odd and greater than 1, 
                for example: 3, 5, 7 ... '''
        self.dblMedianKSize.setToolTip(tt)
        gridLayout.addWidget(QLabel('ksize'))
        gridLayout.addWidget(self.dblMedianKSize)
        self.medianPage.setLayout(gridLayout)
        
        gridLayout = QGridLayout()
        gridLayout.setSpacing(2)
        self.dblD = QDoubleSpinBox()
        self.dblD.setObjectName('dblD')
        self.dblD.setValue(5)
        self.dblD.setMinimum(1)
        self.dblD.setSingleStep(1)
        tt = '''Diameter of each pixel neighborhood that is used during filtering.
                If it is non-positive, it is computed from sigma'''
        self.dblD.setToolTip(tt)
        self.dblBSigma = QDoubleSpinBox()
        self.dblBSigma.setObjectName('dblBSigma')
        self.dblBSigma.setValue(50)
        tt = '''Filter sigma in the color space. A larger value of the parameter
                means that farther colors within the pixel neighborhood (see 
                sigmaSpace) will be mixed together, resulting in larger areas 
                of semi-equal color.'''
        self.dblBSigma.setToolTip(tt)
        self.dblBSigma.setSingleStep(.1)
        gridLayout.addWidget(QLabel('d'), 0, 0)
        gridLayout.addWidget(self.dblD, 0 , 1)
        gridLayout.addWidget(QLabel('sigma'), 1, 0)
        gridLayout.addWidget(self.dblBSigma ,1 ,1)
        self.bilateralPage.setLayout(gridLayout)
        
        self.stackedLayout.addWidget(self.boxPage)
        self.stackedLayout.addWidget(self.gaussianPage)
        self.stackedLayout.addWidget(self.medianPage)
        self.stackedLayout.addWidget(self.bilateralPage)
        
        vbox1.addWidget(groupBox)
        vbox1.addLayout(self.stackedLayout)

        self.setLayout(vbox1)
        # ~ self.img = None
        
        # set all sizepolicy s to preferred
        for item in self.findChildren(QWidget):
            item.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        
        # set margins and spacing for all Layouts
        for item in self.findChildren(QLayout):
            item.setContentsMargins(0, 0, 0, 0)
            item.setSpacing(2)
        
        self.bgrpBlurMethod.button(0).setChecked(True)
Exemple #9
0
    def __init__(self, parent=None):

        super(TemplateMatch, self).__init__()

        self.setObjectName('templateMatch')  # should be plugin name

        self.mask = None

        # declare all parameter widgets below
        vbox1 = QVBoxLayout()
        label1 = QLabel(
            'only TM_SQDIFF and TM_CCORR_NORMED support masks (circles and ellipses)'
        )
        label1.setWordWrap(True)

        labels = [
            'TM_SQDIFF',  # 0
            'TM_SQDIFF_NORMED',  # 1
            'TM_CCORR',  # 2
            'TM_CCORR_NORMED',  # 3
            'TM_CCOEFF',  # 4
            'TM_CCOEFF_NORMED',  # 5
        ]
        groupBox1, self.bgrpMatchMethod = radio_filler('Match Method', labels,
                                                       2)
        self.bgrpMatchMethod.buttonClicked.connect(self.radio_handler)

        hbox1 = QHBoxLayout()
        self.dblThreshold = QDoubleSpinBox()

        self.groupBox2 = QGroupBox('inside target')
        self.groupBox2.setCheckable(True)
        grid1 = QGridLayout()
        self.spinRow = QSpinBox()
        self.spinRow.setMinimum(1)
        grid1.addWidget(QLabel('row'), 0, 0)
        grid1.addWidget(self.spinRow, 0, 1)
        self.groupBox2.setLayout(grid1)

        # set default method to cv.TM_CCOEFF_NORMED
        self.bgrpMatchMethod.button(cv.TM_CCOEFF_NORMED).setChecked(True)
        self.radio_handler()

        grid2 = QGridLayout()

        hbox1.addWidget(self.dblThreshold)
        hbox1.addWidget(QLabel('threshold'))
        grid2.addLayout(hbox1, 0, 0)
        grid2.addWidget(self.groupBox2, 0, 1, 2, 1)

        self.lblResult = QLabel('score: ')
        grid2.addWidget(self.lblResult, 1, 0)

        vbox1.addWidget(label1)
        vbox1.addWidget(groupBox1)
        vbox1.addLayout(grid2)
        # ~ vbox1.setStretch(0, 1)
        # ~ vbox1.setStretch(1, 1)
        # ~ vbox1.setStretch(2, 2)
        # ~ vbox1.addWidget(self.lblResult)

        self.setLayout(vbox1)
Exemple #10
0
    def __init__(self, parent=None):

        super(EdgeEnhance, self).__init__()
        self.setObjectName(
            'edge_detect')  # should be plugin name and (plugin file name!)

        self.isSource = False
        self.inputImg = None
        self.outputImg = None
        self.needsGraphicsView = False

        # declare all parameter widgets below
        vbox1 = QVBoxLayout()
        grid1 = QGridLayout()

        labels = ['Laplacian', 'Canny']
        groupBox1, self.bgrpDetectMethod = radio_filler(
            'Detect Method', labels, 2)

        self.bgrpDetectMethod.buttonClicked.connect(self.radio_handler)

        self.stackedLayout = QStackedLayout()
        laplacianPage = QWidget()
        cannyPage = QWidget()

        vbox2 = QVBoxLayout()
        labels = ['CV_8U', 'CV_16S', 'CV_64F']
        groupBox2, self.bgrpDepth = radio_filler('ddepth', labels, 3)
        tt = 'Desired depth of the destination image.'
        groupBox2.setToolTip(tt)

        self.bgrpDetectMethod.button(0).setChecked(True)
        self.bgrpDepth.button(0).setChecked(True)
        # ~ self.opt8U.setChecked(True)

        grid2 = QGridLayout()
        self.dblKSize = QDoubleSpinBox(objectName='dblKSize')
        self.dblKSize.setValue(5)
        self.dblKSize.setMinimum(1)
        self.dblKSize.setMaximum(31)
        self.dblKSize.setSingleStep(2)
        tt = '''Aperture size used to compute the second-derivative filters.
                must be positive and odd'''
        self.dblKSize.setToolTip(tt)

        self.dblScale = QDoubleSpinBox(objectName='dblScale')
        self.dblScale.setValue(1)
        self.dblScale.setMinimum(0.1)
        self.dblScale.setSingleStep(.1)
        tt = '''Optional scale factor for the computed Laplacian values. 
                By default, no scaling is applied (i.e. scale = 1)'''
        self.dblScale.setToolTip(tt)

        self.dblDelta = QDoubleSpinBox(objectName='dblDelta')
        self.dblDelta.setValue(0)
        self.dblDelta.setMinimum(0.0)
        self.dblDelta.setSingleStep(.1)
        tt = '''Optional delta value that is added to the results prior to storing them in dst .'''
        self.dblDelta.setToolTip(tt)

        grid2.addWidget(QLabel('ksize'), 0, 0)
        grid2.addWidget(self.dblKSize, 0, 1)
        grid2.addWidget(QLabel('scale'), 0, 2)
        grid2.addWidget(self.dblScale, 0, 3)
        grid2.addWidget(QLabel('delta'), 0, 4)
        grid2.addWidget(self.dblDelta, 0, 5)

        vbox2.addWidget(groupBox2)
        vbox2.addLayout(grid2)
        laplacianPage.setLayout(vbox2)

        grid3 = QGridLayout()
        self.dblThreshold1 = QDoubleSpinBox(objectName='dblThreshold1')
        self.dblThreshold1.setMinimum(5)
        self.dblThreshold1.setMaximum(2000)
        self.dblThreshold1.setValue(100)
        self.dblThreshold1.setSingleStep(5)

        self.dblThreshold2 = QDoubleSpinBox(objectName='dblThreshold2')
        self.dblThreshold2.setMinimum(5)
        self.dblThreshold2.setMaximum(2000)
        self.dblThreshold2.setValue(200)
        self.dblThreshold2.setSingleStep(5)

        self.dblApertureSize = QDoubleSpinBox(objectName='dblApertureSize')
        self.dblApertureSize.setValue(3)
        self.dblApertureSize.setSingleStep(2)
        self.dblApertureSize.setMinimum(3)
        self.dblApertureSize.setMaximum(7)

        self.chkL2Gradient = QCheckBox('L2Gradient', objectName='L2Gradient')
        self.chkL2Gradient.setLayoutDirection(Qt.RightToLeft)

        grid3.addWidget(self.dblThreshold1, 0, 0)
        grid3.addWidget(QLabel('threshold1'), 0, 1)
        grid3.addWidget(self.dblThreshold2, 0, 2)
        grid3.addWidget(QLabel('threshold2'), 0, 3)
        grid3.addWidget(self.dblApertureSize, 1, 0)
        grid3.addWidget(QLabel('Aperture Size'), 1, 1)
        grid3.addWidget(self.chkL2Gradient, 1, 2, 1, 2)

        cannyPage.setLayout(grid3)

        self.stackedLayout.addWidget(laplacianPage)
        self.stackedLayout.addWidget(cannyPage)

        vbox1.addWidget(groupBox1)
        vbox1.addLayout(self.stackedLayout)
        vbox1.setStretch(0, 1)
        vbox1.setStretch(1, 2)

        self.setLayout(vbox1)
Exemple #11
0
    def __init__(self, parent = None):
        
        super(Circles, self).__init__()
        
        self.setObjectName('circles') # should be plugin name
    
        # declare all parameter widgets below
        vbox1 = QVBoxLayout()
        hbox1 = QHBoxLayout()
        lblDp = QLabel('dp')
        self.dblDp = QDoubleSpinBox()
        self.dblDp.setObjectName('dblDp')
        self.dblDp.setValue(1.0)
        self.dblDp.setSingleStep(0.1)
        tt = '''Inverse ratio of the accumulator resolution to the image resolution. 
                For example, if dp=1 , the accumulator has the same resolution as the 
                input image. If dp=2 , the accumulator has half as big width and height.'''
        lblDp.setToolTip(tt)
        self.dblDp.setToolTip(tt)
        lblMinDist = QLabel('minDist')
        self.dblMinDist = QDoubleSpinBox()
        self.dblMinDist.setObjectName('dblMinDist')
        tt = '''Minimum distance between the centers of the detected circles. 
                If the parameter is too small, multiple neighbor circles may be falsely 
                detected in addition to a true one. If it is too large, some circles 
                may be missed.'''
        lblMinDist.setToolTip(tt)
        self.dblMinDist.setToolTip(tt)
        self.dblMinDist.setSingleStep(5)
        self.dblMinDist.setMaximum(2000)
        self.dblMinDist.setValue(150)
        hbox1.addWidget(lblDp)
        hbox1.addWidget(self.dblDp)
        hbox1.addWidget(lblMinDist)
        hbox1.addWidget(self.dblMinDist)
        
        hbox2 = QHBoxLayout()
        lblParam1 = QLabel('param1')
        self.dblParam1 = QDoubleSpinBox()
        self.dblParam1.setObjectName('dblParam1')
        self.dblParam1.setSingleStep(1)
        self.dblParam1.setValue(50)
        tt = '''First method-specific parameter. In case of HOUGH_GRADIENT , it is the higher 
                threshold of the two passed to the Canny edge detector (the lower one is twice smaller).'''
        lblParam1.setToolTip(tt)
        self.dblParam1.setToolTip(tt)
        lblParam2 = QLabel('param2')
        self.dblParam2 = QDoubleSpinBox()
        self.dblParam2.setObjectName('dblParam2')
        self.dblParam2.setSingleStep(1)
        self.dblParam2.setValue(45)
        tt = '''Second method-specific parameter. In case of HOUGH_GRADIENT , it is the accumulator
                threshold for the circle centers at the detection stage. The smaller it is,
                the more false circles may be detected. Circles, corresponding to the larger
                accumulator values, will be returned first.'''
        lblParam2.setToolTip(tt)
        self.dblParam2.setToolTip(tt)
        hbox2.addWidget(lblParam1)
        hbox2.addWidget(self.dblParam1)
        hbox2.addWidget(lblParam2)
        hbox2.addWidget(self.dblParam2)
        
        hbox3 = QHBoxLayout()
        lblMinRadius = QLabel('minRadius')
        self.dblMinRadius = QDoubleSpinBox()
        self.dblMinRadius.setObjectName('dblMinRadius')
        self.dblMinRadius.setSingleStep(1)
        self.dblMinRadius.setMaximum(2000)
        self.dblMinRadius.setValue(150)
        tt = '''Inverse ratio of the accumulator resolution to the image resolution. 
                For example, if dp=1 , the accumulator has the same resolution as the 
                input image. If dp=2 , the accumulator has half as big width and height.'''
        lblMinRadius.setToolTip(tt)
        self.dblMinRadius.setToolTip(tt)
        lblMaxRadius = QLabel('maxRadius')
        self.dblMaxRadius = QDoubleSpinBox()
        self.dblMaxRadius.setObjectName('dblMaxRadius')
        self.dblMaxRadius.setSingleStep(1)
        self.dblMaxRadius.setMaximum(2000)
        self.dblMaxRadius.setValue(200)
        
        tt = '''Minimum distance between the centers of the detected circles. 
                If the parameter is too small, multiple neighbor circles may be falsely 
                detected in addition to a true one. If it is too large, some circles 
                may be missed.'''
        lblMaxRadius.setToolTip(tt)
        self.dblMaxRadius.setToolTip(tt)
        hbox3.addWidget(lblMinRadius)
        hbox3.addWidget(self.dblMinRadius)
        hbox3.addWidget(lblMaxRadius)
        hbox3.addWidget(self.dblMaxRadius)
        
        hbox4 = QHBoxLayout()
        self.chkCrop = QCheckBox('Crop ', 
                                 objectName = 'chkCrop')
        labels = ['black', 'white']
        groupBox1, self.bgrpBackground = radio_filler('Background Color', labels, 2)
        self.bgrpBackground.button(0).setChecked(True)
        hbox4.addWidget(self.chkCrop)
        hbox4.addWidget(groupBox1)
        hbox4.setStretch(0,1)
        hbox4.setStretch(1,3)
        
        
        vbox1.addLayout(hbox1)
        vbox1.addLayout(hbox2)
        vbox1.addLayout(hbox3)
        vbox1.addLayout(hbox4)
        vbox1.setSpacing(2)

        self.setLayout(vbox1)