# Image capturing with CVB and GiGE camera

**URL:** <https://forum.commonvisionblox.com/t/image-capturing-with-cvb-and-gige-camera/1479>\
**Category:** Python API\
**Created:** [August 24, 2021, 6:52am UTC](https://forum.commonvisionblox.com/t/image-capturing-with-cvb-and-gige-camera/1479 "2021-08-24T06:52:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakia.aus](https://avatars.discourse-cdn.com/v4/letter/j/35a633/32.png) [@jakia.aus](https://forum.commonvisionblox.com/u/jakia.aus)\
**Post date:** [August 24, 2021, 6:52am UTC](https://forum.commonvisionblox.com/t/image-capturing-with-cvb-and-gige-camera/1479/1 "2021-08-24T06:52:30Z")

</div>

Hi,

I have JAI-FS-3200D camera (GigE version) and I want to save images from the camera using CVB.

I am using the following code:

````auto
    2 #
    3 # 1. Open the GenICam.vin driver.
    4 # 2. Acquire images.
    5 #
    6 # Requires: -
    7 
    8 import os
    9 import cvb
   10 
   11 with cvb.DeviceFactory.open(
   12 os.path.join(cvb.install_path(), "drivers", "CVMock.vin"),
   13 cvb.AcquisitionStack.Vin) as device:
   14     
   15 stream = device.stream()
   16 stream.start()
   17 
   18 for i in range(10):
   19 image, status = stream.wait()
   20 if status == cvb.WaitStatus.Ok:
   21 print("Acquired image: " + str(i) + " | Timestamp: " + str(image.raw_timestamp))
   22 
   23 stream.abort()```

But I cannot able to capture the images.

Can you please advise me how can I save or read the images using CVB with JAI-FS-3200D camera?

Thanks in advance.
````

---

<div class="post-metadata">

**Author:** ![usernv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/usernv/32/637_2.png) [@usernv](https://forum.commonvisionblox.com/u/usernv)\
**Post date:** [August 24, 2021, 7:18am UTC](https://forum.commonvisionblox.com/t/image-capturing-with-cvb-and-gige-camera/1479/2 "2021-08-24T07:18:35Z")

</div>

Hi jakia.aus,

Your posted code in itself should be working. If not please check your installation and post your error.

To use the actual camera, not the mock camera, either configure the camera in the GCBrowser by adding the device to the right side and saving the file. Then change the CVMock.vin to GenICam.vin and the camera should load.

Or you can discover the device and open it directly (see e.g. %CVB%Tutorial\Image Manager\CVBpy\DiscoverDevices\discover\_devices.py). By discovering you search for all available devices on the network or USB bus. You can then search each access\_token in the discovery list (of found devices) for a phrase, most useful would be the name of the device, and open the device by access\_token.

I hope that helps! 🙂

---

<div class="post-metadata">

**Author:** ![jakia.aus](https://avatars.discourse-cdn.com/v4/letter/j/35a633/32.png) [@jakia.aus](https://forum.commonvisionblox.com/u/jakia.aus)\
**Post date:** [August 24, 2021, 1:18pm UTC](https://forum.commonvisionblox.com/t/image-capturing-with-cvb-and-gige-camera/1479/3 "2021-08-24T13:18:16Z")

</div>

@usernv Thank you for your reply.

```auto
import os
import cvb
 
with cvb.DeviceFactory.open(
        os.path.join(cvb.install_path(), "drivers", "CVMock.vin"),
        #os.path.join(cvb.install_path(), "drivers", "GenIcam.vin"),
        cvb.AcquisitionStack.Vin) as device:
     
    stream = device.stream()
    stream.start()

    for i in range(10):
        image, status = stream.wait()
        if status == cvb.WaitStatus.Ok:
            #print("Acquired image: " + str(i) + " | Timestamp: " + str(image.raw_timestamp))
 
 
 	    #src_image = cvb.Image(os.path.join(cvb.install_path(), "tutorial", "Clara.bmp"))
 
 	    #print("Loaded image size: " + str(src_image.width) + " x " + str(src_image.height))
 
            dst_image = image.map(image.bounds, cvb.Size2D(image.size.width * 2, image.size.height * 3))
 
            print("Mapped image size: " + str(dst_image.width) + " x " + str(dst_image.height))
 
            dst_image.save("test.png") 
 
 
 
    stream.abort()

```

The installation is ok.

When I use CVMock.vin it prints

Mapped image size: 1280 x 1440  
Mapped image size: 1280 x 1440  
Mapped image size: 1280 x 1440  
Mapped image size: 1280 x 1440  
Mapped image size: 1280 x 1440  
Mapped image size: 1280 x 1440  
Mapped image size: 1280 x 1440  
Mapped image size: 1280 x 1440  
Mapped image size: 1280 x 1440  
Mapped image size: 1280 x 1440  
But the image is not saved. However, when I changed CVMock.vin to GenICam.vin it gives the following error.

```auto
Traceback (most recent call last):
  File "test.py", line 4, in <module>
    with cvb.DeviceFactory.open(
RuntimeError: C-API call failed

```

---

<div class="post-metadata">

**Author:** ![usernv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/usernv/32/637_2.png) [@usernv](https://forum.commonvisionblox.com/u/usernv)\
**Post date:** [August 24, 2021, 1:39pm UTC](https://forum.commonvisionblox.com/t/image-capturing-with-cvb-and-gige-camera/1479/4 "2021-08-24T13:39:24Z")

</div>

You just need the image.save(“ImAgE.bmp”) call on the image you waited for. The rest from the image load and save tutorial emulates the camera by loading the image which you would normally get by sream.wait().

The GenICam.vin loads the device configured in the %CVBDATA%Drivers\GenICam.ini file. You can configure it using the GenICamBrowser:

 ![GenICamBrowser_setup_camera](https://canada1.discourse-cdn.com/flex027/uploads/commonvisionblox/original/1X/cc4e5e36ea7564e04eab9e554b773f26f0b3c1d0.png)

Please also checkout [https://help.commonvisionblox.com/NextGen/14.0/md\_theory\_of\_operation\_hardware\_\_gen\_i\_cam\_\_c\_v\_b\_\_user\_guide.html](https://help.commonvisionblox.com/NextGen/14.0/md_theory_of_operation_hardware __gen_i_cam__ c_v_b__user_guide.html), it is one of our better getting started sites 🙂

---

<div class="post-metadata">

**Author:** ![jakia.aus](https://avatars.discourse-cdn.com/v4/letter/j/35a633/32.png) [@jakia.aus](https://forum.commonvisionblox.com/u/jakia.aus)\
**Post date:** [August 24, 2021, 1:44pm UTC](https://forum.commonvisionblox.com/t/image-capturing-with-cvb-and-gige-camera/1479/5 "2021-08-24T13:44:32Z")

</div>

> [@usernv](#):
>
> t using the GenICamBrowser:

I want to run a script and save image. Now I can save 1 image with the below code:

```auto
 # CVBpy Example Script
 #
 # 1. Discover all devices.
 # 2. Load the first device found.
 # 3. Acquire images.
 #
 
import cvb
 
 
discover = cvb.DeviceFactory.discover_from_root()
 
mock_info = next((info for info in discover if "GenICam.vin" in info.access_token), None)
if mock_info is None:
    raise RuntimeError("unable to find GenICam.vin")
 
 
with cvb.DeviceFactory.open(
        mock_info.access_token, cvb.AcquisitionStack.Vin) as device:
     
    stream = device.stream()
    stream.start()
 
    for i in range(10):
        image, status = stream.wait(5000)
        #if status == cvb.WaitStatus.Ok:
            #print("Acquired image: " + str(i))
            
            
        dst_image = image.map(image.bounds, cvb.Size2D(image.size.width * 2, image.size.height * 3))
 
        print("Mapped image size: " + str(dst_image.width) + " x " + str(dst_image.height))
 
        dst_image.save("test.png") 
 
    stream.abort()

```

But another problem is coming. We have 2 streams in our camera. One is RGB and another one is IR. The code can save one image from IR stream. How can I get two stream together?

---

<div class="post-metadata">

**Author:** ![usernv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/usernv/32/637_2.png) [@usernv](https://forum.commonvisionblox.com/u/usernv)\
**Post date:** [August 25, 2021, 6:13am UTC](https://forum.commonvisionblox.com/t/image-capturing-with-cvb-and-gige-camera/1479/6 "2021-08-25T06:13:49Z")

</div>

I think you switched topic to:  
[https://forum.commonvisionblox.com/t/image-capturing-both-rgb-and-ir-with-cvb-and-gige-camera/1480/2](https://forum.commonvisionblox.com/t/image-capturing-both-rgb-and-ir-with-cvb-and-gige-camera/1480/2)  
So let’s continue the new issue there 🙂
