As you know, GDAL is added to OpenCV version 3. I have a satellite ecw image and want to read and show it. I already try to use OpenCV sample named : gdal-image.cpp. it has a line for reading input image:
cv::Mat image = cv::imread(argv[1], cv::IMREAD_LOAD_GDAL | cv::IMREAD_COLOR );
my problem : I set my ecw image as argv[1] but it doesnt work. should I convert my image before? any way to read ecw using GDAL?
For read ecw image, i suggest you use GDAL, you can download GDAL binary prebuild and ECW extension from here https://www.gisinternals.com/release.php.
For read the first band of image you can use this code:
GDALDataset* dataset = (GDALDataset*) GDALOpenEx("image.ecw", GDAL_OF_RASTER, NULL, NULL, NULL);
GDALRasterBand* band = dataset->GetRasterBand(1);
cv::Rect roi(x, y, w, h);
cv::Mat mat;
mat.create(roi.size(),CV_32F);
band->RasterIO( GF_Read, roi.x, roi.y, roi.width, roi.height, mat.data,
roi.width, roi.height, GDT_Float32, 0, 0);
You just have to be sure that OpenCV data type match the GDAL datatype and that ROI dimensions are ok for the raster size. For more info it is good: enter link description here