1 | initial version |
Ok I finally got it working and of course, all I needed was the original GDAL Tutorial (http://www.gdal.org/gdal_tutorial.html) and some tweaking.
However, I will have to make a serious workaround to implement the opencv functionality in a regular qt window, because the highgui windows can't do what I need it to.
Here's the complete code fragment if anyone else ever needs it:
void mouseEvent(int evt, int x, int y, int flags, void* ptr)
{
cv::Point pt(x, y);
if (evt == CV_EVENT_LBUTTONDOWN)
{
Point*p = (Point*)ptr;
p->x = x;
p->y = y;
cout<<*p;
GDALAllRegister();
GDALDatasetH hDataset = GDALOpen( "C:/path/to/project/image.tif", GA_ReadOnly );
if( hDataset == NULL )
{
qDebug() << "data set is null";
}
GDALRasterBandH hBand;
int nBlockXSize, nBlockYSize;
int bGotMin, bGotMax;
double adfMinMax[2];
hBand = GDALGetRasterBand( hDataset, 1 );
GDALGetBlockSize( hBand, &nBlockXSize, &nBlockYSize );
adfMinMax[0] = GDALGetRasterMinimum( hBand, &bGotMin );
adfMinMax[1] = GDALGetRasterMaximum( hBand, &bGotMax );
if( ! (bGotMin && bGotMax) )
GDALComputeRasterMinMax( hBand, TRUE, adfMinMax );
float *pafScanline;
int nXSize = GDALGetRasterBandXSize( hBand );
pafScanline = (float *) CPLMalloc(sizeof(float)*nXSize);
GDALRasterIO( hBand, GF_Read, x, y, 1, 1,
pafScanline, nXSize, 1, GDT_Float32,
0, 0 );
qDebug() << x << y << pafScanline[0];
}
}