コード例 #1
0
ファイル: kamera.py プロジェクト: myld1/RoboCup18-19
def cal():
    tres = [0, 0, 0, 0, 0, 0]

    tres[0] = image.rgb_to_lab(img.get_pixel(177, 192))[0]
    tres[1] = image.rgb_to_lab(img.get_pixel(177, 192))[0]
    tres[2] = image.rgb_to_lab(img.get_pixel(177, 192))[1]
    tres[3] = image.rgb_to_lab(img.get_pixel(177, 192))[1]
    tres[4] = image.rgb_to_lab(img.get_pixel(177, 192))[2]
    tres[5] = image.rgb_to_lab(img.get_pixel(177, 192))[2]
    nub = tres

    for x in range(140, 215, 4):
        for y in range(150, 192, 4):
            for i in range(6):
                if i % 2:
                    if image.rgb_to_lab(img.get_pixel(x, y))[i // 2] > tres[i]:
                        tres[i] = image.rgb_to_lab(img.get_pixel(x, y))[i // 2]
                else:
                    if image.rgb_to_lab(img.get_pixel(x, y))[i // 2] < tres[i]:
                        tres[i] = image.rgb_to_lab(img.get_pixel(x, y))[i // 2]
    for i in range(6):
        tres[i] = (tres[i] + 3 * nub[i]) // 4

    print(tres)
    return tres
コード例 #2
0
def unittest(data_path, temp_path):
    import image
    lab = image.rgb_to_lab((120, 200, 120))
    return (lab[0] == 76 and lab[1] == -44 and lab[2] == 34)
コード例 #3
0
def unittest(data_path, temp_path):
    import image
    lab = image.rgb_to_lab((120, 200, 120))
    return  (lab[0] == 76 and lab[1] == -44 and lab[2] == 34)
コード例 #4
0
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.CIF)
sensor.skip_frames(time=2000)
sensor.set_auto_gain(False)  # must be turned off for color tracking
sensor.set_auto_whitebal(False)  # must be turned off for color tracking
clock = time.clock()

img = sensor.snapshot()
img.draw_circle(177, 144, 75)
img.draw_rectangle(123, 91, 106, 106)

img = sensor.snapshot()

tres[0] = image.rgb_to_lab(img.get_pixel(177, 144))[0]
tres[1] = image.rgb_to_lab(img.get_pixel(177, 144))[0]
tres[2] = image.rgb_to_lab(img.get_pixel(177, 144))[1]
tres[3] = image.rgb_to_lab(img.get_pixel(177, 144))[1]
tres[4] = image.rgb_to_lab(img.get_pixel(177, 144))[2]
tres[5] = image.rgb_to_lab(img.get_pixel(177, 144))[2]

#for blob in img.find_blobs(color, pixels_threshold=100, area_threshold=100, merge=True):

for x in range(123, 229, 4):
    for y in range(91, 197, 4):
        for i in range(6):
            if i % 2:
                if image.rgb_to_lab(img.get_pixel(x, y))[i // 2] > tres[i]:
                    tres[i] = image.rgb_to_lab(img.get_pixel(x, y))[i // 2]
            else:
コード例 #5
0
    def detect(self, img):
        self.blobs = self._detect(img)
        self.result = []
        self.check_success = []

        res = []

        if (self.roundness_th != -1):
            res = self._filter_by_roundness(self.blobs, self.roundness_th)

        else:
            res = self.blobs

        #print ("interm res ", res)

        if (self.heigh_width_ratio_low_th != -1
                or self.heigh_width_ratio_high_th != -1):
            self.blobs = []

            for blob in res:
                height_width_ratio = float(blob.h()) / blob.w()
                #print ("heiw rat ", height_width_ratio)

                if (self.heigh_width_ratio_low_th != -1
                        and self.heigh_width_ratio_high_th != -1):
                    if (height_width_ratio > self.heigh_width_ratio_low_th
                            and height_width_ratio <
                            self.heigh_width_ratio_high_th):
                        self.blobs.append(blob)

                elif (self.heigh_width_ratio_low_th != -1):
                    if (height_width_ratio > self.heigh_width_ratio_low_th):
                        self.blobs.append(blob)

                elif (self.heigh_width_ratio_high_th != -1):
                    if (height_width_ratio < self.heigh_width_ratio_high_th):
                        self.blobs.append(blob)

        else:
            self.blobs = []
            self.blobs = res

        #get candidates
        unchecked_result = self.get_k_first_sorted(self.blobs,
                                                   self.sorting_func,
                                                   self.objects_num)

        if (self.rad_coeff < 0 and len(unchecked_result) != 0):
            self.sector_rad = -blob_width(unchecked_result[0]) * self.rad_coeff
            self._generate_encl_points()

        #get averaged surroundings for each

        for res in unchecked_result:
            bbox = res.rect()
            x = int(bbox[0] + bbox[2] / 2)
            y = int(bbox[1] + bbox[3])

            proper = 0

            curr_step_success = []

            for pt in self.sector_points:
                pixels = []

                for i in range(x + pt[0] - self.wind_sz // 2,
                               x + pt[0] + self.wind_sz // 2 + 1):
                    for j in range(y + pt[1] - self.wind_sz // 2,
                                   y + pt[1] + self.wind_sz // 2 + 1):
                        pix = img.get_pixel(x + pt[0] + i, y + pt[1] + j)
                        if (pix is not None):
                            pix_lab = image.rgb_to_lab(pix)
                            pixels.append(pix_lab)

                if (len(pixels) > 0):
                    #print ("sas", pixels)

                    r = 0  #sum (pixels [:] [0]) / len (pixels)
                    g = 0  #sum (pixels [:] [1]) / len (pixels)
                    b = 0  #sum (pixels [:] [2]) / len (pixels)

                    for pix in pixels:
                        r += pix[0]
                        g += pix[1]
                        b += pix[2]

                    a = (r, g, b)

                    #a = image.rgb_to_lab(pix)
                    if (all(self.surr1_th[2 * i] < a[i] < self.surr1_th[2 * i +
                                                                        1]
                            for i in range(len(a) - 1))
                            or all(self.surr2_th[2 * i] < a[i] < self.surr2_th[
                                2 * i + 1] for i in range(len(a) - 1))):
                        proper += 1
                        curr_step_success.append(True)

                    else:
                        curr_step_success.append(False)
                else:
                    curr_step_success.append(True)
                    proper += 1

            self.check_success.append(curr_step_success)
            #self.succ_num.append (proper)

            #print (proper)

            if (proper >= self.points_num * self.corr_ratio):
                self.result.append(res)

        #self.result = unchecked_result

        return self.result