def main(args=sys.argv[1:]):
    usage = "usage: %prog [options] <app name>"
    parser = eideticker.CaptureOptionParser(usage=usage,
                                            capture_area_option=False)
    parser.add_option("--no-capture",
                      action="store_true",
                      dest="no_capture",
                      help="run through the test, but don't actually "
                      "capture anything")
    parser.add_option("--capture-file",
                      action="store",
                      type="string",
                      dest="capture_file",
                      help="Existing capture to analyze instead of running "
                      "test")
    parser.add_option("--app-name",
                      action="store",
                      type="string",
                      dest="appname",
                      default="org.mozilla.fennec",
                      help="Specify an application name (android only)")
    parser.add_option("--output-file",
                      action="store",
                      type="string",
                      dest="output_file",
                      help="Output the results to file")
    parser.add_option("--output-screenshot",
                      action="store",
                      type="string",
                      dest="output_screenshot",
                      help="Output screenshot of a capture frame with capture "
                      "area overlayed")

    options, args = parser.parse_args()

    capture_file = options.capture_file
    if not capture_file:
        if not options.no_capture:
            capture_file = os.path.join(CAPTURE_DIR,
                                        "capture-test-%s.zip" % time.time())
            print "Capturing to file %s" % capture_file
        run_capture(options, capture_file)

    if options.no_capture:
        # we were just doing a test run through the steps here, we're done
        return

    print "Processing capture..."
    capture = videocapture.Capture(capture_file)

    result_queue = multiprocessing.Queue()

    def _get_biggest_framediff_square(result_queue, capture, framenum):
        imgarray = videocapture.get_framediff_imgarray(capture, framenum - 2,
                                                       framenum)
        biggest = square.get_biggest_square([255, 0, 0],
                                            imgarray,
                                            x_tolerance_min=100,
                                            x_tolerance_max=100,
                                            handle_multiple_scanlines=True)
        if biggest:
            result_queue.put(biggest)

    multiprocesses = []
    for (i, framenum) in enumerate(range(4, capture.num_frames)):
        p = multiprocessing.Process(target=_get_biggest_framediff_square,
                                    args=(result_queue, capture, framenum))
        p.start()
        multiprocesses.append(p)
        if len(multiprocesses) == 8:
            for p in multiprocesses:
                p.join()
            multiprocesses = []

    for p in multiprocesses:
        p.join()

    largest_square = None
    while not result_queue.empty():
        s = result_queue.get()
        if not largest_square or square.get_area(s) > square.get_area(
                largest_square):
            largest_square = s

    if largest_square is not None:
        print "Capture area: %s" % largest_square
        if options.output_file:
            with open(options.output_file, 'w+') as f:
                f.write('CAPTURE_AREA=%s\n' % largest_square)
        if options.output_screenshot:
            im = capture.get_frame_image(int(capture.length / 2))
            draw = ImageDraw.Draw(im)
            draw.rectangle(largest_square, outline=(255, 0, 0))
            im.save(options.output_screenshot)
    else:
        print "Couldn't find capture area"
def main(args=sys.argv[1:]):
    usage = "usage: %prog [options] <app name>"
    parser = eideticker.CaptureOptionParser(
        usage=usage, capture_area_option=False)
    parser.add_option("--no-capture", action="store_true",
                      dest="no_capture",
                      help="run through the test, but don't actually "
                      "capture anything")
    parser.add_option("--capture-file", action="store",
                      type="string", dest="capture_file",
                      help="Existing capture to analyze instead of running "
                      "test")
    parser.add_option("--app-name", action="store",
                      type="string", dest="appname",
                      default="org.mozilla.fennec",
                      help="Specify an application name (android only)")
    parser.add_option("--output-file", action="store",
                      type="string", dest="output_file",
                      help="Output the results to file")
    parser.add_option("--output-screenshot", action="store",
                      type="string", dest="output_screenshot",
                      help="Output screenshot of a capture frame with capture "
                      "area overlayed")

    options, args = parser.parse_args()

    capture_file = options.capture_file
    if not capture_file:
        if not options.no_capture:
            capture_file = os.path.join(CAPTURE_DIR, "capture-test-%s.zip" %
                                        time.time())
            print "Capturing to file %s" % capture_file
        run_capture(options, capture_file)

    if options.no_capture:
        # we were just doing a test run through the steps here, we're done
        return

    print "Processing capture..."
    capture = videocapture.Capture(capture_file)

    result_queue = multiprocessing.Queue()

    def _get_biggest_framediff_square(result_queue, capture, framenum):
        imgarray = videocapture.get_framediff_imgarray(capture, framenum - 2,
                                                       framenum)
        biggest = square.get_biggest_square([255, 0, 0],
                                            imgarray,
                                            x_tolerance_min=100,
                                            x_tolerance_max=100,
                                            handle_multiple_scanlines=True)
        if biggest:
            result_queue.put(biggest)

    multiprocesses = []
    for (i, framenum) in enumerate(range(4, capture.num_frames)):
        p = multiprocessing.Process(target=_get_biggest_framediff_square,
                                    args=(result_queue, capture, framenum))
        p.start()
        multiprocesses.append(p)
        if len(multiprocesses) == 8:
            for p in multiprocesses:
                p.join()
            multiprocesses = []

    for p in multiprocesses:
        p.join()

    largest_square = None
    while not result_queue.empty():
        s = result_queue.get()
        if not largest_square or square.get_area(s) > square.get_area(
                largest_square):
            largest_square = s

    if largest_square is not None:
        print "Capture area: %s" % largest_square
        if options.output_file:
            with open(options.output_file, 'w+') as f:
                f.write('CAPTURE_AREA=%s\n' % largest_square)
        if options.output_screenshot:
            im = capture.get_frame_image(int(capture.length / 2))
            draw = ImageDraw.Draw(im)
            draw.rectangle(largest_square, outline=(255, 0, 0))
            im.save(options.output_screenshot)
    else:
        print "Couldn't find capture area"
Beispiel #3
0
def main(args=sys.argv[1:]):
    usage = "usage: %prog [options] <app name>"
    parser = eideticker.CaptureOptionParser(usage=usage, capture_area_option=False)
    parser.add_option("--no-capture", action="store_true",
                      dest = "no_capture",
                      help = "run through the test, but don't actually "
                      "capture anything")
    parser.add_option("--capture-file", action="store",
                      type="string", dest="capture_file",
                      help="Existing capture to analyze instead of running test")
    parser.add_option("--app-name", action="store",
                      type="string", dest="appname",
                      default="org.mozilla.fennec",
                      help="Specify an application name (android only)")

    options, args = parser.parse_args()
    parser.validate_options(options)

    capture_file = options.capture_file
    if not capture_file:
        capture_file = os.path.join(CAPTURE_DIR, "capture-test-%s.zip" % time.time())
        print "Capturing to file %s" % capture_file
        run_capture(options, capture_file)

    if options.no_capture:
        # we were just doing a test run through the steps here, we're done
        return

    print "Processing capture..."
    capture = videocapture.Capture(capture_file)

    result_queue = multiprocessing.Queue()

    def _get_biggest_framediff_square(result_queue, capture, framenum):
        imgarray = videocapture.get_framediff_imgarray(capture, framenum-1, framenum,
                                                       threshold=8.0)
        biggest = square.get_biggest_square([255,0,0],
                                            imgarray,
                                            x_tolerance_min=100,
                                            x_tolerance_max=100,
                                            handle_multiple_scanlines=True)
        if biggest:
            result_queue.put(biggest)

    multiprocesses = []
    for (i, framenum) in enumerate(range(3, capture.num_frames)):
        p = multiprocessing.Process(target=_get_biggest_framediff_square, args=(result_queue, capture, framenum))
        p.start()
        multiprocesses.append(p)
        if len(multiprocesses) == 8:
            for p in multiprocesses:
                p.join()
            multiprocesses = []

    for p in multiprocesses:
        p.join()

    largest_square = None
    while not result_queue.empty():
        s = result_queue.get()
        if not largest_square or square.get_area(s) > square.get_area(largest_square):
            largest_square = s

    if largest_square is not None:
        print "Capture area: %s" % largest_square
    else:
        print "Couldn't find capture area"