Beispiel #1
0
def testLoadConfig():
    cf = TEST_CONF
    sd = ScaleDetection()
    sd.loadConfigFile(config_file=cf)
    assert sd.x_scale is not None
    assert sd.y_scale is not None
    assert sd.units is not None
Beispiel #2
0
def testCalibration():
    sd = ScaleDetection()
    im = sd.openImage(FILENAME)
    sd.calibrate(im, IMG_DIM[0], IMG_DIM[1], UNIT)
    w,h = IMG_PIX
    assert round(sd.x_scale * Decimal(w), 0) == IMG_DIM[0]
    assert round(sd.y_scale * Decimal(h), 0) == IMG_DIM[1]
Beispiel #3
0
    def processImages(self, image1):

        """
        The rest of the logic to stitch the image
        Args:
            image1: image from camera 1
        Returns:
            finalImage: image to be displayed to user to confirm it is correct
        """
        configCom = ConfigCommunicator()

        # Grabs skew info from config, and creates instance of ScannerCamera()

        skewObject = ScannerCamera(1)
        mtx, dist, newmtx = configCom.getSkew(1)
        skewObject.setSkewMtx(mtx, dist, newmtx)
        # Process board image
        image1 = skew_correction(image1, skewObject)

        # Grabs scale info from config
        dictionary = configCom.getScale()

        scale_detect = ScaleDetection()
        scale_detect.setScale(dictionary['x_scale'], dictionary['y_scale'], dictionary['units'])


        #finalImage = stitch_images(image1, image2)
        finalImage = image1
        cv2.imwrite('FinalImage.jpg', finalImage)
        contours, contourImage = find_contours(np.array(finalImage, dtype=np.uint8))
        xscale, yscale, units = get_scale(scale_detect)
        export_json(contours, xscale, yscale, units) #do I need to do something with return value?


        return contourImage #do we want to show the contours on this as well?
Beispiel #4
0
def testChain():
    sd = ScaleDetection()
    im = sd.openImage(FILENAME)
    sd.calibrate(im, IMG_DIM[0], IMG_DIM[1], UNIT)
    im = sd.openImage(FILENAMES[-1])
    w, h, unit = sd.getSize(im, show_conts=SAVE_IMG)
    print "Width: {}".format(round(w,1))
    print "Height: {}".format(round(h,1))
    assert round(w, 1) == round(DIMS[-1][0], 1)
    assert round(h, 1) == round(DIMS[-1][1], 1)
Beispiel #5
0
def testSaveConfig():
    cf = TEST_CONF
    sd = ScaleDetection()
    sd.x_scale = SCALE[0]
    sd.y_scale = SCALE[1]
    sd.units = UNIT
    sd.saveConfigFile(config_file=cf)
    with open(cf, 'r') as conf:
        j = json.load(conf)
    assert j["x_scale"] == sd.x_scale
    assert j["y_scale"] == sd.y_scale
    assert j["units"] == UNIT
Beispiel #6
0
def testScales():
    for i in range(0, len(FILENAMES)):
        sd = ScaleDetection()
        sd.x_scale = SCALE[0]
        sd.y_scale = SCALE[1]
        sd.units = UNIT
        im = sd.openImage(FILENAMES[i])
        w,h,unit = sd.getSize(im, show_conts=SAVE_IMG)
        print "Width: {}".format(round(w,1))
        print "Height: {}".format(round(h,1))
        assert round(w, 1) == round(DIMS[i][0], 1)
        assert round(h, 1) == round(DIMS[i][1], 1)
Beispiel #7
0
def testLoadConfigFail():
    cf = "abc"
    sd = ScaleDetection()
    f = sd.loadConfigFile(config_file=cf)
    assert f == False
Beispiel #8
0
def testCalibrationFailIm():
    sd = ScaleDetection()
    f = sd.calibrate("a", IMG_DIM[0], IMG_DIM[1], UNIT)
    assert f == False
Beispiel #9
0
def testCalibrationFail():
    sd = ScaleDetection()
    im = sd.openImage(FILENAME)
    f = sd.calibrate(im, IMG_DIM[0], "a", UNIT)
    assert f == False
Beispiel #10
0
def testDimensions():
    sd = ScaleDetection()
    im = sd.openImage(FILENAME)
    w, h = sd.getDimensions(im)
    assert w == IMG_PIX[0]
    assert h == IMG_PIX[1]