本文整理汇总了C++中Ptr类的典型用法代码示例。如果您正苦于以下问题:C++ Ptr类的具体用法?C++ Ptr怎么用?C++ Ptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestObjectsObjectSave
void TestObjectsObjectSave(void)
{
CFileUtil cFileUtil;
Ptr<CTestDoubleNamedString> pDouble;
BOOL bResult;
CIndexedConfig cConfig;
cFileUtil.RemoveDir("Output");
cFileUtil.MakeDir("Output/ObjectSave");
cConfig.OptimiseForStreaming("Output/ObjectSave");
cConfig.SetObjectCacheSize(128 MB);
ObjectsInit(&cConfig);
pDouble = SetupObjectsForDehollowfication();
AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
AssertLongLongInt(9, gcObjects.NumMemoryIndexes());
AssertLongLongInt(6, gcObjects.NumMemoryNames());
AssertTrue(pDouble.IsDirty());
bResult = gcObjects.Save(pDouble.BaseObject());
AssertTrue(bResult);
AssertTrue(pDouble.IsDirty()); //This object is *still* dirty after save. Almost no objects will answer true to IsDirty.
AssertLongLongInt(1, gcObjects.NumDatabaseObjects());
AssertLongLongInt(9, gcObjects.NumMemoryIndexes());
AssertLongLongInt(6, gcObjects.NumMemoryNames());
AssertInt(106, pDouble->SerialisedSize());
AssertLongLongInt(1, gcObjects.NumDatabaseObjectsCached(106));
AssertLongLongInt(0, gcObjects.NumDatabaseObjectsCached(118));
bResult = gcObjects.Save(pDouble.BaseObject());
AssertTrue(bResult);
AssertLongLongInt(1, gcObjects.NumDatabaseObjects());
AssertInt(106, pDouble->SerialisedSize());
AssertLongLongInt(1, gcObjects.NumDatabaseObjectsCached(106));
AssertLongLongInt(0, gcObjects.NumDatabaseObjectsCached(118));
pDouble->mszString = OMalloc(CString);
pDouble->mszString->Init("A String");
bResult = gcObjects.Save(pDouble.BaseObject());
AssertTrue(bResult);
AssertLongLongInt(1, gcObjects.NumDatabaseObjects());
AssertInt(118, pDouble->SerialisedSize());
AssertLongLongInt(0, gcObjects.NumDatabaseObjectsCached(106));
AssertLongLongInt(1, gcObjects.NumDatabaseObjectsCached(118));
pDouble->mszString = OMalloc(CString);
pDouble->mszString->Init("Different Object");
AssertInt(118, pDouble->SerialisedSize());
bResult = gcObjects.Save(pDouble.BaseObject());
AssertTrue(bResult);
AssertLongLongInt(1, gcObjects.NumDatabaseObjects());
AssertInt(118, pDouble->SerialisedSize());
AssertLongLongInt(0, gcObjects.NumDatabaseObjectsCached(106));
AssertLongLongInt(1, gcObjects.NumDatabaseObjectsCached(118));
ObjectsKill();
}
示例2: main
int main(int argc, char *argv[]) {
Ptr<Instance::Manager> manager = shippingInstanceManager();
if (manager == NULL) {
cerr << "Unexpected NULL manager." << endl;
return 1;
}
Ptr<Instance> stats = manager->instanceNew("myStats", "Stats");
if (stats == NULL) {
cerr << "Unexpected NULL stats." << endl;
return 1;
}
Ptr<Instance> fleet = manager->instanceNew("myFleet", "Fleet");
if (fleet == NULL) {
cerr << "Unexpected NULL." << endl;
return 1;
}
fleet->attributeIs("Boat, speed", "60");
fleet->attributeIs("Truck, capacity", "50");
fleet->attributeIs("Plane, cost", "20");
cout << "fleet->attribute('Boat, speed'): " << fleet->attribute("Boat, speed") << endl;
// --- Create instances
// -- Locations
// customers
Ptr<Instance> customer1 = manager->instanceNew("customer1", "Customer");
Ptr<Instance> customer2 = manager->instanceNew("customer2", "Customer");
// ports
Ptr<Instance> port1 = manager->instanceNew("port1", "Port");
if (customer1 == NULL || customer2 == NULL || port1 == NULL) {
cerr << "Unexpected NULL customer or port." << endl;
return 1;
}
// -- Segments
// boat
Ptr<Instance> boatSeg1 = manager->instanceNew("boatSeg1", "Boat segment");
Ptr<Instance> boatSeg2 = manager->instanceNew("boatSeg2", "Boat segment");
// truck
Ptr<Instance> truckSeg1 = manager->instanceNew("truckSeg1", "Truck segment");
Ptr<Instance> truckSeg2 = manager->instanceNew("truckSeg2", "Truck segment");
if (boatSeg1 == NULL || boatSeg2 == NULL || truckSeg1 == NULL || truckSeg2 == NULL) {
cerr << "Unexpected NULL segment." << endl;
return 1;
}
// connections
// customer1 <---> port1
truckSeg1->attributeIs("source", "customer1");
truckSeg2->attributeIs("source", "port1");
truckSeg1->attributeIs("return segment", "truckSeg2");
cout << "truckSeg1->attribute('source'): " << truckSeg1->attribute("source") << endl;
// customer2 <---> port1
boatSeg1->attributeIs("source", "customer2");
boatSeg2->attributeIs("source", "port1");
boatSeg1->attributeIs("return segment", "boatSeg2");
cout << "boatSeg1->attribute('return segment'): " << boatSeg1->attribute("return segment") << endl;
// -- Segment lengths
boatSeg1->attributeIs("length", "400");
boatSeg2->attributeIs("length", "400");
truckSeg1->attributeIs("length", "900");
truckSeg2->attributeIs("length", "900");
// -- Segment difficulties
boatSeg1->attributeIs("difficulty", "1");
boatSeg2->attributeIs("difficulty", "1");
truckSeg1->attributeIs("difficulty", "1");
truckSeg2->attributeIs("difficulty", "1");
// -- Segment expedite support
boatSeg1->attributeIs("expedite support", "yes");
boatSeg2->attributeIs("expedite support", "yes");
truckSeg1->attributeIs("expedite support", "yes");
truckSeg2->attributeIs("expedite support", "yes");
// -- Connectivity queries
Ptr<Instance> conn = manager->instanceNew("myConn", "Conn");
if (conn == NULL) {
cerr << "Unexpected NULL conn." << endl;
return 1;
}
cout << "**** explore customer1 : distance 1500 ****" << endl;
cout << conn->attribute("explore customer1 : distance 1500") << endl;
cout << endl;
cout << "*** connect customer2 : customer1 ****" << endl;
cout << conn->attribute("connect customer2 : customer1") << endl;
cout << endl;
//.........这里部分代码省略.........
示例3: CD
MD::MarkovData(const string &lab, Ptr<MarkovData> last, bool grow)
: CD(lab, last->key(), grow)
{
set_prev(last);
last->set_next(this);
}
示例4: initModule_nonfree
bool initModule_nonfree(void)
{
Ptr<Algorithm> sift = createSIFT(), surf = createSURF();
return sift->info() != 0 && surf->info() != 0;
}
示例5: by_type
Ptr<ModelBase> by_type(std::string type, usage use, Ptr<Options> options) {
Ptr<ExpressionGraph> graph = nullptr; // graph unknown at this stage
// clang-format off
if(type == "s2s" || type == "amun" || type == "nematus") {
return models::encoder_decoder()(options)
("usage", use)
("original-type", type)
.push_back(models::encoder()("type", "s2s"))
.push_back(models::decoder()("type", "s2s"))
.construct(graph);
}
if(type == "transformer") {
return models::encoder_decoder()(options)
("usage", use)
.push_back(models::encoder()("type", "transformer"))
.push_back(models::decoder()("type", "transformer"))
.construct(graph);
}
if(type == "transformer_s2s") {
return models::encoder_decoder()(options)
("usage", use)
("original-type", type)
.push_back(models::encoder()("type", "transformer"))
.push_back(models::decoder()("type", "s2s"))
.construct(graph);
}
if(type == "lm") {
auto idx = options->has("index") ? options->get<size_t>("index") : 0;
std::vector<int> dimVocabs = options->get<std::vector<int>>("dim-vocabs");
int vocab = dimVocabs[0];
dimVocabs.resize(idx + 1);
std::fill(dimVocabs.begin(), dimVocabs.end(), vocab);
return models::encoder_decoder()(options)
("usage", use)
("type", "s2s")
("original-type", type)
.push_back(models::decoder()
("index", idx)
("dim-vocabs", dimVocabs))
.construct(graph);
}
if(type == "multi-s2s") {
size_t numEncoders = 2;
auto ms2sFactory = models::encoder_decoder()(options)
("usage", use)
("type", "s2s")
("original-type", type);
for(size_t i = 0; i < numEncoders; ++i) {
auto prefix = "encoder" + std::to_string(i + 1);
ms2sFactory.push_back(models::encoder()("prefix", prefix)("index", i));
}
ms2sFactory.push_back(models::decoder()("index", numEncoders));
return ms2sFactory.construct(graph);
}
if(type == "shared-multi-s2s") {
size_t numEncoders = 2;
auto ms2sFactory = models::encoder_decoder()(options)
("usage", use)
("type", "s2s")
("original-type", type);
for(size_t i = 0; i < numEncoders; ++i) {
auto prefix = "encoder";
ms2sFactory.push_back(models::encoder()("prefix", prefix)("index", i));
}
ms2sFactory.push_back(models::decoder()("index", numEncoders));
return ms2sFactory.construct(graph);
}
if(type == "multi-transformer") {
size_t numEncoders = 2;
auto mtransFactory = models::encoder_decoder()(options)
("usage", use)
("type", "transformer")
("original-type", type);
for(size_t i = 0; i < numEncoders; ++i) {
auto prefix = "encoder" + std::to_string(i + 1);
mtransFactory.push_back(models::encoder()("prefix", prefix)("index", i));
}
mtransFactory.push_back(models::decoder()("index", numEncoders));
return mtransFactory.construct(graph);
}
if(type == "shared-multi-transformer") {
size_t numEncoders = 2;
auto mtransFactory = models::encoder_decoder()(options)
("usage", use)
//.........这里部分代码省略.........
示例6: pdf
double MarkovModel::pdf(Ptr<DataPointType> dp, bool logscale)const{
double ans=0;
if(!!dp->prev()){
ans = Q(dp->prev()->value(), dp->value());
}else ans = pi0(dp->value());
return logscale ? safelog(ans) : ans; }
示例7: train
bool train(const Ptr<TrainData>& data, int)
{
Mat samples = data->getTrainSamples(), labels;
return trainEM(samples, labels, noArray(), noArray());
}
示例8: ACE_MT
MgStringCollection* MgSecurityManager::Authenticate(
MgUserInformation* userInformation, MgStringCollection* requiredRoles,
bool returnAssignedRoles)
{
ACE_MT(ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, ace_mon, sm_mutex, NULL));
Ptr<MgStringCollection> assignedRoles;
MG_TRY()
if (NULL == userInformation)
{
throw new MgAuthenticationFailedException(
L"MgSecurityManager.Authenticate", __LINE__, __WFILE__, NULL, L"", NULL);
}
STRING user = userInformation->GetUserName();
STRING session = userInformation->GetMgSessionId();
if (session.empty())
{
if (user.empty())
{
throw new MgAuthenticationFailedException(
L"MgSecurityManager.Authenticate", __LINE__, __WFILE__, NULL, L"", NULL);
}
const MgUserInfo* userInfo = sm_securityCache->GetUserInfo(user);
assert(NULL != userInfo);
if (userInformation->GetPassword() != userInfo->GetPassword())
{
throw new MgAuthenticationFailedException(
L"MgSecurityManager.Authenticate", __LINE__, __WFILE__, NULL, L"", NULL);
}
}
else
{
user = MgSessionManager::UpdateLastAccessedTime(session);
}
if (NULL != requiredRoles &&
!sm_securityCache->IsUserInRoles(user, requiredRoles))
{
MG_LOG_AUTHENTICATION_ENTRY(MgResources::UnauthorizedAccess.c_str());
throw new MgUnauthorizedAccessException(
L"MgSecurityManager.Authenticate", __LINE__, __WFILE__, NULL, L"", NULL);
}
if (returnAssignedRoles)
{
assignedRoles = sm_securityCache->EnumerateRoles(user);
}
// Commented out logging of successful authentication because it creates lots of entries in the Authentication.log
// MG_LOG_AUTHENTICATION_ENTRY(MgResources::Success.c_str());
MG_CATCH(L"MgSecurityManager.Authenticate")
if (mgException != NULL)
{
MG_LOG_AUTHENTICATION_ENTRY(MgResources::Failure.c_str());
}
MG_THROW()
return assignedRoles.Detach();
}
示例9: main
int main(int _nargs, char **_vargs)
{
DebugLevel debugLevel = LOW;
bool showImages = false;
// Delete previous results
system("rm -rf ./output/*");
if (_nargs < 3)
{
cout << "Not enough arguments\nUsage:\n\tHomework1 <input_file>\n\n";
return EXIT_FAILURE;
}
// Initialize printer
Printer::getInstance()->calculateConversionRate(1000, 1000);
// Method to be used to solve the visual odometry problem
string method = _vargs[2];
cout << "Using method " << method << "\n";
// Get the calibration matrix
Mat K = Mat::zeros(3, 3, CV_64FC1);
Loader::loadCalibrationMatrix(K, _vargs[1]);
// Load images
vector<Mat> images;
Loader::loadInput(images, _vargs[1]);
// Get ground truth
vector<Mat> groundTruth;
Loader::loadGroundTruth(groundTruth, _vargs[1], images.size());
// Print groundtruth trajectory
Printer::printTrajectory(groundTruth, "groundTruth.png", RED);
Ptr<FeatureDetector> featureExtractor = FeatureDetector::create("HARRIS");
Ptr<DescriptorExtractor> descriptorExtractor = DescriptorExtractor::create("SIFT");
FlannBasedMatcher matcher;
vector<vector<KeyPoint>> keypoints;
vector<Mat> descriptors;
vector<Mat> trajectory;
Mat start = Mat::zeros(4, 1, CV_64FC1);
start.at<double>(0, 3) = 1;
trajectory.push_back(start);
// Process data
initModule_nonfree();
for (size_t j = 0; j < images.size(); j++)
{
cout << "*** Processing image " << j << " ***\n";
Mat image = images[j];
// Keypoints extraction
keypoints.push_back(vector<KeyPoint>());
featureExtractor->detect(image, keypoints.back());
// Feature extraction
descriptors.push_back(Mat());
descriptorExtractor->compute(image, keypoints.back(), descriptors.back());
if (j > 0)
{
int train = keypoints.size() - 1;
int query = train - 1;
// Match points between images
vector<DMatch> matches = Helper::getMatches(descriptors[query], descriptors[train], matcher);
if (showImages)
Helper::showMatches(images[query], images[train], keypoints[query], keypoints[train], matches);
if (matches.size() >= 8)
{
Mat transformation;
if (method.compare("essential_matrix") == 0)
{
/** RESOLUTION USING ESSENTIAL MATRIX */
// Calculate the fundamental matrix
Mat F;
Helper::getFundamentalMatrix(F, matches, keypoints[query], keypoints[train]);
if (debugLevel >= LOW)
Printer::printMatrix<double>(F, 3, "F:");
// Calculate E
//Mat E;
//Helper::getEssentialMatrix(E, K, F);
//if (debugLevel >= MEDIUM)
//Printer::printMatrix<double>(E, 3, "E:");
// Calculate the motion between the two images
Mat R, tx, points3D;
Helper::calculateMotion(F, K, R, tx, points3D, keypoints[query], keypoints[train], matches);
hconcat(R, tx, transformation);
}
else if (method.compare("homography") == 0)
{
//.........这里部分代码省略.........
示例10: main
int main(int argc, char *argv[])
{
const char *keys =
"{ help h usage ? | | show this message }"
"{ path p |true| path to dataset (bounding/, camera/, P/, png/ folders) }";
CommandLineParser parser(argc, argv, keys);
string path(parser.get<string>("path"));
if (parser.has("help") || path=="true")
{
parser.printMessage();
return -1;
}
Ptr<MSM_epfl> dataset = MSM_epfl::create();
dataset->load(path);
// ***************
// dataset contains all information for each image.
// For example, let output dataset size and first object.
printf("dataset size: %u\n", (unsigned int)dataset->getTrain().size());
MSM_epflObj *example = static_cast<MSM_epflObj *>(dataset->getTrain()[0].get());
printf("first image:\nname: %s\n", example->imageName.c_str());
printf("\nbounding:\n");
for (int i=0; i<2; ++i)
{
for (int j=0; j<3; ++j)
{
printf("%f ", example->bounding(i, j));
}
printf("\n");
}
printf("\ncamera:\n");
for (int i=0; i<3; ++i)
{
for (int j=0; j<3; ++j)
{
printf("%f ", example->camera.mat1(i, j));
}
printf("\n");
}
printf("\n");
for (int i=0; i<3; ++i)
{
printf("%f ", example->camera.mat2[i]);
}
printf("\n\n");
for (int i=0; i<3; ++i)
{
for (int j=0; j<3; ++j)
{
printf("%f ", example->camera.mat3(i, j));
}
printf("\n");
}
printf("\n");
for (int i=0; i<3; ++i)
{
printf("%f ", example->camera.mat4[i]);
}
printf("\n\n");
printf("image width: %u, height: %u\n", example->camera.imageWidth, example->camera.imageHeight);
printf("\nP:\n");
for (int i=0; i<3; ++i)
{
for (int j=0; j<4; ++j)
{
printf("%f ", example->p(i, j));
}
printf("\n");
}
return 0;
}
示例11: RemoveRoute
void
FibHelper::RemoveRoute(Ptr<Node> node, const Name& prefix, Ptr<Node> otherNode)
{
for (uint32_t deviceId = 0; deviceId < node->GetNDevices(); deviceId++) {
Ptr<PointToPointNetDevice> netDevice =
DynamicCast<PointToPointNetDevice>(node->GetDevice(deviceId));
if (netDevice == 0)
continue;
Ptr<Channel> channel = netDevice->GetChannel();
if (channel == 0)
continue;
if (channel->GetDevice(0)->GetNode() == otherNode
|| channel->GetDevice(1)->GetNode() == otherNode) {
Ptr<L3Protocol> ndn = node->GetObject<L3Protocol>();
NS_ASSERT_MSG(ndn != 0, "Ndn stack should be installed on the node");
shared_ptr<Face> face = ndn->getFaceByNetDevice(netDevice);
NS_ASSERT_MSG(face != 0, "There is no face associated with the p2p link");
RemoveRoute(node, prefix, face);
return;
}
}
NS_FATAL_ERROR("Cannot remove route: Node# " << node->GetId() << " and Node# " << otherNode->GetId()
<< " are not connected");
}
示例12: ACE_DEBUG
///----------------------------------------------------------------------------
/// <summary>
/// Executes the operation.
/// </summary>
///
/// <exceptions>
/// MgException
/// </exceptions>
///----------------------------------------------------------------------------
void MgOpGetLayer::Execute()
{
ACE_DEBUG((LM_DEBUG, ACE_TEXT(" (%t) MgOpGetLayer::Execute()\n")));
MG_LOG_OPERATION_MESSAGE(L"GetLayer");
MG_SERVER_DRAWING_SERVICE_TRY()
MG_LOG_OPERATION_MESSAGE_INIT(m_packet.m_OperationVersion, m_packet.m_NumArguments);
ACE_ASSERT(m_stream != NULL);
if (3 == m_packet.m_NumArguments)
{
Ptr<MgResourceIdentifier> identifier = (MgResourceIdentifier*)m_stream->GetObject();
STRING sectionName;
m_stream->GetString(sectionName);
STRING layerName;
m_stream->GetString(layerName);
BeginExecution();
MG_LOG_OPERATION_MESSAGE_PARAMETERS_START();
MG_LOG_OPERATION_MESSAGE_ADD_STRING((NULL == identifier) ? L"MgResourceIdentifier" : identifier->ToString().c_str());
MG_LOG_OPERATION_MESSAGE_ADD_SEPARATOR();
MG_LOG_OPERATION_MESSAGE_ADD_STRING(sectionName.c_str());
MG_LOG_OPERATION_MESSAGE_ADD_SEPARATOR();
MG_LOG_OPERATION_MESSAGE_ADD_STRING(layerName.c_str());
MG_LOG_OPERATION_MESSAGE_PARAMETERS_END();
Validate();
Ptr<MgByteReader> byteReader = m_service->GetLayer(identifier, sectionName, layerName);
EndExecution(byteReader);
}
else
{
MG_LOG_OPERATION_MESSAGE_PARAMETERS_START();
MG_LOG_OPERATION_MESSAGE_PARAMETERS_END();
}
if (!m_argsRead)
{
throw new MgOperationProcessingException(L"MgOpGetLayer.Execute",
__LINE__, __WFILE__, NULL, L"", NULL);
}
// Successful operation
MG_LOG_OPERATION_MESSAGE_ADD_STRING(MgResources::Success.c_str());
MG_SERVER_DRAWING_SERVICE_CATCH(L"MgOpGetLayer.Execute");
if (mgException != NULL)
{
// Failed operation
MG_LOG_OPERATION_MESSAGE_ADD_STRING(MgResources::Failure.c_str());
}
// Add access log entry for operation
MG_LOG_OPERATION_MESSAGE_ACCESS_ENTRY();
MG_SERVER_DRAWING_SERVICE_THROW()
}
示例13: stitch
bool stitch(vector<Mat> orig_images) {
// Check if have enough images
try {
int num_images = static_cast<int>(orig_images.size());
if (num_images < 1)
{
return 1;
}
if (num_images < 2) {
imwrite(result_name, orig_images[0]);
return 1;
}
double work_scale = 1, seam_scale = 1, compose_scale = 1;
bool is_work_scale_set = false, is_seam_scale_set = false, is_compose_scale_set = false;
LOGLN("Finding features...");
#if ENABLE_LOG
int64 t = getTickCount();
#endif
Ptr<FeaturesFinder> finder;
if (features_type == "surf")
{
#if defined(HAVE_OPENCV_NONFREE) && defined(HAVE_OPENCV_GPU)
if (try_gpu && gpu::getCudaEnabledDeviceCount() > 0)
finder = new SurfFeaturesFinderGpu();
else
#endif
finder = new SurfFeaturesFinder();
}
else if (features_type == "orb")
{
finder = new OrbFeaturesFinder();
}
else
{
cout << "Unknown 2D features type: '" << features_type << "'.\n";
return -1;
}
Mat full_img, img;
vector<ImageFeatures> features(num_images);
vector<Mat> images(num_images);
vector<Size> full_img_sizes(num_images);
double seam_work_aspect = 1;
for (int i = 0; i < num_images; ++i)
{
full_img = orig_images[i];
full_img_sizes[i] = full_img.size();
if (full_img.empty())
{
// LOGLN("Can't open image " << img_names[i]);
return -1;
}
if (work_megapix < 0)
{
img = full_img;
work_scale = 1;
is_work_scale_set = true;
}
else
{
if (!is_work_scale_set)
{
work_scale = min(1.0, sqrt(work_megapix * 1e6 / full_img.size().area()));
is_work_scale_set = true;
}
resize(full_img, img, Size(), work_scale, work_scale);
}
if (!is_seam_scale_set)
{
seam_scale = min(1.0, sqrt(seam_megapix * 1e6 / full_img.size().area()));
seam_work_aspect = seam_scale / work_scale;
is_seam_scale_set = true;
}
(*finder)(img, features[i]);
features[i].img_idx = i;
LOGLN("Features in image #" << i+1 << ": " << features[i].keypoints.size());
resize(full_img, img, Size(), seam_scale, seam_scale);
images[i] = img.clone();
}
finder->collectGarbage();
full_img.release();
img.release();
LOGLN("Finding features, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
LOG("Pairwise matching");
#if ENABLE_LOG
t = getTickCount();
#endif
vector<MatchesInfo> pairwise_matches;
BestOf2NearestMatcher matcher(try_gpu, match_conf);
//.........这里部分代码省略.........
示例14: _isempty
bool _isempty (Ptr<Patch> i)
{
return i.empty();
}
示例15: main
int main(int argc, char **argv)
{
if( argc < 2 )
{
help();
return -1;
}
structured_light::SinusoidalPattern::Params params;
phase_unwrapping::HistogramPhaseUnwrapping::Params paramsUnwrapping;
// Retrieve parameters written in the command line
CommandLineParser parser(argc, argv, keys);
params.width = parser.get<int>(0);
params.height = parser.get<int>(1);
params.nbrOfPeriods = parser.get<int>(2);
params.setMarkers = parser.get<bool>(3);
params.horizontal = parser.get<bool>(4);
params.methodId = parser.get<int>(5);
String outputCapturePath = parser.get<String>(6);
params.shiftValue = static_cast<float>(2 * CV_PI / 3);
params.nbrOfPixelsBetweenMarkers = 70;
String outputPatternPath = parser.get<String>(7);
String outputWrappedPhasePath = parser.get<String>(8);
String outputUnwrappedPhasePath = parser.get<String>(9);
String reliabilitiesPath = parser.get<String>(10);
Ptr<structured_light::SinusoidalPattern> sinus = structured_light::SinusoidalPattern::create(params);
Ptr<phase_unwrapping::HistogramPhaseUnwrapping> phaseUnwrapping;
vector<Mat> patterns;
Mat shadowMask;
Mat unwrappedPhaseMap, unwrappedPhaseMap8;
Mat wrappedPhaseMap, wrappedPhaseMap8;
//Generate sinusoidal patterns
sinus->generate(patterns);
VideoCapture cap(CAP_PVAPI);
if( !cap.isOpened() )
{
cout << "Camera could not be opened" << endl;
return -1;
}
cap.set(CAP_PROP_PVAPI_PIXELFORMAT, CAP_PVAPI_PIXELFORMAT_MONO8);
namedWindow("pattern", WINDOW_NORMAL);
setWindowProperty("pattern", WND_PROP_FULLSCREEN, WINDOW_FULLSCREEN);
imshow("pattern", patterns[0]);
cout << "Press any key when ready" << endl;
waitKey(0);
int nbrOfImages = 30;
int count = 0;
vector<Mat> img(nbrOfImages);
Size camSize(-1, -1);
while( count < nbrOfImages )
{
for(int i = 0; i < (int)patterns.size(); ++i )
{
imshow("pattern", patterns[i]);
waitKey(300);
cap >> img[count];
count += 1;
}
}
cout << "press enter when ready" << endl;
bool loop = true;
while ( loop )
{
char c = (char) waitKey(0);
if( c == 10 )
{
loop = false;
}
}
switch(params.methodId)
{
case structured_light::FTP:
for( int i = 0; i < nbrOfImages; ++i )
{
/*We need three images to compute the shadow mask, as described in the reference paper
* even if the phase map is computed from one pattern only
*/
vector<Mat> captures;
if( i == nbrOfImages - 2 )
{
captures.push_back(img[i]);
captures.push_back(img[i-1]);
captures.push_back(img[i+1]);
}
else if( i == nbrOfImages - 1 )
{
captures.push_back(img[i]);
captures.push_back(img[i-1]);
captures.push_back(img[i-2]);
//.........这里部分代码省略.........