Пример #1
0
 def otherColors(img, colors123, flag, num_max, thresh, model4,
                 flag_havingColor, iteration):
     if flag_havingColor == 1:
         new_im, img1 = Color2Service.modeling2color(model4, img)
         color4 = Color3Service.color4get(new_im, thresh + 10, colors123,
                                          flag, num_max)
         model5 = Color2Service.finalModel(thresh + 10, color4, img1,
                                           model4, flag, iteration)
         colors1234 = Color3Service.colorConcat(color4, colors123)
         return model5, colors1234
     else:
         print('oh no')
         return 1, 1
Пример #2
0
 def color3(model3, img, flag, num_max, thresh, x, x1, colors12,
            flag_havingColor):
     if flag_havingColor == 1:
         new_im, img1 = Color2Service.modeling2color(model3, img)
         color3 = Color3Service.color3get(new_im, thresh, x, x1, flag,
                                          num_max)
         model4 = Color2Service.finalModel(thresh, color3, img1, model3,
                                           flag, 4)
         colors123 = Color3Service.colorConcat(color3, colors12)
         return colors123, model4
     else:
         print('oh no')
         return 1, 1
Пример #3
0
 def color2(model2, img1, thresh, flag, num_max, x, color1,
            flag_havingColor):
     if flag_havingColor == 1:
         new_im, img1 = Color2Service.modeling2color(model2, img1)
         color2, x1, num_max = Color2Service.color2get(
             new_im, thresh, x, flag, num_max)
         #color_centre1 = Color2Service.mergeColor(color_centre1, color12)
         model3 = Color2Service.finalModel(thresh, color2, img1, model2,
                                           flag, 3)
         colors12 = Color2Service.colorConcat(color2, color1)
         return colors12, model3, x1, num_max
     else:
         print('oh no')
         return 1, 1, 1, 1
Пример #4
0
 def afterFindingColor1(model6, img_correct, num_flg, colors123456, flag,
                        thresh, percentage):
     print(model6)
     colorCen = ColorCenter.colorCent(model6, img_correct, num_flg)
     model_new = Color2Service.reshaping(model6)
     s = DominantService.size_img(img_correct)
     #colors =colors123456
     num = num_flg + 1
     admat = FinalMerge.adMat(num, colorCen, thresh, flag)
     print(admat)
     print("num", num)
     model66, number1 = FinalMerge.mergeColor(model_new, num, admat)
     print("number1", number1)
     number, model1 = FinalMerge.modelEnhance1(model66, number1, percentage)
     print("number", number)
     return model1, number, colorCen, s
Пример #5
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)
Пример #6
0
# -*- coding: utf-8 -*-
import numpy as np
from services.customRug.image_service import ImageAlter
import colorgram
from PIL import Image
from services.customRug.dominant_service import DominantService
from services.customRug.color2_service import Color2Service



    
    
model_new1 = Color2Service.unreshaping(model1, img1)
new_im1, img11 =  Color2Service.modeling23color(model_new1, img1)
color_centre11 = Color2Service.colorfindergram(new_im1, thresh)
color121 = Color2Service.color2get(new_im1, thresh)
color_centre11 = Color2Service.mergeColor(color_centre11, color121)
model31 = Color2Service.finalModel(thresh,color_centre11, img1, model_new1, flag1, 6)
model_new2 = Color2Service.reshaping(model31)
num =number + 2
colors1 = FinalMerge.colorConcat(colors, color_centre11)
admat = FinalMerge.adMat(num, colors1, thresh, flag1)
print(admat)
model22, number1 = FinalMerge.mergeColor(model_new2, num, admat)
print(np.size(model2))
number, model1=FinalMerge.modelEnhance(model22, num)
Пример #7
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)