コード例 #1
0
ファイル: camera.py プロジェクト: lauritk/blinky
    def grab_image(self):
        """Grab frame data and append timing values to output variale."""
        if genicam.IsReadable(self.grabResult.ChunkCounterValue):
            if genicam.IsReadable(self.grabResult.ChunkExposureTime):
                if genicam.IsReadable(self.grabResult.ChunkTimestamp):
                    if self.first_timestamp == 0:
                        self.first_timestamp = self.grabResult.ChunkTimestamp.Value
                    to_us = (self.grabResult.ChunkTimestamp.Value -
                             self.first_timestamp) / 1e3
                    self.data_out.append(
                        (self.grabResult.ChunkCounterValue.Value,
                         round(to_us,
                               2), self.grabResult.ChunkExposureTime.Value))
        # print(self.data_out)

        if self.grabResult.GrabSucceeded() and self.imageWindow.IsVisible():
            self.imageWindow.SetImage(self.grabResult)
            if self.parameters['record']:
                image = self.converter.Convert(self.grabResult)
                img = image.GetArray()
                # Skvideo write
                self.output.writeFrame(img)
                # OpenCV write
                # self.output.write(img)
        elif not self.imageWindow.IsVisible():
            self.camera.StopGrabbing()
        else:
            print("Error: ", self.grabResult.ErrorCode)
コード例 #2
0
def main():
    try:
        XMLFileName = "HelloWorld.xml"

        Camera = genicam.CNodeMapRef()
        Camera._LoadXMLFromFile(XMLFileName)

        theNode = Camera.GetNode("TheNode")
        print(type(theNode))

        theInt = Camera.GetNode("TheInt")
        print(type(theInt))

        nodes = Camera._GetNodes()
        for n in nodes:
            print(n.ToString())

        theFloat = Camera.GetNode("TheFloat")

        print(theNode.ToString())
        print(theInt.ToString())
        print(theInt.Node.GetPropertyNames())
        print(genicam.IsReadable(theNode))

        print(theFloat.GetIntAlias())
        print(theInt.GetFloatAlias())

        print(Camera.DeviceInfo)

        return 0
    except genicam.GenericException as e:
        print("Error ", e.GetDescription())

        return -1
コード例 #3
0
    def OnImageGrabbed(self, camera, grabResult):
        # The chunk data is attached to the grab result and can be accessed anywhere.

        # Native parameter access:
        # When using the device specific grab results the chunk data can be accessed
        # via the members of the grab result data.
        if genicam.IsReadable(grabResult.ChunkTimestamp):
            print("OnImageGrabbed: TimeStamp (Result) accessed via result member: ", grabResult.ChunkTimestamp.Value)
コード例 #4
0
    def test_grab_chunk_image(self):

        # Only look for usb cameras
        info = pylon.DeviceInfo()
        info.SetDeviceClass("BaslerUsb")

        # Create an instant camera object with the first found camera device that matches the specified device class.
        camera = pylon.InstantCamera(
            pylon.TlFactory.GetInstance().CreateFirstDevice(info))

        # Open the camera.
        camera.Open()

        camera.StaticChunkNodeMapPoolSize = camera.MaxNumBuffer.GetValue()

        if genicam.IsWritable(camera.ChunkModeActive):
            camera.ChunkModeActive = True
        else:
            self.fail()

        # Enable time stamp chunks.
        camera.ChunkSelector = "Timestamp"
        camera.ChunkEnable = True

        # Enable CRC checksum chunks.
        camera.ChunkSelector = "PayloadCRC16"
        camera.ChunkEnable = True

        camera.StartGrabbingMax(self.countOfImagesToGrab)

        while camera.IsGrabbing():

            # Wait for an image and then retrieve it. A timeout of 5000 ms is used.
            # RetrieveResult calls the image event handler's OnImageGrabbed method.
            grabResult = camera.RetrieveResult(
                5000, pylon.TimeoutHandling_ThrowException)

            # Check to see if a buffer containing chunk data has been received.
            if pylon.PayloadType_ChunkData != grabResult.PayloadType:
                self.fail()

            # Since we have activated the CRC Checksum feature, we can check
            # the integrity of the buffer first.
            # Note: Enabling the CRC Checksum feature is not a prerequisite for using
            # chunks. Chunks can also be handled when the CRC Checksum feature is deactivated.
            if grabResult.HasCRC() and grabResult.CheckCRC() == False:
                self.fail()

            if not genicam.IsReadable(grabResult.ChunkTimestamp):
                self.fail()

        camera.ChunkModeActive = False
コード例 #5
0
        # Check to see if a buffer containing chunk data has been received.
        if pylon.PayloadType_ChunkData != grabResult.PayloadType:
            raise pylon.RuntimeException("Unexpected payload type received.")

        # Since we have activated the CRC Checksum feature, we can check
        # the integrity of the buffer first.
        # Note: Enabling the CRC Checksum feature is not a prerequisite for using
        # chunks. Chunks can also be handled when the CRC Checksum feature is deactivated.
        if grabResult.HasCRC() and grabResult.CheckCRC() == False:
            raise pylon.RuntimeException("Image was damaged!")

        # Access the chunk data attached to the result.
        # Before accessing the chunk data, you should check to see
        # if the chunk is readable. When it is readable, the buffer
        # contains the requested chunk data.
        if genicam.IsReadable(grabResult.ChunkTimestamp):
            print("TimeStamp (Result): ", grabResult.ChunkTimestamp.Value)

        # USB camera devices provide generic counters. An explicit FrameCounter value is not provided by USB camera devices.
        if not camera.IsUsb():
            if genicam.IsReadable(grabResult.ChunkFramecounter):
                print("FrameCounter (Result): ", grabResult.ChunkFramecounter.Value)
        print()

    # Disable chunk mode.
    camera.ChunkModeActive = False
    camera.Close()

except genicam.GenericException as e:
    # Error handling.
    print("An exception occurred.", e.GetDescription())