| layout | default |
|---|---|
| title | Basic Usage Example |
| description | Basic Mini-OpenCV usage example - loading, processing, and saving images. |
Complete walkthrough of loading an image, applying operations, and saving the result.
#include "gpu_image/gpu_image_processing.hpp"
#include <iostream>
using namespace gpu_image;
int main() {
// Step 1: Check CUDA availability
if (!isCudaAvailable()) {
std::cerr << "CUDA not available!" << std::endl;
return 1;
}
std::cout << "Using: " << getDeviceInfo() << std::endl;
// Step 2: Create processor
ImageProcessor processor;
// Step 3: Create test image
HostImage input = ImageUtils::createHostImage(512, 512, 3);
for (int y = 0; y < 512; ++y) {
for (int x = 0; x < 512; ++x) {
input.at(x, y, 0) = (x * 255) / 512; // R gradient
input.at(x, y, 1) = (y * 255) / 512; // G gradient
input.at(x, y, 2) = 128; // B constant
}
}
// Step 4: Upload to GPU
GpuImage gpu = processor.loadFromHost(input);
// Step 5: Apply operations
GpuImage blurred = processor.gaussianBlur(gpu, 5, 1.5f);
GpuImage edges = processor.sobelEdgeDetection(blurred);
// Step 6: Download result
HostImage output = processor.downloadImage(edges);
// Step 7: Verify output
std::cout << "Output: " << output.width << "x" << output.height
<< "x" << output.channels << std::endl;
return 0;
}Always verify CUDA is available before processing.
ImageProcessor manages GPU resources and provides synchronous operations.
HostImage stores data in CPU RAM with convenient pixel accessors.
loadFromHost() copies data to GPU memory via PCIe.
Operations run on GPU and synchronize automatically.
downloadImage() copies results back to CPU memory.
# With CMake
target_link_libraries(my_app gpu_image::gpu_image_processing)
# Direct compilation
nvcc -std=c++17 example.cpp -I/path/to/mini-opencv/include \
-L/path/to/mini-opencv/build/lib -lgpu_image_processing -o example