OpenCV Images are held in the Mat data structure. The IplImage data structure is deprecated. OpenCV offers support for the image formats Windows bitmap (bmp), portable image formats (pbm, pgm, ppm) and Sun raster (sr, ras). With help of plugins you may also load image formats like JPEG (jpeg, jpg, jpe), JPEG 2000 (jp2), TIFF files (tiff, tif) and portable network graphics (png).
OpenCV Load Image C++
To load and display an image using OpenCV:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
// OpenCV Load and display image, https://talkera.org/opencv
#include
#include
#include
using namespace cv;
int main( int argc, char** argv )
{
char* imageName = argv[1];
Mat image;
image = imread( imageName, 1 );
if( argc != 2 || !image.data )
{
printf( " No image data \n " );
return -1;
}
namedWindow( imageName, CV_WINDOW_AUTOSIZE );
imshow( imageName, image );
waitKey(0);
return 0;
}
|
Compilation:
1
2
|
g++ -w image.cpp -o image -fpermissive `pkg-config --libs opencv`
./image cat.jpg
|
Output:
OpenCV Window
OpenCV Load Image Python
1
2
3
4
5
6
7
8
9
|
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('cat.jpg')
cv2.imshow('OpenCV Load Image ', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
|