pythonopencvcomputer-visioncameragenicam

Python Harvesters Image Acquisition GigeCam


I tried get image from my gige camera. In the camera's own software its working just fine, but when I do it with harvesters my image has a weird grid and I don't know why is it there and how to remove it. I need this for a stereovision project. Any idea? Don't mind the brightness I tried it with higher expo as well, it did not changed a thing. :D

enter image description here

import genicam.genapi as ge
import cv2
from harvesters.core import Harvester
import matplotlib.pyplot as plt
import numpy as np

# Create a Harvester object:
h = Harvester()

# Load a GenTL Producer; you can load many more if you want to:
h.add_file("C:/Program Files\MATRIX VISION/mvIMPACT             Acquire/bin/x64/mvGenTLProducer.cti")
# Enumerate the available devices that GenTL Producers can handle:
h.update()

# Select a target device and create an ImageAcquire object that
# controls the device:
ia = h.create(0)
ia2 = h.create(1)

# Configure the target device; it looks very small but this is just
# for demonstration:
ia.remote_device.node_map.Width.value = 1456
ia.remote_device.node_map.Height.value = 1088
# ia.remote_device.node_map.PixelFormat.symbolics
ia.remote_device.node_map.PixelFormat.value = 'BayerRG8'

ia2.remote_device.node_map.Width.value = 1456
ia2.remote_device.node_map.Height.value = 1088
# ia2.remote_device.node_map.PixelFormat.symbolics
ia2.remote_device.node_map.PixelFormat.value = 'BayerRG8'

ia.remote_device.node_map.ChunkSelector.value = 'ExposureTime'
ia.remote_device.node_map.ExposureTime.set_value(100000.0)

ia2.remote_device.node_map.ChunkSelector.value = 'ExposureTime'
ia2.remote_device.node_map.ExposureTime.set_value(100000.0)

# Allow the ImageAcquire object to start image acquisition:
ia.start()
ia2.start()
# We are going to fetch a buffer filled up with an image:
# Note that you'll have to queue the buffer back to the
# ImageAcquire object once you consumed the buffer; the
# with statement takes care of it on behalf of you:
while True:
    with ia.fetch() as buffer:
    component = buffer.payload.components[0]
    _2d = component.data.reshape(1088, 1456)
    img = _2d
    img = cv2.resize(img,(640,480))
    cv2.imshow('right',img)
    cv2.imwrite('test_left.png',img)
    cv2.waitKey(10)
with ia2.fetch() as buffer:
    component = buffer.payload.components[0]
    _2d = component.data.reshape(component.height, component.width)
    img2 = _2d
    img2 = cv2.resize(img2, (640, 480))
    cv2.imshow('left', img2)
    cv2.imwrite('test_right.png',img2)
    cv2.waitKey(10)

ia.stop()
ia2.stop()
ia.destroy()
ia2.destroy()
h.reset()

Solution

  • I just had to convert it to Gray or RGB with cvtColor, and its working. Thanks anyway.