Image Handling

This page shows how to handle images in a connected camera storage using RICOH Camera USB SDK.

Contents

The following classes are used when you manage images:

CameraImage

  • The CameraImage class represents image information and image data.
  • This class includes methods for obtaining image information and image data.

CameraImageList

  • The CameraImageList class represents a list of CameraImage.

CameraDevice

  • The CameraDevice class represents a camera device.
  • This class includes methods for obtaining camera information and operating camera device.

CameraStorage

  • The CameraStorage class represents a storage of camera device.

CameraStorageList

  • The CameraStorageList class represents a list of CameraStorage.

List Images

Use the getImages method of the CameraDevice class to obtain a list of images stored in the connected camera device.

for (size_t i = 0; i < camera->getStorages().size(); i++) {
    const auto& storage = camera->getStorages().get(i);
    std::cout << "[" << i << "]\n"
              << "  Storage Id: 0x"
              << std::hex << stoi(storage->getId()) << std::dec << std::endl;
    std::cout << "  StorageListImagesState: "
              << static_cast<int>(storage->getListImagesState()) << std::endl;
}
for (size_t i = 0; i < camera->getImages().size(); i++) {
    const auto& image = camera->getImages().get(i);
    std::cout << "  [" << i << "]"
              << " Storage ID: 0x" << std::hex
              << stoi(image->getStorage()->getId()) << std::dec
              << ", Name: " << image->getName()
              << ", Type: " << static_cast<int>(image->getType())
              << ", Format: " << static_cast<int>(image->getFormat())
              << ", Size: " << image->getSize()
              << ", ID: " << image->getId()
              << ", HasThumbnail: " << image->hasThumbnail()
              << ", Date: " << image->getDateTime() << std::endl;
}

The image list in camera storage is synchronized automatically in background process when the camera is connected and when the image list is updated. The image list returned by getImages is sorted in descending order of date and time. By using the getListImagesState method of the CameraStorage class, you can know acquisition status of the image list for each storage. Use the getStorages method of the CameraDevice class to obtain a list of storages in the connected camera device.

Note: The image list is synchronized automatically in background. Therefore, a loop index of the image list may change while looping through. To obtain a snapshot of the image list, use the clone method of CameraImageList class.

std::unique_ptr<const CameraImageList> images = cameraDevice->getImages().clone();

Obtain an Image

Use get method of CameraImageList class to obtain a single image. And you can obtain image data by using getData method of CameraImage class.

// Get the latest image
std::shared_ptr<const CameraImage> image = cameraDevice->getImages().get(0);
std::string filename = image->getName();
std::ofstream o;
o.open(filename, std::ofstream::out | std::ofstream::binary);

Response res = image->getData(o);

o.close();

std::cout << "Get Image is "
          << (res.getResult() == Result::Ok ? "SUCCEED." : "FAILED.")
          << std::endl;
if (res.getResult() == Result::Ok) {
    std::cout << "Image Path: " << filename << std::endl;
} else {
    for (const auto& error : res.getErrors()) {
        std::cout << "Error Code: " << static_cast<int>(error->getCode())
                  << " / Error Message: " << error->getMessage() << std::endl;
    }
}

Obtain Image Thumbnails

Use the getThumbnail method to obtain image thumbnails.

// Get the thumbnail of latest image
const std::shared_ptr<const CameraImage> image = cameraDevice->getImages().get(0);
std::string filename = "thumb_" + image->getName();
std::ofstream o;
o.open(filename, std::ofstream::out | std::ofstream::binary);

Response res = image->getThumbnail(o);

o.close();

std::cout << "Get Thumbnail Image is "
          << (res.getResult() == Result::Ok ? "SUCCEED." : "FAILED.")
          << std::endl;
if (res.getResult() == Result::Ok) {
    std::cout << "Image Path: " << filename << std::endl;
} else {
    for (const auto& error : res.getErrors()) {
        std::cout << "Error Code: " << static_cast<int>(error->getCode())
                  << " / Error Message: " << error->getMessage() << std::endl;
    }
}

Delete Images

Use the deleteData method to delete images in camera storage.

// Delete the latest image
const std::shared_ptr<const CameraImage> image = cameraDevice->getImages().get(0);
Response res = image->deleteData();

std::cout << "Delete Image(" << image->getName() << ") is "
          << (res.getResult() == Result::Ok ? "SUCCEED." : "FAILED.")
          << std::endl;