Ejemplo n.º 1
0
def tstInvert(img):
    " inverted images have a horizontal line at .3 instead of .7 "
    if db:
        img.save("invert.png")
    fset = img.findLines(minlinelength=100)
    fh = fset.filter(abs(fset.angle()) < 2)  #   near horizon
    if db:
        fh.draw(color=Color.RED, width=9)
        img.save(Gd)
        if db:
            cpause(["tst invert fset >>", len(fset)], Gd)
    v7 = 0
    v3 = 0
    for fx in fh:
        yh = round(fx.y / float(img.height), 1)  # % dist on y axis
        if yh == 0.3:
            v3 = v3 + 1
        elif yh == 0.7:
            v7 = v7 + 1
        if db:
            print "yh  v3  v7", yh, v3, v7, fx.angle()
    # print 'v3', v3, 'v7', v7
    if v3 > v7:
        return 180
    else:
        fmx = fh.filter(abs(fh.angle()) == max(abs(fh.angle())))
        x = fmx.angle()[0]  # one is enough
        print " remove skew", x
        return x  #  largest < 2 deg
Ejemplo n.º 2
0
def Cropx(img):
    global db, Gd
    # img = self.__img
    img.save(Gd)
    print " w x h", img.width, img.height
    if img.height == 2988:
        img = img.rotate(90)  #  all Dec set rotate
    # fi = cropSetx(img)

    ##    mask =   imgE.hueDistance(128.0)
    ##    img2  =   mask.binarize(128)
    img2 = img.hueDistance(Color.BLUE).invert()
    fi = cropSub(img2, 0.03, 0.21)  # tolerance .03
    if fi is None:
        print "fi is None try  no mask"
        imgE = img.erode(2)
        fi = cropSub(imgE, 0.1, 0.21)
        if fi is None:
            print "fi is none - try  100%"
            fi = cropSub(img2, 0.1, 1)
            if fi is None:
                raise ValueError("Cropx failed")

    print "Sub blb area", fi.area(),
    print round(100.0 * fi.area() / img.area(), 2), "pct"
    img3 = img.crop(fi)  # crop the original image
    angle = tstInvert(img3)
    img3 = img3.rotate(angle, fixed=False)  # remove skew or inversion

    img4 = img3.resize(w=1040, h=410)
    img4.save(Gd)
    if db:
        cpause("cropx", Gd)
    return img4
Ejemplo n.º 3
0
        if not fname == "input.png":
            self.img.save("input.png")
        self.cropped = Cropx(self.img)  # crop image
        self.cropped.save("cropTest.png")  # save intermediat results
        [self.wt, self.fat, self.h2o] = Part(self, self.cropped)  # partition cropped image
        self.fat.save("fatTest.png")
        self.h2o.save("h2oTest.png")
        self.wt.save("wtTest.png")
        #  hunt for the appropriate number in each partitioned image
        self.nwt = hunt(self.wt, "wt")
        self.nfat = hunt(self.fat, "fat")
        self.nh2o = hunt(self.h2o, "h2o")
        return None


if __name__ == "__main__":

    filename = "input.png"
    print "weight.py", filename
    #  Gd  = Display((1040,410))
    db = True
    s = Scale(filename)

    print s.name, "wt is", s.nwt, "iHunt global"
    for i in iHunt:
        print i
    s.cropped.save(Gd)  #   test image display
    cpause(" end Scale")

    Gd.quit()
Ejemplo n.º 4
0
    imgx.drawLine((fv2, fy), (fv2, imgx.height), color=Color.YELLOW, thickness=3)
    # imgx.show()
    wt = imgx.crop((fcut, 0), (fv1, fy))  #  100  x 300   st at 150   asp = .33
    dy = 0.15 * imgx.height
    fat = imgx.crop((fcut2, 0), (imgx.width, fy - dy))  # fy - dy ??
    h2o = imgx.crop((fcut, fyc), (fv2, imgx.height))
    return [wt, fat, h2o]


if __name__ == "__main__":
    Gd = Display((1040, 410))
    db = True
    fil = "input.png"
    # fil = 'C:\\Users\\charles\\Desktop\\ScTest\\TX\\20141103_0629.JPG'
    print "sworks.py", fil
    img = Image(fil)
    if not fil == "input.png":
        img.save("input.png")

    imt = Cropx(img)
    imt.save(Gd)
    [wt, fat, h2o] = Part(1, imt)
    fat.save(Gd)
    cpause("fat", Gd)
    h2o.save(Gd)
    cpause("h2o", Gd)

    raw_input("press enter to quit")
    Gd.quit()
    # cpause('end Scale')
Ejemplo n.º 5
0
    t = f[fds + 1 : fds + 11] + " " + f[fds + 12 : fds + 14] + ":" + f[fds + 15 : fds + 17]  # hr :  # mm

    td = t[:10]  #   just the date from above
    # td = t[3:10]
    print "tnow {}  t  {}".format(tnow, t)
    if td == tnow:
        from weight import Scale, Gd
        from rnum import cpause

        sx = Scale(f)  #    the main function of Weight that returns the number
        # sx is a tuple of w, fat, water
        print "Date and Time", t, "weight", sx.nwt
        #   note the raw string below
        f = open(r"C:\Users\charles\Data\Prod\wtdata\aaScale.r", "a")
        print "updd(", t, sx.nwt, ")"
        st = str(t)
        sw = str(sx.nwt) + ", " + str(sx.nfat) + ", " + str(sx.nh2o)
        s = "\nupdd('" + st + "'," + sw + ")"
        f.write(s)
        s = "\ninfo()"
        f.write(s)
        f.close()
        ##        sx.cropped.save(Gd)
        cpause()

        Gd.quit()
        rawchar = "Q"
    else:
        print "Not today's picture"
        rawchar = raw_input("Enter c to continue else Quit")