Error loading cr2 with edsdk - c++

I am trying to read cr2 images using canon sdk (canon_edsdk-2.12).
I seem to be loading the dll correctly, but when I try to get the actual image, I get an error.
I tried to run the sample program to see how that is different than mine, but the same thing happens.
Trying to look for the issue on the web, I found the actual source code of the sample: http://read.pudn.com/downloads107/sourcecode/graph/texture_mapping/440409/RAWDevelop/RAWDevelopDlg.cpp__.htm
My error, on the given source, is in the void CRAWDevelopDlg::LoadImage() function -
err = EdsGetImage( m_ImageRef , source , kEdsTargetImageType_RGB , rect , size , DstStreamRef );
if( err == EDS_ERR_OK ) {...}
else
{
AfxMessageBox("The error occurred with the EdsGetImage function.");
}
The above (on line 481 on the page) is the same method that I use, and i get the same error - with error code 35 (instead of 0).
The error seems to be
#define EDS_ERR_FILE_OPEN_ERROR 0x00000023L
So... could there be something wrong with the files ? I experimented with files taken by different versions, including the newest cameras... The files open in Photoshop... And the demo does show header information, as it gives the error. So it can see something.
Am I missing anything ?
All the required dll's used are on the system path...
Thank you.

Old question, still, might help someone:
To open a raw file with the SDK you need to call these functions (you should check for errors, of course):
EdsStreamRef stream = NULL;
EdsImageRef imgRef = NULL;
EdsCreateFileStream("filename", kEdsFile_OpenExisting, kEdsAccess_Read, &stream);
EdsCreateImageRef(stream, &imgRef);
EdsRelease(stream);
Then you can set and get properties with the imgRef.
To save the image as jpg/tiff/RGB image use EdsSaveImage function.

Related

Get raw buffer for in-memory dataset in GDAL C++ API

I have generated a GeoTiff dataset in-memory using GDALTranslate() with a /vsimem/ filepath. I need access to the buffer for the actual GeoTiff file to put it in a stream for an external API. My understanding is that this should be possible with VSIGetMemFileBuffer(), however I can't seem to get this to return anything other than nullptr.
My code is essentially as follows:
//^^ GDALDataset* srcDataset created somewhere up here ^^
//psOptions struct has "-b 4" and "-of GTiff" settings.
const char* filep = "/vsimem/foo.tif";
GDALDataset* gtiffData = GDALTranslate(filep, srcDataset, psOptions, nullptr);
vsi_l_offset size = 0;
GByte* buf = VSIGetMemFileBuffer(filep, &size, true); //<-- returns nullptr
gtiffData seems to be a real dataset on inspection, it has all the appropriate properties (number of bands, raster size, etc). When I provide a real filesystem location to GDALTranslate() rather than the /vsimem/ path and load it up in QGIS it renders correctly too.
Looking a the source for VSIGetMemFileBuffer(), this should really only be returning nullptr if the file can't be found. This suggests i'm using it incorrectly. Does anyone know what the correct usage is?
Bonus points: Is there a better way to do this (stream the file out)?
Thanks!
I don't know anything about the C++ API. But in Python, the snippet below is what I sometimes use to get the contents of an in-mem file. In my case mainly VRT's but it shouldn't be any different for other formats.
But as said, I don't know if the VSI-api translate 1-on-1 to C++.
from osgeo import gdal
filep = "/vsimem/foo.tif"
# get the file size
stat = gdal.VSIStatL(filep, gdal.VSI_STAT_SIZE_FLAG)
# open file
vsifile = gdal.VSIFOpenL(filep, 'r')
# read entire contents
vsimem_content = gdal.VSIFReadL(1, stat.size, vsifile)
In the case of a VRT the content would be text, shown with something like print(vsimem_content.decode()). For a tiff it would of course be binary data.
I came back to this after putting in a workaround, and upon swapping things back over it seems to work fine. #mmomtchev suggested looking at the CPL_DEBUG output, which showed nothing unusual (and was silent during the actual VSIGetMemFileBuffer call).
In particular, for other reasons I had to put a GDALWarp call in between calling GDALTranslate and accessing the buffer, and it seems that this is what makes the difference. My guess is that GDALWarp is calling VSIFOpenL internally - although I can't find this in the source - and this does some kind of initialisation for VSIGetMemFileBuffer. Something to try for anyone else who encounters this.

Wia API - Error on changing transfer file format

I tried to control my Wifi scanner using the Windows Wia API.
I followed the tutorial on:
https://learn.microsoft.com/en-us/windows/win32/wia/-wia-wia-tutorial
And I looked at the Examples:
https://github.com/pauldotknopf/WindowsSDK7-Samples/tree/master/multimedia/wia
I basically copied the code from the datatransfer project:
https://github.com/pauldotknopf/WindowsSDK7-Samples/tree/master/multimedia/wia/datatransfer
And everthing works fine. I can communicate with my scanner and scan a document to a ".BMP" file.
Now I'd like to play around with some settings.I startet with trying to change the file format.
in DataTransfer.cpp:
https://github.com/pauldotknopf/WindowsSDK7-Samples/blob/master/multimedia/wia/datatransfer/DataTransfer.cpp
The scan happens in HRESULT DownloadItem(IWiaItem2* pWiaItem2 , BOOL bTransferFlag).
I thought the file format is specified there:
HRESULT DownloadItem(IWiaItem2* pWiaItem2 , BOOL bTransferFlag
{
...
GUID itemCategory = GUID_NULL;
ReadPropertyGuid(pWiaItem2,WIA_IPA_ITEM_CATEGORY,&itemCategory );
if( (!IsEqualIID(itemCategory,WIA_CATEGORY_FINISHED_FILE)) || (!IsEqualIID(itemCategory,WIA_CATEGORY_FOLDER)) )
{
/* WiaImgFmt_BMP sets the format to ".BMP" */
hr = WritePropertyGuid(pWiaPropertyStorage,WIA_IPA_FORMAT,WiaImgFmt_BMP);
}
if(FAILED(hr))
{
ReportError(TEXT("WritePropertyGuid() failed in DownloadItem().Format couldn't be set to BMP"),hr);
}
...
}
So i tried to change WiaImgFmt_BMP to other formats like WiaImgFmt_JPEG or WiaImgFmt_PNG
but they return the Error: HRESLUT: 0x80070057.
How can I make this work ?
I thought that maybe the scanner doesn't support the other formats, but I don't know how to check that.
When I researched this, I only found reference to the Wia Mini Driver. But I don't quite understand the difference between the API and the driver. If somebody could explain this to me I'd appreciate it.
Windows fax and scan does provide the PNG, JPEG format and I think they also use Wia, so I'd be surprised if the formats aren't supported.
I think it only support BMP and JPEG, you can use IWiaTransfer::EnumWIA_FORMAT_INFO method to know the format it support.

Reading a saved EVTX file in the given path

I am currently working on a project where I need to read windows events .
I am using OpenEventLog() and ReadEventLog() from Win API. I can read the events from system using the typename of the event.
But I need to specify the file name or file path of the .evtx file that I have saved from the EventViewer.I tried the below code,
HANDLE logHandle = OpenEventLog(NULL, "C:\\Users\\MyAccount\\Documents\\myevents.evtx");
DWORD status = GetLastError();
if(logHandle == NULL){
cerr<<"NO HANDLE GENERATED!!!"<<endl;
}else if(status == ERROR_INVALID_HANDLE){
cerr<<"INVALID HANDLE!!!"<<endl;
}else if(status!=0){
cout<<"OPENEVENTLOG ERROR STATUS::>"<<status<<endl;
}
But it does not find the specified file and switches over to default Application Events. Can anyone please tell me what the problem could be? or if there is anything to be changed in the code?
PS: I even tried placing the file in project folder and specifying just the filename(myevents.evtx) , but still doesn't work.I also tried reading the evtx directly as shown in "Reading .evt/.evtx files directly" , but later I found this can't be done. Apparently there is no way to read them directly without win API or without writing a whole bunch of parser code.
Thanks in advance.
Well, it turns out OpenEventLog() is not meant for opening saved .evtx files.
I should've been using OpenBackupEventLog() for that.

FbxManager error Efailure and unexpected file type error

I am having an issue where my FbxImporter fails to initialize. The ErrorString it returns when I call GetStatus.GetErrorString() is "Unexpected File Type". The Error code for the status is EFailure(after looking this up all autodesk says about is it means it failed). I have tried many different fbx files, and none of them seem to work. Also, I have included them in the visual studio project, and even with the executable(I know this is not the reason because other files load just fine). After looking around, there really is no forum post or anything that helps me with my problem.
Here is a snippet of my importer code.
//set up the fbxmanager
FbxManager* fbxManager = FbxManager::Create();
//set the settings for the manager
FbxIOSettings* ioSettings = FbxIOSettings::Create(fbxManager, IOSROOT);
fbxManager->SetIOSettings(ioSettings);
//set the settings for the fbx io settings
//create and init the importer
FbxImporter *importer = FbxImporter::Create(fbxManager,"");
//create and init the scene
FbxScene* fbxScene = FbxScene::Create(fbxManager, "");
//init the importer
result = importer->Initialize(filename,-1, fbxManager->GetIOSettings());
if (!result)
{
string error = importer->GetStatus().GetErrorString();
FbxStatus status = importer->GetStatus().GetCode();
return false;
}
If I need to clarify the question or you need more information to answer my question please say so, thanks.
I figure it out how to solve it!
There are two types of FBX file.
Binary FBX
ASCII FBX
Whenever you try to do
importer->Initialize(filename,-1, fbxManager->GetIOSettings());
with Binary FBX, it causes "Unexpected File Type".
However, if you convert binary FBX to ASCII FBX by FBX Converter, your program will be able to read the file.
P.S: Sample program can read the binary FBX. I think FBX has a different version and it causes compatibility issues.

Edit the frame rate of an avi file

Is it possible to change the frame rate of an avi file using the Video for windows library? I tried the following steps but did not succeed.
AviFileInit
AviFileOpen(OF_READWRITE)
pavi1 = AviFileGetStream
avi_info = AviStreamInfo
avi_info.dwrate = 15
EditStreamSetInfo(dwrate) returns -2147467262.
I'm pretty sure the AVIFile* APIs don't support this. (Disclaimer: I was the one who defined those APIs, but it was over 15 years ago...)
You can't just call EditStreamSetInfo on an plain AVIStream, only one returned from CreateEditableStream.
You could use AVISave, then, but that would obviously re-copy the whole file.
So, yes, you would probably want to do this by parsing the AVI file header enough to find the one DWORD you want to change. There are lots of documents on the RIFF and AVI file formats out there, such as http://www.opennet.ru/docs/formats/avi.txt.
I don't know anything about VfW, but you could always try hex-editing the file. The framerate is probably a field somewhere in the header of the AVI file.
Otherwise, you can script some tool like mencoder[1] to copy the stream to a new file under a different framerate.
[1] http://www.mplayerhq.hu/
HRESULT: 0x80004002 (2147500034)
Name: E_NOINTERFACE
Description: The requested COM interface is not available
Severity code: Failed
Facility Code: FACILITY_NULL (0)
Error Code: 0x4002 (16386)
Does it work if you DON'T call EditStreamSetInfo?
Can you post up the code you use to set the stream info?