Stripes on image

Hello,

I’m trying to acquire some images using a DAHUA MV-A7500MG20E camera.
The issue I’m facing is that when I take an image, sometimes it has horizontal stripes (I uploaded an image for reference).
What am I doing wrong?

The code I’m using is this one:

import cv2
import cvb
import numpy as np

# Camera settings
CAMERA_EXPOSURE = 7000
if __name__ == '__main__':
    vin_device = cvb.DeviceFactory.open(cvb.install_path() + "/drivers/GenICam.vin")
    vin_device.stream.ring_buffer.change_count(1, 0)
    dev_node_map = vin_device.node_maps["Device"]
    exposure_node = dev_node_map["ExposureTime"]
    exposure_node.value = CAMERA_EXPOSURE
    stream = vin_device.stream
    stream.start()
    try:
        while True:
            trigger = input('Press o to acquire: ')
            if trigger == 'o':
                trigger = ''
                
                for ii in range(0, 2): # I use this method to empty the ring buffer
                    image, status = stream.wait()
                np_image = cvb.as_array(image, copy=False)
                cv2.imwrite('image_' + str(0) + '.png', np_image)
                if status == cvb.WaitStatus.Ok:
                    print("Acquired image " + " into buffer " + 
                    str(image.buffer_index) + ".")
                else:
                    raise RuntimeError("timeout during wait" 
                        if status == cvb.WaitStatus.Timeout else 
                            "acquisition aborted")
    except KeyboardInterrupt:
        pass
    
    finally:
        stream.try_abort()

Hi @pare,

please have a look at the tutorial StreamingSimple which comes with your full CVB installation. It can be found under %CVB%Tutorial\Image Manager\CVBpy\StreamingSimple.py

We highly recommend to have at least three buffers available for the ringbuffer. You only need to call stream.wait() once every time a new image is needed. If you only need to acquire an image once in a while, you could also use image, status = stream.get_snapshot() but without starting the stream. This will start the stream, aquire one image and stop the stream again.

To save the image, you can just use image.save( 'image_' + str(0) + '.png') which is part of CVB.

Regarding the striped image, please refer to our GEV setup guide for the recommended settings of your network card etc. https://help.commonvisionblox.com/NextGen/14.0/md_theory_of_operation_hardware__gen_i_cam__c_v_b__user_guide.html#gcug_chmtopic26
You can also check your camera setup using the GenICam browser which should help tweaking the camera configuration until the image is normal.Saving the configuration there will keep your changes and the camera will produce the same result when loaded in code e.g. using the StreamingSimple.py example.

I hope this helps! :slight_smile:

Best
Nico

1 Like

Thank you for your reply.

First of all I changed my code to just take one snapshot (I don’t need a continuous data stream).

Then I checked the link you suggested and I tried to setup new values for the MTU. Unfortunately when I try MTU values above 1500, my Rasperry giver back an error.

$ sudo ip link set eth0 mtu 8192
> Error: mtu greater than device maximum.

So I decided to lower the width and height of the image from 2448x2048 to 1748x1748 and now I obtain a better image, without frame loss or stripes.

Just one more thing: how can I change the width and height of the image provided by the device through python code?

Hi @pare,

normally you should be able to send the full image over the network but if changing the resolution works fine for you, you can change the resolution using the device node map:

device_node_map = device.node_maps['Device']
device_node_map['Std::Width'].value = 64

The same goes for the image height (Std::Height).

2 Likes

Thank you, it worked perfectly!
Where can I find all the device_node_map parameters that can be changed? I’d like to set the static IP from my python script.

1 Like

The parameters of your device nodemap consist of standard parameters (starting with Std:: ) and camera dependent parameters. I think the easiest way to check for them is to use the GenICam browser. Configure the cameras IP and open it. You can then:

  • Change the NodeMap by clicking the four bars in the top right corner --> Selected NodeMap (also set Max visibility to Guru)
  • Look through the sorted NodeMap parameters or use the search bar in the top right corner
  • When you highlight an individual node, you can see additional information on it like the data type, max min values and if it is writable/readable.

For setting the cameras IP address, maybe you can refer to this thread with an example in C++ and C# linked in it as well. Our Python Api wrapps the C++ Api and has the same or at least very similar naming to our other Apis. If you have any problems in adapting the code please let me know.

2 Likes

Thank you for the info about the nodemap parameters, it is exactly what I needed.

About the IP address, what topic are you referring to?

Sorry, I forgot to paste the links.
C++:
https://forum.commonvisionblox.com/t/how-to-set-a-the-ip-address-of-gev-camera-programmatically-in-cvb/274/5?u=usernv

C#:
https://forum.commonvisionblox.com/t/exception-during-discovery/318/8?u=usernv

2 Likes

Hi @usernv,

I noticed that the missing frames are related to a previous image (when they are not black stripes), so I decided to use 2 times the function image, status = stream.get_snapshot() and now the obtained image doesn’t seem to have any problem even using the full camera resolution (I had to switch to a different camera, A5501MG20E, that has a slightly higher resolution).

Can you help me to figure out why?

Hi @pare,

get_snapshot() should just return one new image. My explanation would be that the first image is not completely written into the buffer which can happen when the connection is faulty. The second attempt might work since the last trigger wasn’t too long ago and hence the camera internally reacts faster now.

1 Like

Hi pare. I think I’m having a similar issue. I’m getting horizontal stripes that I noticed belong to previous images. Is that what you mean here?

Hi @naguir3d

This is the same issue which “pare” had.
Optimizing the network settings like described here should. help:
https://help.commonvisionblox.com/NextGen/14.0/md_theory_of_operation_hardware__gen_i_cam__c_v_b__user_guide.html#gcug_chmtopic26