Beispiel #1
0
def main():
    # print version
    print "nvcamera version: %s " % nvcamera.__version__

    oGraph = nvcamera.Graph()
    oGraph.setImager(0)
    oGraph.preview()
    oGraph.still()
    oGraph.video(1280, 720, "mpeg4", "/data/nvcs_try.3gp")
    oGraph.run()

    oCamera = nvcamera.Camera()

    oCamera.startPreview()
    oCamera.waitForEvent(12000, nvcamera.CamConst_FIRST_PREVIEW_FRAME)

    print "Start video recording..."
    oCamera.startVideoRecording()

    # record video for 5 seconds
    time.sleep(5)

    print "Stop video recording..."
    oCamera.stopVideoRecording()

    oCamera.stopPreview()
    oCamera.waitForEvent(12000, nvcamera.CamConst_PREVIEW_EOS)

    oGraph.stop()
    oGraph.close()
Beispiel #2
0
def main():
    # print version
    print "nvcamera version: %s " % nvcamera.__version__

    oGraph = nvcamera.Graph()

    oGraph.setImager(0)
    oGraph.preview()
    oGraph.still()
    oGraph.run()

    oCamera = nvcamera.Camera()

    # set focus to CAF
    oCamera.setAttr(nvcamera.attr_continuousautofocus, 1)

    oCamera.startPreview()
    oCamera.waitForEvent(12000, nvcamera.CamConst_FIRST_PREVIEW_FRAME)

    oCamera.halfpress(5000)
    oCamera.waitForEvent(12000, nvcamera.CamConst_ALGS)

    oCamera.still("/data/test.jpg")
    oCamera.waitForEvent(12000, nvcamera.CamConst_CAP_READY, nvcamera.CamConst_CAP_FILE_READY)

    oCamera.hp_release()
    oCamera.stopPreview()
    oCamera.waitForEvent(12000, nvcamera.CamConst_PREVIEW_EOS)

    oGraph.stop()
    oGraph.close()
def main():
    NUMBER_OF_ITERATION = 10

    # change filename to point to correct raw file
    filename = "/data/raw/IMG_20000223_224642.nvraw"

    header = None
    # ---- Read and load raw file ---- #
    nvrf = nvrawfile.NvRawFile()
    if nvrf.readFile(filename):
        header = nvrf.makeLegacyHeader()

        try:
            # print version
            print "nvcamera version: %s " % nvcamera.__version__

            # ---- create OpenMax graph ---- #
            oGraph = nvcamera.Graph()

            oGraph.setImager("host")
            oGraph.still(nvrf._width, nvrf._height)

            oGraph.run()

            # ---- Pass host images through ISP ---- #
            oCamera = nvcamera.Camera()

            # disable ANR until the last execution
            oCamera.setAttr(nvcamera.attr_anr, 0)

            for i in range(NUMBER_OF_ITERATION):
                # set the iso from raw file
                # set the exposure time from the raw file
                print "Setting the exposure time to: %f" % nvrf._exposureTime
                print "Setting the iso to: %d" % nvrf._iso

                oCamera.setAttr(nvcamera.attr_iso, nvrf._iso)
                oCamera.setAttr(nvcamera.attr_exposuretime, nvrf._exposureTime)

                if (i == NUMBER_OF_ITERATION - 1):
                    # enable ANR for the last iteration
                    oCamera.setAttr(nvcamera.attr_anr, 1)

                # pass the raw image header, data and iteration information
                oCamera.setRawImage(header, nvrf._pixelData, i)
                oCamera.still("/data/test_%d.jpg" % i)
                oCamera.waitForEvent(12000, nvcamera.CamConst_CAP_READY)

                # wait here for ALL_CAPTURE_DONE event
                oCamera.waitForEvent(12000, nvcamera.CamConst_ALL_CAPTURE_DONE)

        except Exception, err:
            traceback.print_exc()

        # ---- stop the camera graph ---- #
        oGraph.stop()
        oGraph.close()
Beispiel #4
0
def main():
    # print version
    print "nvcamera version: %s " % nvcamera.__version__

    oGraph = nvcamera.Graph()

    oGraph.setImager(0)
    oGraph.preview()
    oGraph.still()
    oGraph.run()

    oCamera = nvcamera.Camera()
    oCamera.setAttr(nvcamera.attr_concurrentrawdumpflag, 7)
    oCamera.setAttr(nvcamera.attr_pauseaftercapture, 1)

    # set 3A to Auto
    oCamera.setAttr(nvcamera.attr_whitebalance, "Auto")
    oCamera.setAttr(nvcamera.attr_exposuretime, -1)
    oCamera.setAttr(nvcamera.attr_continuousautofocus, 1)

    # create dirctory /data/raw because drive dumps
    # raw images in this directory
    if(not os.path.exists("/data/raw")):
        os.mkdir("/data/raw")

    oCamera.startPreview()
    oCamera.waitForEvent(12000, nvcamera.CamConst_FIRST_PREVIEW_FRAME)

    # set the flash mode to Auto, which will help assist the
    # halfpress to converge using flash and then do a strobe
    # during the capture
    oCamera.setAttr(nvcamera.attr_flashmode, "Auto")

    oCamera.halfpress(10000)
    oCamera.waitForEvent(12000, nvcamera.CamConst_ALGS)

    oCamera.still("/data/test.jpg")
    oCamera.waitForEvent(12000, nvcamera.CamConst_CAP_READY, nvcamera.CamConst_CAP_FILE_READY)

    oCamera.hp_release()
    oCamera.stopPreview()
    oCamera.waitForEvent(12000, nvcamera.CamConst_PREVIEW_EOS)

    oGraph.stop()
    oGraph.close()
def main():
    try:
        # print version
        print "nvcamera version: %s " % nvcamera.__version__

        oGraph = nvcamera.Graph()

        oGraph.setImager(0)
        oGraph.preview()
        oGraph.still()
        oGraph.run()

        oCamera = nvcamera.Camera()

        oCamera.setAttr(nvcamera.attr_exposuretime, 0.1)

        # set focus to CAF
        oCamera.setAttr(nvcamera.attr_continuousautofocus, 1)

        oCamera.startPreview()
        oCamera.waitForEvent(12000, nvcamera.CamConst_FIRST_PREVIEW_FRAME)

        oCamera.halfpress(10000)
        oCamera.waitForEvent(12000, nvcamera.CamConst_ALGS)

        oCamera.still("/data/test.jpg")
        oCamera.waitForEvent(12000, nvcamera.CamConst_CAP_READY,
                             nvcamera.CamConst_CAP_FILE_READY)

        oCamera.hp_release()
        oCamera.stopPreview()
        oCamera.waitForEvent(12000, nvcamera.CamConst_PREVIEW_EOS)

        oGraph.stop()
        oGraph.close()
    except Exception, err:
        traceback.print_exc()
        print "Error: %s" % err
 def __init__(self, obGraph):
     if(obGraph == None):
         raise ValueError("Graph is not open")
     self._obGraph = obGraph
     self._obCamera = nvcamera.Camera()
     self.logger = nvcstestutils.Logger()
def main():
    oGraph = None

    try:
        # parse arguments
        usage = "\nUsage: %prog <options>\n\nCaptures an image with AE, AWB, and AF defaulted to Automatic"
        parser = OptionParser(usage)

        parser.add_option(
            '-i',
            '--imager',
            dest='imager_id',
            default=0,
            type="int",
            metavar="IMAGER_ID",
            help='Sets Camera to be used for Captures                     \
                            Default = 0                                             \
                            0 = Rear Facing, 1 = Front Facing                       '
        )

        parser.add_option(
            '-f',
            '--focus',
            dest='focus',
            default=400,
            type="int",
            metavar="FOCUS",
            help='Sets the Focus Position                                 \
                            Default = 400                                           '
        )

        parser.add_option(
            '-g',
            '--gain',
            dest='gain',
            default=1.0,
            type="float",
            metavar="GAIN",
            help='Sets the amount of Digital Gain                         \
                            Default = 1.0                                           '
        )

        parser.add_option(
            '-e',
            '--exp',
            dest='exp_time',
            default=0.1,
            type="float",
            metavar="EXP_TIME",
            help='Sets the Exposure Time (in seconds)                     \
                            Default = 0.1                                           '
        )

        parser.add_option(
            '-p',
            '--preview',
            dest='preview',
            default=(0, 0),
            type="int",
            metavar="PREVIEW_RES",
            nargs=2,
            help='Sets the Image Preview Resolution                       \
                            Default = 0 0 [Maximum Supported Preview Resolution]  \
                            --preview=<width> <height>                              '
        )

        parser.add_option(
            '-w',
            '--preview_wait',
            dest='preview_wait',
            default=0,
            type="int",
            metavar="PREVIEW_WAIT",
            help='Sets the number of seconds to wait before capture       \
                            Default = 0                                             '
        )

        parser.add_option(
            '-s',
            '--still',
            dest='still',
            default=(0, 0),
            type="int",
            metavar="STILL_RES",
            nargs=2,
            help='Sets the Capture Resolution                             \
                            Default = 0 0 [Maximum Supported Capture Resolution]  \
                            --still=<width> <height>                                \
                            NOTE: Does not affect Raw Captures                      '
        )

        parser.add_option(
            '-n',
            '--name',
            dest='fname',
            default="nvcs_test",
            type="str",
            metavar="FILE_NAME",
            help='Sets the Name of the Output File                        \
                            Default = nvcs_test                                     '
        )

        parser.add_option(
            '-o',
            '--outdir',
            dest='output_dir',
            type="str",
            metavar="OUTPUT_DIR",
            default='/data/raw',
            help='Sets the Name of the Output Directory                   \
                            Default = /data/raw                                     '
        )

        parser.add_option(
            '-t',
            '--outputtype',
            dest='output_type',
            type="str",
            metavar="OUTPUT_TYPE",
            default='raw',
            help='Sets the Type of Output                                 \
                            Default = raw                                           \
                            Supported Types: raw, jpeg, concurrent                  '
        )

        parser.add_option(
            '-v',
            '--version',
            dest='version',
            action='store_true',
            metavar="VERSION",
            default=False,
            help='Prints NvCamera Module Version                          \
                            Default = False                                         '
        )

        # parse the command line arguments
        (options, args) = parser.parse_args()

        # print nvcamera module version
        if (options.version):
            print "nvcamera version: %s" % nvcamera.__version__
            return

        rawImageDir = "/data/raw"  # Unrelated to Output Directory Option
        outType = OUTTYPE_UNSPECIFIED

        # Determine Output Type
        if (options.output_type[0] == 'r'):  #RAW
            outType = OUTTYPE_RAW

        elif (options.output_type[0] == 'j'):  #JPEG
            outType = OUTTYPE_JPEG

        elif (options.output_type[0] == 'c'):  #CONCURRENT
            outType = OUTTYPE_CONCURRENT

            # Create Raw Dump Directory for Driver
            if not os.path.exists(rawImageDir):
                os.mkdir(options.output_dir)

        else:  #Unknown
            raise Exception("Unknown Capture Type")

        # create and run camera graph
        oGraph = nvcamera.Graph()
        oGraph.setImager(options.imager_id)

        # set preview resolution
        oGraph.preview(options.preview[0], options.preview[1])

        graphType = "Jpeg"
        if (outType == OUTTYPE_RAW):
            graphType = "Bayer"

        # set capture resolution
        oGraph.still(options.still[0], options.still[1], graphType)

        oGraph.run()

        oCamera = nvcamera.Camera()
        oCamera.setAttr(nvcamera.attr_pauseaftercapture, 1)

        # Create Output Directory
        if not os.path.exists(options.output_dir):
            os.mkdir(options.output_dir)

        # Start Camera and Wait until Ready
        oCamera.startPreview()
        oCamera.waitForEvent(12000, nvcamera.CamConst_FIRST_PREVIEW_FRAME)

        # Set Camera Attributes
        if (options.gain != -1):
            oCamera.setAttr(
                nvcamera.attr_bayergains,
                [options.gain, options.gain, options.gain, options.gain])
        oCamera.setAttr(nvcamera.attr_exposuretime, options.exp_time)

        hasFocuser = True
        try:
            physicalRange = oCamera.getAttr(
                nvcamera.attr_focuspositionphysicalrange)
        except nvcamera.NvCameraException, err:
            print("focuser is not supported")
            hasFocuser = False
        else:
Beispiel #8
0
def main():
    try:
        # parse arguments
        usage = "Usage: %prog <options>\nThe script captures image/video with AE, AWB and AF set to Auto by default."
        parser = OptionParser(usage)

        parser.add_option(
            '-c',
            '--imager',
            dest='imager_id',
            default=0,
            type="int",
            metavar="IMAGER_ID",
            help='select camera, 0 for rear facing, 1 for front facing')

        parser.add_option(
            '-p',
            '--preview',
            dest='preview',
            default=(-1, -1),
            type="int",
            metavar="PREVIEW_RES",
            nargs=2,
            help='set preview resolution (--preview=<width> <height>)\n\
                                     , default is maximum supported preview resolution'
        )

        parser.add_option(
            '-w',
            '--preview_wait',
            dest='preview_wait',
            default=0,
            type="int",
            metavar="PREVIEW_WAIT",
            help='number of seconds to wait after starting preview')

        parser.add_option(
            '-s',
            '--still',
            dest='still',
            default=(-1, -1),
            type="int",
            metavar="STILL_RES",
            nargs=2,
            help=
            'capture still image at specified resolution (--still=<width> <height>)'
        )

        parser.add_option('-i',
                          '--iso',
                          dest='iso',
                          default=-1,
                          type="int",
                          metavar="ISO",
                          help='set iso value, default is Auto')

        parser.add_option('-e',
                          '--exp',
                          dest='exp_time',
                          default=-1,
                          type="float",
                          metavar="EXP_TIME",
                          help='exposure time in seconds, default is Auto')

        parser.add_option('-g',
                          '--gain',
                          dest='gain',
                          default=-1,
                          type="float",
                          metavar="GAIN",
                          help='gain, default is Auto')

        parser.add_option('-f',
                          '--focus',
                          dest='focus',
                          default=-1,
                          type="int",
                          metavar="FOCUS",
                          help='focus position, , default is Auto')

        parser.add_option('-n',
                          '--name',
                          dest='fname',
                          default="nvcs_test",
                          type="str",
                          metavar="FILE_NAME",
                          help='name of the file, default is nvcs_test')

        parser.add_option('-r',
                          '--raw',
                          dest='concurrent_raw',
                          action='store_true',
                          metavar="CONCURRENT_RAW",
                          default=False,
                          help='captures concurrent raw image')

        parser.add_option(
            '--caf',
            dest='continuous_af',
            action='store_true',
            metavar="CONTINUOUS_AF",
            default=False,
            help='sets continuous auto focus mode, , default is False')

        parser.add_option(
            '-o',
            '--outdir',
            dest='output_dir',
            type="str",
            metavar="OUTPUT_DIR",
            default='/data/raw',
            help='sets output directory for the image(s), default is /data/raw'
        )

        parser.add_option(
            '--video',
            dest='video',
            default=(-1, -1),
            type="int",
            metavar="VIDEO_RES",
            nargs=2,
            help=
            'capture video at specified resolution (--video=<width> <height>)')

        parser.add_option('--video-enc',
                          dest='video_enc',
                          default="Mpeg4",
                          type="string",
                          metavar="VIDEO_ENC",
                          help='set video encoder, default is Mpeg4 encoder')

        parser.add_option(
            '--video-time',
            dest='video_time',
            default=5,
            type="int",
            metavar="VIDEO_TIME",
            help='set video recording time in seconds, default is 5 seconds')

        parser.add_option('-v',
                          '--version',
                          dest='version',
                          action='store_true',
                          metavar="VERSION",
                          default=False,
                          help='print nvcamera module version')

        # parse the command line arguments
        (options, args) = parser.parse_args()

        # print nvcamera module version
        if (options.version):
            print "nvcamera version: %s" % nvcamera.__version__
            return

        # create and run camera graph
        oGraph = nvcamera.Graph()

        oGraph.setImager(options.imager_id)

        # set to default resolutions unless user has specified
        if (options.preview[0] == -1):
            oGraph.preview()
        else:
            oGraph.preview(options.preview[0], options.preview[1])

        # set to default resolutions unless user has specified
        if (options.still[0] == -1):
            oGraph.still()
        else:
            oGraph.still(options.still[0], options.still[1])

        videoFileName = options.output_dir + "/" + options.fname + ".3gp"
        if (options.video[0] == -1):
            oGraph.video(640, 480, options.video_enc, videoFileName)
        else:
            oGraph.video(options.video[0], options.video[1], options.video_enc,
                         videoFileName)

        oGraph.run()

        oCamera = nvcamera.Camera()
        oCamera.setAttr(nvcamera.attr_pauseaftercapture, 1)

        rawImageDir = "/data/raw"
        if (options.concurrent_raw):
            oCamera.setAttr(nvcamera.attr_concurrentrawdumpflag, 7)

            # create dirctory /data/raw because drive dumps
            # raw images in this directory
            if (not os.path.exists(rawImageDir)):
                os.mkdir(rawImageDir)

        if (not os.path.exists(options.output_dir)):
            os.mkdir(options.output_dir)

        if (options.concurrent_raw):
            rawFilesList = os.listdir(rawImageDir)

        oCamera.startPreview()
        oCamera.waitForEvent(12000, nvcamera.CamConst_FIRST_PREVIEW_FRAME)

        # set the required attributes
        oCamera.setAttr(nvcamera.attr_iso, options.iso)
        if (options.gain != -1):
            oCamera.setAttr(
                nvcamera.attr_bayergains,
                [options.gain, options.gain, options.gain, options.gain])
        oCamera.setAttr(nvcamera.attr_exposuretime, options.exp_time)

        hasFocuser = True
        try:
            oCamera.setAttr(nvcamera.attr_focuspos, options.focus)
        except nvcamera.NvCameraException, err:
            if (err.value == nvcamera.NvError_NotSupported):
                hasFocuser = False
                if (options.focus != -1 or options.continuous_af):
                    raise OptionValueError(
                        "ERROR: Focuser is not supported..can't use -f, --focus or --caf"
                    )
                else:
                    pass
            else:
                raise

        if (options.continuous_af and hasFocuser):
            oCamera.setAttr(nvcamera.attr_continuousautofocus, 1)

        time.sleep(options.preview_wait)

        if (options.still[0] != -1):
            # ---- IMAGE CAPTURE START ---- #
            oCamera.halfpress(5000)
            oCamera.waitForEvent(12000, nvcamera.CamConst_ALGS)

            # capture an image
            jpegFileName = options.output_dir + "/" + options.fname + ".jpg"
            oCamera.still(jpegFileName)

            oCamera.waitForEvent(12000, nvcamera.CamConst_CAP_READY,
                                 nvcamera.CamConst_CAP_FILE_READY)

            oCamera.hp_release()
            # ---- IMAGE CAPTURE STOP ---- #

        if (options.video[0] != -1):
            # ---- VIDEO CAPTURE START ---- #
            oCamera.startVideoRecording()
            time.sleep(options.video_time)
            oCamera.stopVideoRecording()
            # ---- VIDEO CAPTURE STOP ---- #

        oCamera.stopPreview()
        oCamera.waitForEvent(12000, nvcamera.CamConst_PREVIEW_EOS)

        # stop and close the graph
        oGraph.stop()
        oGraph.close()

        newList = os.listdir(rawImageDir)
        if (options.concurrent_raw):
            for key in newList:
                if key not in rawFilesList:
                    if 'nvraw' in key:
                        os.rename(
                            os.path.join(rawImageDir, key),
                            os.path.join(options.output_dir,
                                         options.fname + ".nvraw"))
                        break
Beispiel #9
0
 def __init__(self):
     self.graph = nvcamera.Graph()
     self.camera = nvcamera.Camera()