I am using Visual Studio 2010, with OpenCV 3.0. I'm trying to load some images from a folder but I am having problems.
Firstly I did not have the file dirent.h, so I downloaded it in order to get the DIR* and "dirent*" structures to access to the files. All seems to be well, but now when I get to the line
string fileName = in_file->d_name;
I have found that I don't access to the name of the file.
Anyone have any thoughts on this?
This is the code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <opencv2/core/dirent.h>
#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h>
#endif
#include <conio.h>
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <strsafe.h>
#pragma comment(lib, "User32.lib")
#include <errno.h>
#include <iostream>
#include <time.h>
#include <limits.h>
#include <fstream>
#include <sys/stat.h>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/ml.hpp>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace cv::ml;
using namespace std;
int patchWidth = 15;
int patchHeight = 15;
int main(int, char**)
{
string imagesPath = "Images";
string resultsPath = "Patches";
DIR* FD;
struct dirent* in_file;
if (NULL == (FD = opendir (imagesPath.c_str())))
{
fprintf(stderr, "Error : Failed to open input directory\n");
return 0;
}
while ((in_file = readdir(FD)))
{
/* On linux/Unix we don't want current and parent directories
* If you're on Windows machine remove this two lines
*/
// if (!strcmp (in_file->d_name, "."))
// continue;
// if (!strcmp (in_file->d_name, ".."))
// continue;
/* Open directory entry file for common operation */
/* TODO : change permissions to meet your need! */
string fileName = in_file->d_name;
string pathFile = imagesPath;
pathFile.append("/");
pathFile.append(fileName);
//pathFile.append(".jpg");
Mat img = imread(pathFile.c_str());
Thanks in advance.
for a much simpler solution, just use cv::glob :
String imagesPath = "Images/*.png"; // it has filters, too !
vector<String> fn;
glob(path, fn, true); // recursive, if you want
for (size_t i=0; i<fn.size(); i++)
{
Mat img = imread(fn[i]);
...
}
Related
I am trying to create a program in c++ on xcode to communicate to the gsm modem and send sms through AT comands. I haven' t found much on the net. Here is the code that I have written till now.
#include <iostream>
#include <xlnt/xlnt.hpp>
#include <xlnt/xlnt_config.hpp>
#include <IOKitLib.h>
#include <IOTypes.h>
#include <IOReturn.h>
#include <IOKitKeys.h>
#include <iokitmig.h>
#include <OSMessageNotification.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <paths.h>
#include <termios.h>
#include <sysexits.h>
#include <sys/param.h>
#include <sys/select.h>
#include <sys/time.h>
#include <time.h>
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/serial/IOSerialKeys.h>
#include <IOKit/IOBSD.h>
#define LOCAL_ECHO
#ifdef LOCAL_ECHO
#define kOKResponseString “AT\r\r\nOK\r\n”
#else
#define kOKResponseString “\r\nOK\r\n”
#define kATCommandString "AT\r"
#define kMyErrReturn -1
enum {
kNumRetries = 3
};
static struct termios gOriginalTTYAttrs;
int main()
{
char path;
char text;
int fileDescriptor;
kern_return_t kernResult;
io_iterator_t serialPortIterator;
char deviceFilePath[MAXPATHLEN];
kernResult = MyFindModems(&serialPortIterator);
kernResult = MyGetModemPath(serialPortIterator, deviceFilePath,
sizeof(deviceFilePath));
IOObjectRelease(serialPortIterator); // Release the iterator.
// Open the modem port, initialize the modem, then close it.
if (!deviceFilePath[0])
{
printf("No modem port found.\n");
return EX_UNAVAILABLE;
}
fileDescriptor = OpenSerialPort(deviceFilePath);
if (fileDescriptor == kMyErrReturn)
{
return EX_IOERR;
}
if (MyInitializeModem(fileDescriptor))
{
printf("Modem initialized successfully.\n");
}
else {
printf("Could not initialize modem.\n");
}
MyCloseSerialPort(fileDescriptor);
printf("Modem port closed.\n");
return EX_OK;
It's giving me an error "use of undeclared identifier MyFindModems" and all the other fuctions that start with "My".
Here is the documentation to which I refer: http://mirror.informatimago.com/next/developer.apple.com/documentation/DeviceDrivers/Conceptual/WorkingWSerial/WorkingWithSerial.pdf
I am new to llvm , writing the program "main.cpp" of https://github.com/davidar/lljvm/blob/master/backend/main.cpp.
I stuck at the error while executing the command : "pm.run(m)"
error: no matching function for call to ‘llvm::legacy::PassManager::run(llvm::Expected<std::unique_ptr<llvm::Module> >&)
Here is my source code:
#include "backened.h"
#include <iostream>
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/IR/PassManager.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/IR/DataLayout.h"
#include <llvm/Transforms/Scalar.h>
#include "llvm/IR/LegacyPassManager.h"
using namespace llvm;
using namespace std;
static cl::opt<string> input(cl::Positional, cl::desc("Bitcode File.."),cl::Required);
static cl::opt<string> classname("classname",cl::desc("Binary name of the generated class..."));
int main(int argc, char** argv)
{
cl::ParseCommandLineOptions(argc, argv, "Hi..");
LLVMContext context;
ErrorOr<unique_ptr<MemoryBuffer>> mb = MemoryBuffer::getFile(input);
if(error_code ec = mb.getError()) {
errs() << ec.message();
return 1;
}
Expected<unique_ptr<Module>> m = parseBitcodeFile(mb->get()->getMemBufferRef(),context);
if(error_code ec= errorToErrorCode(m.takeError()) )
{
errs() <<"Unable to read bitcode file.." <<ec.message() ;
}
PassManager<Module> pm;
pm.add(createVerifierPass());
pm.add(createGCLoweringPass());
pm.add(createLowerSwitchPass());
pm.add(createCFGSimplificationPass());
pm.add(new JVMWriter(fouts(), classname, debugLevel));
pm.add(createGCInfoDeleter());
pm.run(*m);
return 0;
}
Please help me.
I wrote this code:
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <regex>
using namespace std;
int compile()
{
string linecode;
linecode = "_hello:";
if (std::regex_match (linecode, std::regex("(_)(.*)(:)") ))
{
cout<<"...";
}
else if (std::regex_match (linecode, std::regex("(#)(.*)(:)") ))
{
cout<<"###";
}
return 1;
}
int main(int argc, char** argv)
{
compile();
return 0;
}
And i get this error:
enter image description here
cstring error, probably in regex library.
How i can fix this ?
Thanks in advance.
I am compiling a program agains LLVM-CLANG. This is the main
#include <iostream>
#include "CompilerFactory.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Basic/Diagnostic.h"
int main(int argc, char const *argv[])
{
using clang::CompilerInstance;
using clang::TargetOptions;
using clang::TargetInfo;
using clang::FileEntry;
using clang::Token;
using clang::DiagnosticOptions;
using clang::TextDiagnosticPrinter;
CompilerInstance ci;
CSFV::CompilerFactory::GetCompilerInstance(ci);
const FileEntry *pFile = ci.getFileManager().getFile("test.c");
ci.getSourceManager().createMainFileID(pFile);
ci.getPreprocessor().EnterMainSourceFile();
ci.getDiagnosticClient().BeginSourceFile(ci.getLangOpts(),
&ci.getPreprocessor());
Token tok;
do
{
ci.getPreprocessor().Lex(tok);
if (ci.getDiagnostics().hasErrorOccurred())
break;
ci.getPreprocessor().DumpToken(tok);
std::cerr << std::endl;
} while (tok.isNot(clang::tok::eof));
ci.getDiagnosticClient().EndSourceFile();
return 0;
}
and this is the included class
//If they are not defined we have an error at compile time
#define __STDC_LIMIT_MACROS
#define __STDC_CONSTANT_MACROS
#include "llvm/Support/Host.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/Basic/TargetInfo.h"
using namespace clang;
namespace CSFV{
class CompilerFactory
{
public:
CompilerFactory();
~CompilerFactory();
/// \brief Generate and returns a compiler instance object
static void GetCompilerInstance(CompilerInstance &ci){
DiagnosticOptions diagOpts;
TextDiagnosticPrinter* diagPrinter =
new TextDiagnosticPrinter(llvm::outs(), &diagOpts, true);
ci.createDiagnostics(diagPrinter);
llvm::IntrusiveRefCntPtr<TargetOptions> pto (new TargetOptions());
pto->Triple = llvm::sys::getDefaultTargetTriple();
TargetInfo *pti =
TargetInfo::CreateTargetInfo(ci.getDiagnostics(), pto.getPtr());
ci.setTarget(pti);
ci.createFileManager();
ci.createSourceManager(ci.getFileManager());
ci.createPreprocessor();
return;
}
};
} //end of namespace CSFV
For some reason I get a segfault at the end of the execution of the main. What am I missing?
I don't know if this is the same problem I had, but what I did was declare the targetoptions as a new pointer.
eg:
clang::TargetOptions *targetOpts=new clang::TargetOptions;
I have a feeling targetinfo cleans it up when itself is destroyed.
where i can find an sample code for hypertable or else can any one post an sample for hypertable with c++
If you meant the source code for hypertable
otherwise here is the manual
You can use this HQL tutorial or look at this example
see this:: http://blog.hypertable.com/
and download hypertable project :: http://www.hypertable.org/
#ifndef BOOST_FOREACH
#define BOOST_FOREACH 0
#endif
#include "Common/Compat.h"
#include "Common/System.h"
#include <arpa/inet.h>
#include <iostream>
#include <fstream>
#include "ThriftBroker/Client.h"
#include "ThriftBroker/gen-cpp/HqlService.h"
#include "ThriftBroker/ThriftHelper.h"
#include "ThriftBroker/SerializedCellsReader.h"
using namespace Hypertable;
using namespace Hypertable::ThriftGen;
int main (int argc, char **argv)
{
Thrift::Client *client = new Thrift::Client("localhost", 38080);
if (!client->namespace_exists("/"))
{
delete client;
return 0;
}
Namespace ns = client->namespace_open("/");
HqlResult result;
client->hql_query(result, ns, "select * from foo");
std::cout << result << std::endl;
client->namespace_close(ns);
delete client;
return 0;
}
将其和/opt/hypertable/current/include/ThriftBroker/gen-cpp文件夹下的
Client_constants.cpp、Client_types.cpp、ClientService.cpp、Hql_constants.cpp、Hql_types.cpp、HqlService.cpp一起编译