def create_database(self):
     all = ChineseCharacterGenerator.all(self.CHARACTERS_NUM)
     print "start len all", len(all)
     all = self.all_to_characters(all)
     print "unpacked len all", len(all)
     print "finish getting characters"
     with open(self.database_file, "w+") as file:
         file.write(self.heading);
         for i, sign in enumerate(all):
             image = sign.pilImageColor
             cv_image = PILtoCV(image)
             h_desc, v_desc = self.picture_descriptioner(cv_image)
             self.write_line(file, i,  sign.sign, sign.fontName, h_desc, v_desc)
             if i % self.reminder_num == 0:
                 print "Already written:", i
     print "Finally written", i
 def computeFeaturesInAllSet(cls, binary=True):
     allSet = {}
     allSet["X"] = []
     allSet["y"] = []
     picNum = 0
     all = ChineseCharacterGenerator.all()
     for sign, pic_in_fonts in all.items():
         for pic in pic_in_fonts:
             sign_features = cls.features(pic)
             sign_features = np.array(sign_features)
             allSet["X"].append(sign_features)
             allSet["y"].append(sign)
             picNum += 1
             if picNum % 1000 == 0:
                 print "Already {} pictures".format(picNum)
     with open(cls.allSetFile, "wb") as file:
         pickle.dump(allSet, file)
 def create_database(self):
     all = ChineseCharacterGenerator.all(self.CHARACTERS_NUM)
     print "start len all", len(all)
     all = self.all_to_characters(all)
     print "unpacked len all", len(all)
     print "finish getting characters"
     k = 1
     with open(self.database_file, "w+") as file:
         file.write(self.heading)
         for i, sign in enumerate(all):
             image = sign.pilImageColor
             cv_image = PILtoCV(image)
             desc = self.picture_descriptioner(cv_image, sign.fontName)
             if (
                 sign.fontName != "WCL-07.ttf"
                 and sign.fontName != "wts11.ttf"
                 and self.write_line(file, k, sign.sign, sign.fontName, desc)
             ):
                 k = k + 1
             if k % self.reminder_num == 0:
                 print "Already written:", k
     print "Finally written", k
 def set_chinese_sign_picture_right(self):
     self.sign_picture = ChineseCharacterGenerator.nextChar(self.sign_picture)
     while self.sign_picture.isBlank():
         self.sign_picture = ChineseCharacterGenerator.nextChar(self.sign_picture)
     self.refresh_setting_to_new_picture()
 def set_chinese_sign_picture_random(self):
     picture = ChineseCharacterGenerator.random(self.app.picture_actual_size)
     while picture.isBlank():
         picture = ChineseCharacterGenerator.random(self.app.picture_actual_size)
     self.sign_picture = picture
     self.refresh_setting_to_new_picture()
Пример #6
0
    for i in range(len(x_points)):
        file.write(str(x_points[i]) + ", ")
    for j in range(len(y_points) - 1):
        file.write(str(y_points[j]) + ", ")
    file.write(str(y_points[-1]) + "\n")


with open('line_detection_statistics.csv', 'w+') as file:
    file.write("Id, AllNum, Noise, ")
    for i in range(30):
        file.write("h" + str(i) + ", ")
    for j in range(29):
        file.write("v" + str(j) + ", ")
    file.write("v29\n")

    all = ChineseCharacterGenerator.all()

    i = 0
    all_num = 0
    magic_num = 9
    for character, inAllFonts in all.items()[:2000]:
        for signPicture in inAllFonts:
            cv_image = PILtoCV(signPicture.pilImageColor)
            x_points, y_points = LineDetector.getLinesOnPicture(cv_image)
            file.write(str(i) + ", " + str(all_num) + ",no, ")
            writePoints(file, x_points, y_points)
            i += 1
            for j in xrange(magic_num):
                image = ImageNoiser.Noise(cv_image)
                x_points, y_points = LineDetector.getLinesOnPicture(image)
                file.write(str(i) + ", " + str(all_num) + ",yes, ")
        all = ChineseCharacterGenerator.all()
        for sign, pic_in_fonts in all.items():
            for pic in pic_in_fonts:
                sign_features = cls.features(pic)
                sign_features = np.array(sign_features)
                allSet["X"].append(sign_features)
                allSet["y"].append(sign)
                picNum += 1
                if picNum % 1000 == 0:
                    print "Already {} pictures".format(picNum)
        with open(cls.allSetFile, "wb") as file:
            pickle.dump(allSet, file)

    @classmethod
    def allFeatures(cls):
        with open(cls.allSetFile, "r") as file:
            allFeaturesSet = pickle.load(file)
            print "all features set loaded"
            return allFeaturesSet


if __name__ == "__main__":
    sign = ChineseCharacterGenerator.random(30)
    CellFeatureExtractor.computeFeaturesInAllSet()
    allFeatures = CellFeatureExtractor.allFeatures()
    print len(allFeatures["X"][0])
    print len(allFeatures["X"])
    print len(allFeatures["y"])