Exemplo n.º 1
0
 def HSV(x, img, thresh):
     imgb = CV2Service.cvtColor1(img)
     imgH = CV2Service.cvtColorHsv(imgb)
     im = Image.fromarray(DominantService.croping(imgH))
     img1 = np.copy(imgH)
     x = max(im.getcolors(im.size[0] * im.size[1]))
     cl = im.getcolors(im.size[0] * im.size[1])
     cl1 = sorted(cl, reverse=True)
     print('hsv')
     color12 = np.zeros([3])
     color12[0] = x[1][0]
     color12[1] = x[1][1]
     color12[2] = x[1][2]
     img21 = np.zeros([img.shape[0], img.shape[1]])
     colorC1 = np.zeros([3])
     count = 0
     for i in range(0, img.shape[0]):
         for j in range(0, img.shape[1]):
             if color12[2] > 230 or color12[2] < 50:
                 distance_cen = ImageAlter.dist1_v(color12, imgH[i, j, :])
             else:
                 distance_cen = ImageAlter.dist1_w(color12, imgH[i, j, :])
             if distance_cen < thresh:
                 img21[i, j] = 1
                 colorC1 += img[i, j, :]
                 count += 1
     colorC1 = np.round(colorC1 / count)
     model2 = ImageAlter.enhancing(img21, 2)
     return model2, img1, colorC1, x
Exemplo n.º 2
0
 def fill1(perspective_carpet, back_floor):
     #perspective_carpet = perspective_carpet[450:2000, 1000:2000, :]
     imax,jmax,ch = np.shape(back_floor)
     img3 = np.copy(back_floor)
     img2gray = CV2Service.rgb2gray(img3)
     for ii in range(0, imax):
         for jj in range(0, jmax):
             if img2gray[ii, jj] == 0: 
                 back_floor[ii, jj, :] = perspective_carpet[ii, jj, :]
     return back_floor
Exemplo n.º 3
0
    def start_filling(self, socket):
        self.mainFloor = self.imread(self.url)
        extended_carpet = CV2Service.carpet_extend(self.mainFloor,
                                                   self.carpType)
        perspective_carpet = self.perspective_maker(extended_carpet)
        if self.type == 1:
            image = FloorFillService.fill1(perspective_carpet, self.backFloor)
        else:
            image = FloorFillService.fill2(perspective_carpet, self.backFloor)

        socket.write_message(self.image2str(image))
Exemplo n.º 4
0
    def start_clustering(self, socket):
        im = DominantService.pilimread(self.url)
        img = CV2Service.cv2imread(self.url)
        x = DominantService.getColors(im)
        flag1 = DominantService.rgbOrhsv(x, self.flag)
        thresh = 32
        #flag1 = 1
        if flag1 < 1:
            print('hi')
            model2, img1 = DominantService.RGB(x, img, thresh)
            #colorC1 = np.copy(x)
        else:
            print('bye')
            model2, img1, colorC1, x = DominantService.HSV(x, img, thresh)
        print("part 123")
        new_im, img1 = Color2Service.modeling23color(model2, img1)
        color_centre1 = Color2Service.colorfindergram(new_im, thresh)
        color12 = Color2Service.color2get(new_im, thresh)
        #color_centre1 = Color2Service.mergeColor(color_centre1, color12)
        model3 = Color2Service.finalModel(thresh, color_centre1, img1, model2,
                                          flag1, 4)
        model_new = Color2Service.reshaping(model3)
        s = DominantService.size_img(img)
        colorC23 = Color2Service.findColorC(model3, img)
        colors = Color2Service.colorConcat(color_centre1, x)
        print(colorC23)
        ############
        num = 3
        admat = FinalMerge.adMat(num, colors, thresh, flag1)
        print(admat)
        model2, number1 = FinalMerge.mergeColor(model_new, num, admat)
        print(np.size(model2))
        number, model1 = FinalMerge.modelEnhance(model2, num)
        print("part 101")
        ###################################################

        #        model1 = model_new
        #################################################
        serialized_data = json.dumps({
            "colors": colors.tolist(),
            "model_1d": model1.tolist(),
            "shape": s.tolist(),
            "number": number
        })
        socket.write_message(serialized_data)
Exemplo n.º 5
0
 def imread(url):
     image = CV2Service.imread_remote(url)
     img_array = np.array(bytearray(image), dtype=np.uint8)
     return CV2Service.cvtColor(CV2Service.imdecode(img_array))
Exemplo n.º 6
0
 def perspective_maker(self, extended_carpet):
     if self.type == 1:
         return CV2Service.perspective_maker1(extended_carpet)
     else:
         return CV2Service.perspective_maker2(extended_carpet)
Exemplo n.º 7
0
 def imread_local(self, url):
     return CV2Service.imread_local(url)
Exemplo n.º 8
0
    def start_clustering(self, socket):    
        start = time.time()
        num_flg = 6
        number_color = 1
        flag_havingColor =  np.ones([6]);
        num_haveingColor = 1000;
        im  = DominantService.pilimread(self.url)
        img = CV2Service.cv2imread(self.url)
        median = cv2.medianBlur(img,5)
        #blur = cv2.bilateralFilter(median,9,75,75)
        img = cv2.bilateralFilter(median,10,100,100)
#        plt.imshow(img)
#        plt.show()
        img_correct = np.copy(img)
        x = DominantService.getColors(im)
        thresh = 38
        num_max = 0
        percentage = 0.08
        s = DominantService.size_img(img)
        model2, img1, colorC1, x, num_max, color1 = ColorAllService.color1(x, img, thresh)
        flag_havingColor[0] = Color3Service.havingColor(model2, flag_havingColor[0], num_haveingColor)
        if flag_havingColor[0] == 0:
            print('wow')
            number  = 1
            #colorCen = ColorCenter.colorCent(model2, img_correct, 1)
            #model1= Color2Service.reshaping(model2)
            model1, number, colorCen, s = ColorAllService.afterFindingColor1(model2, img_correct, 1, colorC1, self.flag, thresh, percentage)
            serialized_data = json.dumps({"colors": colorCen[0:number+1].tolist(), "model_1d": model1.tolist(), "shape":s.tolist(), "number":number })
            socket.write_message(serialized_data)
            return
        #print("part 1 is finished",sum(model2[model2==1]))
        colors12, model3, x1, num_max = ColorAllService.color2(model2, img1, thresh, self.flag, num_max, x, color1, flag_havingColor[0])
        flag_havingColor[1] = Color3Service.havingColor(model3, flag_havingColor[0], num_haveingColor)
        if flag_havingColor[1] == 0 and flag_havingColor[0] == 1:
            print('wow')
            number  = 2
            #colorCen = ColorCenter.colorCent(model3, img_correct, 2)
            #model1= Color2Service.reshaping(model3)
            model1, number, colorCen, s = ColorAllService.afterFindingColor1(model2, img_correct, 1, colors12, self.flag, thresh, percentage)
            serialized_data = json.dumps({"colors": colorCen[0:number+1].tolist(), "model_1d": model1.tolist(), "shape":s.tolist(), "number":number })
            socket.write_message(serialized_data)
            return
        #print("part 2 is finished",sum(model3[model3==2]))
        colors123, model4 = ColorAllService.color3(model3, img, self.flag, num_max, thresh, x, x1, colors12, flag_havingColor[1])
        flag_havingColor[2] = Color3Service.havingColor(model4, flag_havingColor[1], num_haveingColor)
        if flag_havingColor[2] == 0 and  flag_havingColor[1] == 1:
            print('wow')
            number  = 3
            #colorCen = ColorCenter.colorCent(model4, img_correct, 3)
            #model1= Color2Service.reshaping(model4)
            model1, number, colorCen, s = ColorAllService.afterFindingColor1(model2, img_correct, 1, colors123, self.flag, thresh, percentage)
            serialized_data = json.dumps({"colors": colorCen[0:number+1].tolist(), "model_1d": model1.tolist(), "shape":s.tolist(), "number":number })
            socket.write_message(serialized_data)
            return
        #print("part 3 is finished",sum(model4[model4==3]))
        modelN = model4
        colorsall = colors123
        #print(colorsall)
        for i in range(4,5):
            modelN, colorsall = ColorAllService.otherColors(img, colorsall, self.flag, num_max, thresh, modelN, flag_havingColor[i-2],i+1)
            #print(colorsall)
            flag_havingColor[i-1] = Color3Service.havingColor(modelN, flag_havingColor[i-2], num_haveingColor)
           # print("part  is finished",sum(modelN[modelN==i]))
            if (flag_havingColor[i-1] == 0 and  flag_havingColor[i-2] == 1)or i ==4:
                print('wow',i)
                model1, number, colorCen, s = ColorAllService.afterFindingColor1(modelN, img_correct, i, colorsall, self.flag, thresh, percentage)
                #model1, number, colorCen, s = ColorAllService.afterFindingColor(Color2Service.unreshaping(model1,img_correct), img_correct, number, colorCen, self.flag, thresh)
                #number  = i
                serialized_data = json.dumps({"colors": colorCen[0:number+1].tolist(), "model_1d": model1.tolist(), "shape":s.tolist(), "number":number })
                socket.write_message(serialized_data)
                return
                break
            
#            number = 6
        print('finish')
Exemplo n.º 9
0
    def start_clustering(self, socket):
        start = time.time()
        num_flg = 6
        im = DominantService.pilimread(self.url)
        img = CV2Service.cv2imread(self.url)
        img_correct = np.copy(img)
        x = DominantService.getColors(im)
        thresh = 35
        num_max = 0
        if self.flag < 1:
            print('hi')
            model2, img1 = DominantService.RGB(x, img, thresh)
            #colorC1 = np.copy(x)
        else:
            print('bye')
            model2, img1, colorC1, x, num_max, color1 = DominantService.HSV(
                x, img, thresh)
        print("part 1 is finished")
        #        if sum(model2[model2==0]) < 10:
        #            num_flg= num_flg -1
        new_im, img1 = Color2Service.modeling2color(model2, img1)
        color2, x1, num_max = Color2Service.color2get(new_im, thresh, x,
                                                      self.flag, num_max)
        #color_centre1 = Color2Service.mergeColor(color_centre1, color12)
        model3 = Color2Service.finalModel(thresh, color2, img1, model2,
                                          self.flag, 3)
        colors12 = Color2Service.colorConcat(color2, color1)
        print("part 2 is finished")
        #        if sum(model3[model3==0]) < 10:
        #            num_flg= num_flg -1
        new_im, img1 = Color2Service.modeling2color(model3, img)
        color3 = Color3Service.color3get(new_im, thresh, x, x1, self.flag,
                                         num_max)
        model4 = Color2Service.finalModel(thresh, color3, img1, model3,
                                          self.flag, 4)
        colors123 = Color3Service.colorConcat(color3, colors12)
        print("part 3 is finished")
        #        if sum(model4[model4==0]) < 10:
        #            num_flg= num_flg -1
        ##################################################################################
        new_im, img1 = Color2Service.modeling2color(model4, img)
        color4 = Color3Service.color4get(new_im, thresh + 10, colors123,
                                         self.flag, num_max)
        model5 = Color2Service.finalModel(thresh + 10, color4, img1, model4,
                                          self.flag, 5)
        colors1234 = Color3Service.colorConcat(color4, colors123)
        print("part 4 is finished")
        #        if sum(model5[model5==0]) < 10:
        #            num_flg= num_flg -1
        new_im, img1 = Color2Service.modeling2color(model5, img)
        color5 = Color3Service.color4get(new_im, thresh + 20, colors1234,
                                         self.flag, num_max)
        model6 = Color2Service.finalModel(thresh + 20, color5, img1, model5,
                                          self.flag, 6)
        colors12345 = Color3Service.colorConcat(color5, colors1234)
        print("part 5 is finished")
        #        if sum(model6[model6==0]) < 10:
        #            num_flg= num_flg -1
        new_im, img1 = Color2Service.modeling2color(model6, img)
        print("6-1 finised")
        color6 = Color3Service.color4get(new_im, thresh + 20, colors12345,
                                         self.flag, num_max)
        print("6-2 finised")
        model6 = Color2Service.finalModel(thresh + 20, color6, img1, model6,
                                          self.flag, 7)
        print("6-3 finised")
        #        model6 = ImageAlter.enhancing(model6, 7)
        colors123456 = Color3Service.colorConcat(color6, colors12345)
        print("part 6 is finished", num_flg)
        colorCen = ColorCenter.colorCent(model6, img_correct, num_flg)
        print(np.shape(model6))
        print(np.shape(img_correct))
        print('shapes')
        model_new = Color2Service.reshaping(model6)
        s = DominantService.size_img(img)
        colors = colors123456

        ############
        num = num_flg + 1
        admat = FinalMerge.adMat(num, colorCen, thresh, self.flag)
        print(admat)
        model66, number1 = FinalMerge.mergeColor(model_new, num, admat)
        print(np.size(model2))
        number, model1 = FinalMerge.modelEnhance(model66, number1)

        print("Merge part")
        end = time.time()
        print(end - start)
        ###################################################

        #        model1 = model_new
        #        number =6
        #################################################
        serialized_data = json.dumps({
            "colors": colorCen[0:number + 1].tolist(),
            "model_1d": model1.tolist(),
            "shape": s.tolist(),
            "number": number
        })
        socket.write_message(serialized_data)