예제 #1
0
def __main__():
    args = argparser()
    out = args['output']

    orig_img = image.load(args['image']).convert('RGB')
    if args['contrast'] != None:
        orig_img = ImageEnhance.Contrast(orig_img).enhance(args['contrast'])
    orig_img = resizer.resize(orig_img, 1, ANTI_FONT_DISTORTION)
    fit_ratio = resizer.fit_in_ratio(orig_img.size, term.size())
    if args['ratio']:
        fit_ratio *= args['ratio']

    img = resizer.resize(orig_img, fit_ratio, (1, 1))
    lows, mids, highs = posterizer.thresholds(img)
    if args['color'] != None:
        lows = map(lambda val: bound_addition(val, args['color']), lows)
        mids = map(lambda val: bound_addition(val, args['color']), mids)
        highs = map(lambda val: bound_addition(val, args['color']), highs)
    colors = posterizer.posterize(img, mids, highs)

    #    img.show()
    shapes = resizer.resize(orig_img, fit_ratio, (2, 4))
    #    shapes.show()
    shapes = shapes.convert('L')
    threshold = otsu.threshold(shapes.histogram())
    #    mask = shapes.point(lambda val: 255 if val <= threshold else 0).convert('1')
    #    threshold = otsu.threshold(shapes.histogram(mask))
    if args['shape'] != None:
        threshold = bound_addition(threshold, args['shape'])
    shapes = shapes.point(lambda val: 255
                          if val > threshold else 0).convert('1')
    #    shapes.show()
    dots = Canvas()
    w, h = shapes.size
    for index, pixel in enumerate(list(shapes.getdata()), 0):
        if pixel:
            dots.set(index % w, index // w)


#    out.write(dots.frame(0,0,w,h))
#    out.write('\n')

    w, h = colors.size
    for index, pixel in enumerate(list(colors.getdata()), 0):
        x = (index % w) * 2
        y = (index // w) * 4
        miniframe = unicode(dots.frame(x, y, x + 2, y + 4), 'utf-8')
        miniframe = miniframe if len(miniframe) else u'\u2800'
        out.write(color_print.rgb2esc(pixel, [0, 0, 0], lows, highs,
                                      miniframe))
        if not (1 + index) % w:
            out.write('\n')
def loadin():
    x=['sqr','sphr']
    ret=[]
    lbl=[]
    ret2=[]
    lbl2=[]
    ret_labels=[]
    cnt=0
    print('start')
    
    for j in range(110):
        cnt=0
        for i in x:
            if j%30==0:
                print('x')
            if j<=2:
                cloud=dl.DataLoader('../data_pcd/'+x[cnt]+str(j)+'.pcd')
                
                for i in range(6):
                    cloud[i]=rs.resize(cloud[i],250)
                ret.append(cloud)
                
                if x[cnt]=='sqr':
                    lbl.append(0)
                else:
                    lbl.append(1)
            else:
                cloud=dl.DataLoader('../data_pcd/'+x[cnt]+str(j)+'.pcd')
                for i in range(6):
                    cloud[i]=rs.resize(cloud[i],250)
                    
                ret2.append(cloud)
                if x[cnt]=='sqr':
                    lbl2.append(0)
                else:
                    lbl2.append(1)
        
            cnt+=1
    #print(ret)
    try:
        np.save('ret',ret)
        np.save('lbl',lbl)
        np.save('ret2',ret2)
        np.save('lbl2',lbl2)
    except:
        print('saving unsuccesful')
        
    return ret,lbl,ret2,lbl2
예제 #3
0
def load_image(path):
    img = cv2.imread(path)
    img = resizer.fill_to_square(img)
    img = resizer.resize(img, IMAGE_SIZE)
    img = np.asarray(img) / (255.0)  # normalize Data
    img = img.reshape(-1, IMAGE_SIZE, IMAGE_SIZE, 3)
    return img
def loadin_pred(file):
    ret=[]
    cloud=dl.DataLoader(file)
    for i in range(6):
        cloud[i]=rs.resize(ab.fill(cloud[i]),250)
        cv2.imwrite('as'+str(i)+'.jpg',cloud[i])
    ret.append(cloud)
    return ret
    def __call__(self, image):
        try:
            opened_image = Image.open(image.path)
            squared_image = square(opened_image)

        except OSError:
            return image.path

        for resolution in self.output_folders:
            resized_image = resize(resolution, squared_image)
            save_path = self.output_folders[resolution]
            save_name = '_'.join([image.prefix, image.name])
            print("saving image %s in resolution %dpx" %
                  (save_name, resolution))
            resized_image.save(path.join(save_path, save_name))
예제 #6
0
    def openFile(self):
        options = QFileDialog.Options()
        options |= QFileDialog.DontUseNativeDialog
        tuple = QFileDialog.getOpenFileName(
            None,
            "QFileDialog.getOpenFileName()",
            "",
            "All Files (*);;PNG (*.png);;JPEG (*.jpeg *jpg)",
            options=options)
        fileName = tuple[0]
        if fileName != '':
            self.input_file_name = os.path.split(fileName)[1]

            img1 = cv2.imread(fileName, cv2.IMREAD_GRAYSCALE)

            img_converted = convert(img1)
            self.imgDraw.setPixmap(QPixmap(img_converted))

            self.input_img = img1

            #Converted to set to a QLabel for Matcheswindow
            self.input_img_converted = convert(resize(img1, 300))
import argparse
import os
import re
import resizer

parser = argparse.ArgumentParser()
parser.add_argument('--output_dir', type=str, action='store', default='.')
parser.add_argument('--width', type=int, action='store', default=32)
parser.add_argument('--height', type=int, action='store', default=32)
parser.add_argument('input_dir', type=str, action='store')

args = parser.parse_args()

if args.input_dir == args.output_dir:
    print('Error: output directory is same as input directory.')
    exit()

if not os.path.exists(args.output_dir):
    os.makedirs(args.output_dir)

print("resize target=(%d, %d)" % (args.width, args.height))
files = os.listdir(args.input_dir)
files = [file for file in files if not re.match('^\.', file)]
for i, file in enumerate(files):
    inputname = os.path.join(args.input_dir, file)
    outputname = os.path.join(args.output_dir, file)
    print('%d: input=%s, output=%s' % (i, inputname, outputname))
    resizer.resize(inputname, outputname, args.width, args.height)
예제 #8
0
def upload():
    if(request.cookies.get("pwauname")):
        email = str(request.cookies.get("pwauname"))
        projectName = request.form.get("project_name")
        projectImage = request.files.get("project_image")
        projectImageName = ""
        json_file = open(f"{APP_ROOT}/db/data.json", "r")
        data = json.load(json_file)
        json_file.close()
        for key,value in data.items():
            if((value["email"]==email) and (value["projectName"]==projectName)):
                flash("Project already exists!")
                return redirect(url_for("index"))
        if(projectImage):
            os.makedirs(f"{APP_ROOT}/static/folders/{email}/{projectName}")
            projectImageName = projectImage.filename
            target = f"{APP_ROOT}/static/folders/{email}/{projectName}"
            destination = "/".join([target, projectImageName])
            projectImage.save(destination)
        else:
            flash("No image provided!")
            return redirect(url_for("index"))

        json_file = open(f"{APP_ROOT}/db/data.json", "r")
        data = json.load(json_file)
        json_file.close()
        newDataId = str(uuid.uuid4())
        curDate = dt.datetime.now()
        day = curDate.strftime("%d-%m-%Y")
        newData = {
            newDataId: {
                "email": email,
                "projectName": str(projectName),
                "date": str(day),
                # "projectImage": str(projectImageName),
                "48": "logo48.png",
                "72": "logo72.png",
                "96": "logo96.png",
                "144": "logo144.png",
                "196": "logo196.png",
                "512": "logo512.png",
                "app": "app.js",
                "serviceWorker": "serviceWorker.js",
                "manifest": "manifest.json"
            }
        }
        data.update(newData)
        json_file = open(f"{APP_ROOT}/db/data.json", "w")
        json_file.seek(0)
        json.dump(data, json_file, indent=2)
        json_file.close()
        resizer.resize(48,48,email,projectName,projectImageName)
        resizer.resize(72,72,email,projectName,projectImageName)
        resizer.resize(96,96,email,projectName,projectImageName)
        resizer.resize(144,144,email,projectName,projectImageName)
        resizer.resize(196,196,email,projectName,projectImageName)
        resizer.resize(512,512,email,projectName,projectImageName)
        os.remove(
            f"{APP_ROOT}/static/folders/{email}/{projectName}/{projectImageName}"
        )

        data = {
                    "manifest_version": 2,
                    "name": f"{projectName}",
                    "short_name": f"{projectName}",
                    "start_url": "/",
                    "display": "standalone",
                    "background_color": "#FFFFFF",
                    "theme_color": "#FFFFFF",
                    "orientation": "portrait",
                    "icons": [
                        {
                            "src": "./logo48.png",
                            "type": "image/png",
                            "sizes": "48x48"
                        },
                        {
                            "src": "./logo72.png",
                            "type": "image/png",
                            "sizes": "72x72"
                        },
                        {
                            "src": "./logo96.png",
                            "type": "image/png",
                            "sizes": "96x96"
                        },
                        {
                            "src": "./logo144.png",
                            "type": "image/png",
                            "sizes": "144x144"
                        },
                        {
                            "src": "./logo196.png",
                            "type": "image/png",
                            "sizes": "196x196"
                        },
                        {
                            "src": "./logo512.png",
                            "type": "image/png",
                            "sizes": "512x512"
                        }
                    ],
                    "scope": "/"
                }

        json_file = open(f"{APP_ROOT}/static/folders/{email}/{projectName}/manifest.json", "w")
        json_file.seek(0)
        json.dump(data, json_file, indent=2)
        json_file.close()
        
        flash(f"{projectName} created!")
        return redirect(url_for('index'))
    else:
        return redirect(url_for('login'))
예제 #9
0
 def load_image(self, path):
     img = cv2.imread(path)  # Read Image as numbers
     img_square = resizer.fill_to_square(img)
     img_resized = resizer.resize(img_square, self.IMAGE_SIZE)
     return img_resized
예제 #10
0
    def __init__(self, input_window, mainwindow_object, modified=False):
        super().__init__()
        self.input_window = input_window
        self.setupUi(input_window)



        self.mainwindow_object = mainwindow_object
        self.input_pic = mainwindow_object.input_img_converted


        #Original Bilder die zum Input gematched wurden
        self.match1 = convert(resize(self.mainwindow_object.top5Objects[0].imgdata, 150))
        self.match2 = convert(resize(self.mainwindow_object.top5Objects[1].imgdata, 150))
        self.match3 = convert(resize(self.mainwindow_object.top5Objects[2].imgdata, 150))
        self.match4 = convert(resize(self.mainwindow_object.top5Objects[3].imgdata, 150))
        self.match5 = convert(resize(self.mainwindow_object.top5Objects[4].imgdata, 150))

        #Modifizierte Bilder die zum Input gematched wurden

        self.match1_modified = convert(resize(self.mainwindow_object.top5Objects[0].img_data_skeleton, 150))
        self.match2_modified = convert(resize(self.mainwindow_object.top5Objects[1].img_data_skeleton, 150))
        self.match3_modified = convert(resize(self.mainwindow_object.top5Objects[2].img_data_skeleton, 150))
        self.match4_modified = convert(resize(self.mainwindow_object.top5Objects[3].img_data_skeleton, 150))
        self.match5_modified = convert(resize(self.mainwindow_object.top5Objects[4].img_data_skeleton, 150))


        #Matching Ergebnisse der Einzelnen Matches
        self.match1Result = rgb2qimage(cv2.resize(self.mainwindow_object.top5Objects[0].matching_result,(360,300)))
        self.match2Result = rgb2qimage(cv2.resize(self.mainwindow_object.top5Objects[1].matching_result,(360,300)))
        self.match3Result = rgb2qimage(cv2.resize(self.mainwindow_object.top5Objects[2].matching_result,(360,300)))
        self.match4Result = rgb2qimage(cv2.resize(self.mainwindow_object.top5Objects[3].matching_result,(360,300)))
        self.match5Result = rgb2qimage(cv2.resize(self.mainwindow_object.top5Objects[4].matching_result,(360,300)))

        self.matchresults = [self.match1Result, self.match2Result, self.match3Result, self.match4Result,
                             self.match5Result]





        # Ab hier Events

        # Vorschaubilder
        self.m1.setPixmap(QPixmap(self.match1))
        self.m2.setPixmap(QPixmap(self.match2))
        self.m3.setPixmap(QPixmap(self.match3))
        self.m4.setPixmap(QPixmap(self.match4))
        self.m5.setPixmap(QPixmap(self.match5))

        self.inputIMG.setPixmap(QPixmap(self.input_pic))

        if modified == True:
            # Vorschau der modifizierten Bilder
            self.modified_label.setText("Modifiziertes Bild")
            self.original_label.setText("Original Bild")
            self.skel1.setPixmap(QPixmap(self.match1_modified))
            self.skel2.setPixmap(QPixmap(self.match2_modified))
            self.skel3.setPixmap(QPixmap(self.match3_modified))
            self.skel4.setPixmap(QPixmap(self.match4_modified))
            self.skel5.setPixmap(QPixmap(self.match5_modified))

            self.skel_input.setPixmap(QPixmap(convert(resize(self.mainwindow_object.input_sift_object.img_data_skeleton, 300))))


        # VorschauNamen
        self.match1Name.setText(self.mainwindow_object.top5Objects[0].imgname)
        self.match2Name.setText(self.mainwindow_object.top5Objects[1].imgname)
        self.match3Name.setText(self.mainwindow_object.top5Objects[2].imgname)
        self.match4Name.setText(self.mainwindow_object.top5Objects[3].imgname)
        self.match5Name.setText(self.mainwindow_object.top5Objects[4].imgname)

        self.inputImgName.setText(self.mainwindow_object.input_file_name)

        # Buttons
        self.match1Btn.clicked.connect(self.showMatch1)
        self.match2Btn.clicked.connect(self.showMatch2)
        self.match3Btn.clicked.connect(self.showMatch3)
        self.match4Btn.clicked.connect(self.showMatch4)
        self.match5Btn.clicked.connect(self.showMatch5)

        self.backBtn.clicked.connect(self.closeSecond)