Esempio n. 1
0
def main():
    img = cv.LoadImage("latex/Pictures/IMG_7324.CR2.jpg")
    img = normalize_rgb(img, aggressive=0.005)
    mask, seqs, time = get_mask_with_contour(img, ret_cont=True, ret_img=True, with_init_mask=False, time_took=True)
    boxes, min_rects = get_skin_rectangles(seqs)
    draw_boxes(boxes, img)
    center = [(c[0],c[1]) for c,_,_ in min_rects]
    verticies = []
    for x,y,w,h in boxes:
        verticies+=[(x,y), (x+w,y),(x,y+h),(x+w,y+h)]

#    verticies = [(x+w/2, y+h/2) for x,y,w,h in boxes]

    polys = map(cv.BoxPoints, min_rects)
    cv.PolyLine(img, polys, True, cv.RGB(50,50,255), 2)

    sample_count = len(verticies)
    samples = cv.CreateMat(sample_count, 1, cv.CV_32FC2)
    clusters = cv.CreateMat(sample_count, 1, cv.CV_32SC1)
    [cv.Set1D(samples, i, verticies[i]) for i in range(sample_count)]
    cv.KMeans2(samples, 3, clusters,
                   (cv.CV_TERMCRIT_EPS + cv.CV_TERMCRIT_ITER, 10, 1.0))
    color = [cv.RGB(255,10,10),
             cv.RGB(255,255,10),
             cv.RGB(10,255,255),
             cv.RGB(255,10,255)]
    for i, xy in enumerate(verticies):
        cv.Circle(img, xy, 5, color[int(clusters[i,0])], thickness=-1)

#    np_centers = np.asarray(verticies)
#    result = cv.kmeans(verticies, 2, 0, 5, cv.CV_TERMCRIT_ITER)

    show_image(img)
Esempio n. 2
0
    def from_message(self, msg, alpha=0.0):
        """ Initialize the camera calibration from a CameraInfo message """

        self.size = (msg.width, msg.height)
        self.intrinsics = cv.CreateMat(3, 3, cv.CV_64FC1)
        self.distortion = cv.CreateMat(len(msg.D), 1, cv.CV_64FC1)
        self.R = cv.CreateMat(3, 3, cv.CV_64FC1)
        self.P = cv.CreateMat(3, 4, cv.CV_64FC1)
        for i in range(len(msg.D)):
            self.distortion[i, 0] = msg.D[i]
        for i in range(9):
            cv.Set1D(self.intrinsics, i, msg.K[i])
        for i in range(9):
            cv.Set1D(self.R, i, msg.R[i])
        for i in range(12):
            cv.Set1D(self.P, i, msg.P[i])

        self.mapx = cv.CreateImage(self.size, cv.IPL_DEPTH_32F, 1)
        self.mapy = cv.CreateImage(self.size, cv.IPL_DEPTH_32F, 1)
        self.set_alpha(0.0)
Esempio n. 3
0
            gray_image, corners, (11, 11), (0, 0),
            (cv.CV_TERMCRIT_EPS + cv.CV_TERMCRIT_ITER, 30, 0.1))
        if (len(corners) > 1):
            cv.DrawChessboardCorners(image, board_size, corners, 1)
        if (len(corners) == board_total):
            cv.ShowImage("Snapshot", image)
            step = successes * board_total
            i = step
            for j in range(board_total):
                cv.Set2D(image_points, i, 0, corners[j][0])
                cv.Set2D(image_points, i, 1, corners[j][1])
                cv.Set2D(object_points, i, 0, float(j) / num_horizontal)
                cv.Set2D(object_points, i, 1, float(j % num_horizontal))
                cv.Set2D(object_points, i, 2, 0.0)
                i += 1
            cv.Set1D(point_counts, successes, board_total)
            successes += 1

    c = cv.WaitKey(15)
    if (c == ord('p')):
        c = 0
        while (c != ord('p') and c != 27):
            c = cv.WaitKey(250)
    image = cv.QueryFrame(cam)
    cv.ShowImage("Raw Video", image)

object_points2 = cv.CreateMat(successes * board_total, 3, cv.CV_32FC1)
image_points2 = cv.CreateMat(successes * board_total, 2, cv.CV_32FC1)
point_counts2 = cv.CreateMat(successes, 1, cv.CV_32SC1)

for i in range(successes * board_total):