Python Image Processing Continuous Calibration Kernel Issue

asked 2020-06-04 13:25:09 -0500

murkoc gravatar image

Hi,

I have a Python program with OpenCV libraries. I am setting a calibration value once per each opening the program. Lastly I have added kernel slider and changing the kernel to reach optimized value for each image but after changing kernel after calibration, my results are changing.

I would like to ask how to get same calibration for each kernel for different images. Belows are my code lines related to calibration:

 self.process = processorController(self.image.copyImage(), self.kernelSize, 1, self.minAreaValue, self.maxAreaValue,self.colorCheck,self.safecountFlag,self.calibrationValue)


class MainWindow(QtWidgets.QMainWindow):
 calibrationValue = 1
 realcalibration = 2.0

    self.gui.calibrate.clicked.connect(lambda: self.setcalibrationFlag())


def calibration(self, pos):
    print("FLAG")
    print(self.calibrateFlag)
    if self.calibrateFlag:
        newX = self.myView.mapToScene(pos).x()
        newY = self.myView.mapToScene(pos).y()
        temp_distance = []
        choice = 0
        cnt = None
        for item in self.process.diamond_list:
            temp2_distance = math.sqrt(pow(abs(
                int(item.getCenter()[0]) - int(newX)), 2) + pow(abs(
                int(item.getCenter()[1]) - int(newY)), 2))
            temp_distance.append(temp2_distance)
        print("before distance")
        print(min(temp_distance))
        print(self.process.average)
        try:
            choice = temp_distance.index(min(temp_distance))
            id = self.process.diamond_list[choice].getDiamondID()
            print("finding stone")
            choice = id
            print(choice)
            for item in self.process.diamond_list:
                if item.getDiamondID() == choice:
                    cnt = item.getContourList()
            calibrateInstance = getSize(cnt,self.image.copyImage(),1)
            self.calibrationValue = ((calibrateInstance.dimA + calibrateInstance.dimB) / 2) / self.realcalibration
            print("Calibration")
            print(self.calibrationValue)
            self.msgPrint("Calibration Completed !!")
        except:
            self.calibrationValue = 1
            self.calibrateFlag = False

    self.process.labelinstance.calibrationValue = self.calibrationValue
    image2 = self.process.labelinstance.getLabelledImage(self.image.copyImage(),
                                                         self.process.diamond_list,
                                                         self.minAreaValue,
                                                         self.maxAreaValue, self.safecountFlag)
    self.process.final_image = image2
    self.setImageview(image2)




        self.process = processorController(self.image.copyImage(), self.kernelSize, 1, self.minAreaValue, self.maxAreaValue,self.colorCheck,self.safecountFlag,self.calibrationValue)
edit retag flag offensive close merge delete