Exemple #1
0
    def new_dewarp(self):
        vidpath = self.iVidPath  #get input video path

        # isInROI is deprecated and not used in this program
        def isInROI(x, y, R1, R2, Cx, Cy):
            isInOuter = False
            isInInner = False
            xv = x - Cx
            yv = y - Cy
            rt = (xv * xv) + (yv * yv)
            if (rt < R2 * R2):
                isInOuter = True
                if (rt < R1 * R1):
                    isInInner = True
            return isInOuter and not isInInner

        """ ws = width of input video
            hs = height of input video
            wd = width of destination/output video
            Hd = height of destinaton/output video
          
        """

        def buildMap(Ws, Hs, Wd, Hd, R1, R2, Cx, Cy):
            #the function throws type error, if Wd and Hd are not converted to integers
            Hd = int(Hd)
            Wd = int(Wd)
            map_x = np.zeros((Hd, Wd), np.float32)
            map_y = np.zeros((Hd, Wd), np.float32)
            rMap = np.linspace(R1, R1 + (R2 - R1), Hd)
            thetaMap = np.linspace(0, 0 + float(Wd) * 2.0 * np.pi, Wd)
            sinMap = np.sin(thetaMap)
            cosMap = np.cos(thetaMap)

            for y in xrange(0, int(Hd - 1)):
                map_x[y] = Cx + rMap[y] * sinMap
                map_y[y] = Cy + rMap[y] * cosMap

            return map_x, map_y

        # do the unwarping
        def unwarp(img, xmap, ymap):
            output = cv2.remap(img.getNumpyCv2(), xmap, ymap, cv2.INTER_LINEAR)
            result = Image(output, cv2image=True)
            # return result
            return result

        disp = Display(
            (800, 600))  #initialise a 800x600 simplecv display to show preview
        #disp = Display((1296,972))
        vals = []
        last = (0, 0)
        # Load the video
        vc = VirtualCamera(vidpath, "video")
        # Sometimes there is crud at the begining, buffer it out
        for i in range(0, 10):
            img = vc.getImage()
            img.save(disp)
        # Show the user a frame let them left click the center
        #    of the "donut" and the right inner and outer edge
        # in that order. Press esc to exit the display
        while not disp.isDone():
            test = disp.leftButtonDownPosition()
            if test != last and test is not None:
                last = test
                print "[360fy]------- center = {0}\n".format(last)

                vals.append(test)
        print "[360fy]------- Dewarping video and generating frames using center, offset1, offset2\n"

        Cx = vals[0][0]
        Cy = vals[0][1]
        #print str(Cx) + " " + str(Cy)
        # Inner donut radius
        R1x = vals[1][0]
        R1y = vals[1][1]
        R1 = R1x - Cx
        #print str(R1)
        # outer donut radius
        R2x = vals[2][0]
        R2y = vals[2][1]
        R2 = R2x - Cx
        #print str(R2)
        # our input and output image siZes
        Wd = round(float(max(R1, R2)) * 2.0 * np.pi)
        #Wd = 2.0*((R2+R1)/2)*np.pi
        #Hd = (2.0*((R2+R1)/2)*np.pi) * (90/360)
        Hd = (R2 - R1)
        Ws = img.width
        Hs = img.height
        # build the pixel map, this could be sped up
        print "BUILDING MAP"

        xmap, ymap = buildMap(Ws, Hs, Wd, Hd, R1, R2, Cx, Cy)
        print "MAP DONE"

        result = unwarp(img, xmap, ymap)

        result.save(disp)

        print "[360fy]------- Storing frames into ../temp_data/frames\n"
        i = 0
        while img is not None:
            print bcolors.OKBLUE + "\rFrame Number: {0}".format(
                i) + bcolors.ENDC,

            sys.stdout.flush(
            )  #flushes stdout so that frame numbers print continually without skipping
            #print " percent complete         \r",
            result = unwarp(img, xmap, ymap)
            result.save(disp)
            # Save to file
            fname = "../temp_data/frames/FY{num:06d}.png".format(num=i)
            result.save(fname)

            img = vc.getImage()
            i = i + 1
        print " \n"

        if img is None:
            self.statusText.setText(str("Status: Done"))
            disp.quit()
Exemple #2
0

disp = Display((800, 600))
vals = []
last = (0, 0)
# Load the video from the rpi
vc = VirtualCamera("video.h264", "video")
# Sometimes there is crud at the begining, buffer it out
for i in range(0, 10):
    img = vc.getImage()
    img.save(disp)
# Show the user a frame let them left click the center
# of the "donut" and the right inner and outer edge
# in that order. Press esc to exit the display
while not disp.isDone():
    test = disp.leftButtonDownPosition()
    if (test != last and test is not None):
        last = test
        vals.append(test)

# 0 = xc yc
# 1 = r1
# 2 = r2
# center of the "donut"
Cx = vals[0][0]
Cy = vals[0][1]
# Inner donut radius
R1x = vals[1][0]
R1y = vals[1][1]
R1 = R1x - Cx
# outer donut radius
Exemple #3
0

disp = Display((800,600))
vals = []
last = (0,0)
# Load the video from the rpi
vc = VirtualCamera("video.h264","video")
# Sometimes there is crud at the begining, buffer it out
for i in range(0,10):
    img = vc.getImage()
    img.save(disp)
# Show the user a frame let them left click the center
# of the "donut" and the right inner and outer edge
# in that order. Press esc to exit the display
while not disp.isDone():
    test = disp.leftButtonDownPosition()
    if( test != last and test is not None):
        last = test
        vals.append(test)

# 0 = xc yc
# 1 = r1
# 2 = r2
# center of the "donut"    
Cx = vals[0][0]
Cy = vals[0][1]
# Inner donut radius
R1x = vals[1][0]
R1y = vals[1][1]
R1 = R1x-Cx
# outer donut radius
	print("Give (at least one) file name(s) of the images(s) to process")
	sys.exit()

disp = Display((1280,1024))
virtual_cam = VirtualCamera(sys.argv[1], "image")
img = virtual_cam.getImage()
img.save(disp)

points = []
last_pt = (0, 0)

# Show the first image, the user had to left click the center of the donut,
# followed by the right inner and outer edge (in that order). Press "Esc" to exit.
# All the images are processed with the same parameters
while not disp.isDone():
    temp_pt = disp.leftButtonDownPosition()
    if( temp_pt != last_pt and temp_pt is not None):
        last_pt = temp_pt
        points.append(temp_pt)

# Center of the donut 
Cx = points[0][0]
Cy = points[0][1]
# Inner donut radius
R1x = points[1][0]
R1y = points[1][1]
R1 = R1x-Cx
# Outer donut radius
R2x = points[2][0]
R2y = points[2][1]
R2 = R2x-Cx
Exemple #5
0
COLOR = Color.BLUE

# main loop #

while not disp.isDone():

    img = cam.getImage()
    img = img.flipHorizontal()  # just for my convenience - simulates mirror :)

    if inVideoMode:
        (orig_h, orig_w) = (img.height, img.width)  # required for VideoStream

    px = disp.mouseX
    py = disp.mouseY

    left_down = disp.leftButtonDownPosition()  # grab coordinates for event press
    left_up = disp.leftButtonUpPosition()  # grab coordinates for event release

    if left_down is not None:  # left mouse button pressed
        # start drawing rectangle
        (lx, ly) = left_down

    if left_up is not None:  # left mouse button released
        # stop drawing rectangle, go into zoom mode
        (lx, ly) = (None, None)
        inZoomMode = True if not inZoomMode else False  # enter zooming mode
        zoom = (sx, sy, w, h)

    if inZoomMode:

        img = img.crop(zoom[0], zoom[1], zoom[2], zoom[3])