Skip to content
⚡ Developer documentation for INFINICAM, the real-time high-speed camera (UC-1.1 / GbE-2)

SingleImage + DC component extraction

This sample extracts only the DC components from INFINICAM’s compressed data to build an image scaled down to 1/8 in each direction. It takes far less time than decoding the whole image, and still gives you a rough picture of the whole scene. It also compares the time with decoding the whole image.

  1. Enter and save the program

    Save the following code as single_image_dc.py in C:\infinicam_projects\python.

    import time
    import cv2
    from pypuclib import CameraFactory, PUCException
    print("Connecting to the camera...")
    try:
    # Connect to the GbE-2 at this IP address
    cam = CameraFactory().create(ip="192.168.0.10")
    except PUCException as e:
    print("Error: could not connect to the camera.", e)
    raise SystemExit(1)
    try:
    reso = cam.resolution()
    print("Full size:", reso.width, "x", reso.height)
    # Receive the compressed data for one frame
    data = cam.grab()
    decoder = cam.decoder()
    # In the DC image, each 8 x 8 block of pixels becomes one pixel
    blocks_x = reso.width // 8 # Number of blocks across
    blocks_y = reso.height // 8 # Number of blocks down
    # Compare the time to decode the whole image with the time to extract only the DC components
    start = time.perf_counter()
    full_image = decoder.decode(data)
    full_ms = (time.perf_counter() - start) * 1000
    start = time.perf_counter()
    dc_image = decoder.decodeDC(data, 0, 0, blocks_x, blocks_y)
    dc_ms = (time.perf_counter() - start) * 1000
    finally:
    cam.close()
    print(f"Full decode: {full_ms:.2f} ms / DC extraction: {dc_ms:.2f} ms")
    filename = "dc_captured_image.png"
    cv2.imwrite(filename, dc_image)
    print(f"Saved: {filename} (size: {dc_image.shape[1]} x {dc_image.shape[0]})")
  2. Run it

    Run the following 2 lines, one at a time, in Command Prompt (or PowerShell).

    Terminal window
    cd C:\infinicam_projects\python
    Terminal window
    python single_image_dc.py

    If you see the following and a small 100 × 75 image dc_captured_image.png is created, it worked. The times depend on your PC.

    Connecting to the camera...
    Full size: 800 x 600
    Full decode: 1.25 ms / DC extraction: 0.18 ms
    Saved: dc_captured_image.png (size: 100 x 75)

INFINICAM compresses images in 8 × 8 pixel blocks. For each block, the compressed data holds a value representing “the brightness of the whole block”, called the DC component.

Lining up just the DC components gives an image scaled down to 1/8 in each direction, with one pixel per block (100 × 75 for 800 × 600). Fine patterns are lost, but you can still tell what is where.

dc_image = decoder.decodeDC(data, 0, 0, blocks_x, blocks_y)

The 4 numbers passed to decodeDC() are in blocks, not pixels.

Argument Meaning In this example
Second and third Block position to start from (horizontal, vertical) 0, 0 (from the top left)
Fourth and fifth Number of blocks to extract (horizontal, vertical) 100, 75 (the whole image)

DC components can be extracted without the detailed decoding calculations, so this takes much less time than decoding the whole image.

  • Display: show a lightweight scaled-down live view and leave the PC’s power for analysis
  • Rough detection: quickly find the approximate position of bright or moving objects in the whole image
  • Combined with ROI: find an object’s position with DC components first, then decode only the area around it in detail with ROI decoding