I want to load a saved .rssdk file as input to my realsense application. I saw the below code from examples.
pxcCHAR fileName[1024] = { 0 };
PXCSenseManager *psm = PXCSenseManager::CreateInstance();
PXCCaptureManager* captureManager = psm->QueryCaptureManager();
captureManager->SetFileName(fileName, false);
psm->QueryCaptureManager()->SetRealtime(false);
But my problem is how to give my file name (suppose "out.rssdk") to this pxcCHAR fileName??
pxcCHAR is just a wchar:
typedef wchar_t pxcCHAR;
so you can just use a wchar literal:
pxcCHAR fileName[1024] = L"out.rssdk";
and other wchar stuff like std::wstring.
Related
I searched everywhere but I can't find sample on how to actually save a file to the system. Threads about opening a Save File dialog box can be read in numerous sites but the successful saving of the user created file to a user selected path is always cut (//add your code here). Please bear with me as I am new in C++ (MFC).
I know I need to actually code the saving of the data to the file path but I just don't know how.
Code snippet (via CFileDialog):
void CTryDlg::OnBnClickedSaveAs()
{
CFileDialog dlg(FALSE);
dlg.m_ofn.nMaxFile = MAX_PATH;
dlg.m_ofn.lpstrFilter = _T("Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0\0");
dlg.m_ofn.lpstrTitle = _T("Save File As");
CString filename;
if (dlg.DoModal() == IDOK)
{
filename = dlg.GetPathName(); // return full path and filename
//write your sample code here to save the file to the user selected path
}
}
Code snippet via GetSaveFileName():
OPENFILENAME SfnInit()
{
OPENFILENAME t_sfn;
char szFileName[MAX_PATH] = "";
ZeroMemory(&t_sfn, sizeof(t_sfn));
t_sfn.lStructSize = sizeof(t_sfn);
t_sfn.hwndOwner = NULL;
t_sfn.lpstrFilter = _T("Text file\0*.txt\0");
t_sfn.lpstrFile = szFileName;
t_sfn.lpstrTitle = _T("Save As\0");
t_sfn.nMaxFile = MAX_PATH;
t_sfn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
t_sfn.lpstrDefExt = _T("Text file\0*.txt\0");
if (GetSaveFileName(&t_sfn2) != true)
{
AfxMessageBox(_T("Saving file canceled!"));
}
else
{
//write your sample code here to save the file to the user selected path
}
}
Anybody who can provide a very simple sample code that could actually save a user desired file (ex: text file) to the user selected path will be greatly appreciated.
I have also read that the program should run as administrator.
Thank you.
Since you are using MFC, I would recommend sticking with MFC classes for such file I/O.
Sadly, I am using VS 2008, but here is the class hierarchy for CFile:
If it's a text file, using/deriving from CStdioFile makes sense. It has the basic ReadString WriteString methods.
However, if you are wanting to serialize something derived from CDocument (Document/View architecture), you will want to utilize streams, possibly with schemas/versioning to go with your serialization. That's a completely different topic/answer.
EDIT: duh - here's a simple CStdioFile output
CFileDialog fd(FALSE, "txt", "MyFile.txt", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "Text files (*.txt)|*.txt|All files (*.*)|*.*", this);
if (fd.DoModal() == IDOK)
{
CStdioFile fOut(fd.GetPathName(), CFile::modeCreate | CFile::modeWrite);
for (int i = 0; i < asData.GetSize(); i++)
{
fOut.WriteString(asData[i] + '\n');
}
fOut.Close();
}
Here is a very basic sample:
...
if (dlg.DoModal() == IDOK)
{
filename = dlg.GetPathName(); // return full path and filename
FILE *file = fopen(filename, "w"); // open file for writing
if (file == NULL)
AfxMessageBox("File couild not be created."};
else
{
// file could be created, write something
fprintf(file, "Some text\n");
// and close the file
fclose(file);
}
}
...
This will write "some text" into the file whose name has been provided by the user with the CFileDialog file picker.
In real world you need to write whatever text according to the data of your program.
This is really most basic knowledge.
I am new to using the FBX SDK and I am trying to convert an OBJ file to an FBX ASCII file in C++. However, when running the following code it outputs a Binary FBX file and the file seems to be incorrect/"corrupted." The reason I say it is corrupted is because when I insert it into the FBX conversion program that Autodesk provides, it says the input binary file I got as an output from my program is corrupted. Can anyone help me solve this issue please? Thank you in advance.
//Creates a SDK manager
FbxManager* fbxmanager = FbxManager::Create();
//Set the Input/Output Settings for the SDK Manager
//EXP_ = export settings; IMP_ = import setting
FbxIOSettings* ios_settings = FbxIOSettings::Create(fbxmanager, IOSROOT);
ios_settings->SetBoolProp(EXP_ASCIIFBX, true);
fbxmanager->SetIOSettings(ios_settings);
//Creates a Scene
FbxScene* fbxscene = FbxScene::Create(fbxmanager, "");
//Creates an importer object
FbxImporter* fbximporter = FbxImporter::Create(fbxmanager, "");
//Path to the obj file
const char* obj_path = "objs/airboat.obj";
//Path to the saved fbx file
const char* fbx_path = "fbxs/global_mesh.fbx";
//Initilaize the Importer Object with the path and name of the file
bool import_stat = fbximporter->Initialize(obj_path, -1, fbxmanager->GetIOSettings());
import_stat = fbximporter->Import(fbxscene);
//Creates an exporter object
FbxExporter* fbxexporter = FbxExporter::Create(fbxmanager, "");
//Initilaize the Exporter Object with the path and name of the file
bool export_stat = fbxexporter->Initialize(fbx_path, -1,fbxmanager->GetIOSettings());
export_stat = fbxexporter->Export(fbxscene);
EDIT: Sorry forgot to provide debugging output:
All boolean functions result in true.
I would like to access files which are inside Resources in app bundle. Unfortunately i cannot use QT resorces, as i'm using CascadeClassifier from opencv. My current paths are
const std::string FACE_CLASIFIER_PATH = "/Resources/haarcascade_frontalface_default.xml";
const std::string EYES_CLASIFIER_PATH = "/Resources/haarcascade_mcs_eyepair_big.xml";
I also tried
const std::string FACE_CLASIFIER_PATH = "../Resources/haarcascade_frontalface_default.xml";
const std::string EYES_CLASIFIER_PATH = "../Resources/haarcascade_mcs_eyepair_big.xml";
But nether of them work. As for config both files are present inside MyApp.app/Contents/Resources, i include them using qmake
mac {
APP_XML_FILES.files = ../haarcascade_frontalface_default.xml ../haarcascade_mcs_eyepair_big.xml
APP_XML_FILES.path = Contents/Resources
QMAKE_BUNDLE_DATA += APP_XML_FILES
}
I would appreciate any help with this issue
You don't say what you want to do with the files, though that could be due to my lack of knowledge of opencv. However you can use the Core Foundation classes to get paths to files in the resources folder: -
CFURLRef appUrlRef;
appUrlRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("somefile"), NULL, NULL);
// do something with the file
//...
// Ensure you release the reference
CFRelease(appUrlRef);
With a CFURLRef, you can use Apple's documentation to get what you need from it.
For example, if you want a file path: -
CFStringRef filePathRef = CFURLCopyPath(appUrlRef);
// Always release items retrieved with a function that has "create or "copy" in its name
CFRelease(filePathRef);
From the file path, we can get a char* to the path: -
const char* filePath = CFStringGetCStringPtr(filePathRef, kCFStringEncodingUTF8);
So, putting it all together, if you want to get a char* path to haarcascade_mcs_eyepair_big.xml: -
CFURLRef appUrlRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("haarcascade_mcs_eyepair_big.xml"), NULL, NULL);
CFStringRef filePathRef = CFURLCopyPath(appUrlRef);
const char* filePath = CFStringGetCStringPtr(filePathRef, kCFStringEncodingUTF8);
// Release references
CFRelease(filePathRef);
CFRelease(appUrlRef);
I'm working on a C++ program that will automatically backup my work to my FTP server. So far I am able to upload a single file, by specifying a file name using this
CString strFilePath = szFile ;
int iPos = strFilePath.ReverseFind('\\');
CString strFileName = strFilePath.Right((strFilePath.GetLength()- iPos-1) );
CString strDirPath = m_szFolderDroppedIn ;
strDirPath = strDirPath.Mid(0,strDirPath.GetLength() - 1);
int iPost = strDirPath.ReverseFind('\\');
CString strDirName = strDirPath.Right((strDirPath.GetLength()- iPost -1) );
bool curdir = ftpclient.SetServerDirectory((char*)strDirName.GetBuffer(strDirName.GetLength()));
//Upload to Server
int uploadret = ftpclient.PutFile(szFile,(char*)strFileName.GetBuffer(strFileName.GetLength()),0,true,dwLastError);
m_lsDroppedFiles.RemoveAll();
break;
}
Now I want to be able to iterate through a directory (Which contains subdirectories) and recursively call. I'm having a problem getting a hold of the files in the directory.
Any help or code snippet...
Since you are using MFC, you can use the CFileFind class. Example code is given in MSDN. Alternatively, you can use boost.filesystem for the same.
#Swapnil: If you use boost::filesystem, there is a recursive_directory_iterator
I'd like to get the length of a media file in a qt application i'm building and so i decided to use taglib. This is the methos that is meant to read the length
void loadMetaData(QString file) {
QByteArray fileName = QFile::encodeName( file );
const char * encodedName = fileName.constData();
TagLib::FileRef fileref = TagLib::FileRef( encodedName );
if (fileref.isNull())
{
qDebug() << "Null";
}
else
{
qDebug() << "Not Null";
}
}
Problem is fileref is always null for some reason and i can't figure out why......
Use the getter audioProperties() on your FileRef object. The returned pointer contains the length of the file in seconds.
TagLib# is able to work with some Theora files. I used it in a project but found it wouldn't work with many Theora videos (I don't think any converted using libtheora 1.1 worked).
TagLib.File file = TagLib.File.Create(#"c:\video.ogv");
string height = file.Properties.VideoHeight;
This is for the .NET, not C++ though.