void ba81AggregateDistributions(std::vector<struct omxExpectation *> &expectation, int *version, omxMatrix *meanMat, omxMatrix *covMat) { int allVer = 0; for (size_t ex=0; ex < expectation.size(); ++ex) { BA81Expect *ba81 = (BA81Expect *) expectation[ex]->argStruct; allVer += ba81->ElatentVersion; } if (*version == allVer) return; *version = allVer; BA81Expect *exemplar = (BA81Expect *) expectation[0]->argStruct; ba81NormalQuad &quad = exemplar->getQuad(); ba81NormalQuad combined(quad); int got = 0; for (size_t ex=0; ex < expectation.size(); ++ex) { BA81Expect *ba81 = (BA81Expect *) expectation[ex]->argStruct; // double weight = 1/ba81->weightSum; ? combined.addSummary(ba81->grp.quad); ++got; } if (got == 0) return; int dim = quad.abilities(); int numLatents = dim + triangleLoc1(dim); Eigen::ArrayXd latentDist(numLatents); combined.EAP(got, latentDist); for (int d1=quad.abilities(); d1 < numLatents; d1++) { latentDist[d1] *= got / (got - 1.0); } exportLatentDistToOMX(quad, latentDist.data(), meanMat, covMat); }
double UtcTime::difference( const UtcTime &other_time ) const { double other = other_time.combined(); double me = combined(); return me - other; }
ItemSet* Parser::generate_itemset(std::set<Item> head) { std::cout << "=== Generating head:" << std::endl; for (auto& x : head) { std::cout << "\t"; Parser::debug_item(x); } std::cout << "=== done head "; std::map<std::set<Item>, ItemSet*>::iterator it = this->itemsets.find(head); if (it != this->itemsets.end()) { std::cout << "(exists)" << std::endl; return it->second; } std::cout << "(new)" << std::endl; std::unique_ptr<ItemSet> is(new ItemSet); is->head = head; is->index = this->states.size(); ItemSet* ret = is.get(); this->itemsets[head] = ret; this->states.push_back(std::move(is)); std::set<std::string> encountered_terminals; for (auto& item : head) { if (Parser::is_item_done(item)) { continue; } std::string next_symbol = item.first->symbols.at(item.second); this->expand_symbol_into_itemset(ret, next_symbol, &encountered_terminals); } std::set<Item> combined(ret->head); combined.insert(ret->additionals.begin(), ret->additionals.end()); assert(combined.size() == ret->head.size() + ret->additionals.size()); for (auto& item : combined) { if (Parser::is_item_done(item)) { continue; } std::string next_symbol = item.first->symbols.at(item.second); if (ret->next.find(next_symbol) == ret->next.end()) { std::set<Item> h2; for (auto& i2 : combined) { if (Parser::is_item_done(i2)) { continue; } std::string ns2 = i2.first->symbols.at(i2.second); if (ns2 == next_symbol) { h2.insert(Item(i2.first, i2.second + 1)); } } ret->next[next_symbol] = this->generate_itemset(h2); } } return ret; }
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------ Resource::ResourceId ResourcePool::GenerateResourceId(StorageLocation in_location, const std::string& in_filePath, const IResourceOptionsBaseCSPtr& in_options) const { std::string combined(ToString((u32)in_location) + in_filePath); u32 fileHash = HashCRC32::GenerateHashCode(combined); if(in_options == nullptr) { return fileHash; } u32 optionsHash = in_options->GenerateHash(); u64 combinedHash = fileHash + ((u64)(optionsHash) << 32); return HashCRC32::GenerateHashCode((const s8*)&combinedHash, sizeof(u64)); }
ListOptions::ListOptions(const std::string& userDefined, const std::string& forced) : all(false), longFormat(false), slashDirs(false), reverse(false), recursive(false), sizeSort(false), modTimeSort(false) { std::string combined(forced); combined += userDefined; for (char ch : combined) ParseOption(ch); }
std::vector<Genome*> MuPlusLambdaES::doReplacement( std::vector<Genome*> parents, std::vector<Genome*> offspring, std::vector<Fitness>& populationFitnesses, std::vector<ObjectiveFunction*> objectives ) { std::vector<Genome*> result, combined(parents); std::vector<Fitness> combinedFitnesses(populationFitnesses); combined.insert(combined.end(), offspring.begin(), offspring.end()); for (unsigned int i = 0; i < offspring.size(); i++) combinedFitnesses.push_back(this->evaluateFitness( offspring[i], objectives )); this->sortPopulation(combined, combinedFitnesses); for (unsigned int i = 0; i < parents.size(); i++) { result.push_back(combined[i]); populationFitnesses[i] = combinedFitnesses[i]; } return result; }
bool redblade_laser::findPole(geometry_msgs::Point& point, pcl::PointCloud<pcl::PointXYZ>::Ptr cluster, double tolerance){ boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> > combined(new pcl::PointCloud<pcl::PointXYZ>()); // boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> > // cluster(new pcl::PointCloud<pcl::PointXYZ>()); this->getClouds(combined); //ROS_INFO("Size of combined %d",combined->points.size()); if(combined->points.size()==0){ return false; } this->cluster(combined,cluster,tolerance); //ROS_INFO("Size of cluster %d",cluster->points.size()); if(cluster->points.size() < this->maxSize){ return false; } this->cloud2point(cluster,point); //this->cloud2point(combined,point); if(isnan(point.x) or isnan(point.y) or isnan(point.x)){ return false; } return true; }
// Gets the hue/sat/val for areas that we believe are license plate characters // Then uses that to filter the whole image and provide a mask. void ColorFilter::findCharColors() { int MINIMUM_SATURATION = 45; if (this->debug) cout << "ColorFilter::findCharColors" << endl; //charMask.copyTo(this->colorMask); this->colorMask = Mat::zeros(charMask.size(), CV_8U); bitwise_not(this->colorMask, this->colorMask); Mat erodedCharMask(charMask.size(), CV_8U); Mat element = getStructuringElement( 1, Size( 2 + 1, 2+1 ), Point( 1, 1 ) ); erode(charMask, erodedCharMask, element); vector<vector<Point> > contours; vector<Vec4i> hierarchy; findContours(erodedCharMask, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE); vector<float> hMeans, sMeans, vMeans; vector<float> hStdDevs, sStdDevs, vStdDevs; for (unsigned int i = 0; i < contours.size(); i++) { if (hierarchy[i][3] != -1) continue; Mat singleCharMask = Mat::zeros(hsv.size(), CV_8U); drawContours(singleCharMask, contours, i, // draw this contour cv::Scalar(255,255,255), // in CV_FILLED, 8, hierarchy ); // get rid of the outline by drawing a 1 pixel width black line drawContours(singleCharMask, contours, i, // draw this contour cv::Scalar(0,0,0), // in 1, 8, hierarchy ); //drawAndWait(&singleCharMask); Scalar mean; Scalar stddev; meanStdDev(hsv, mean, stddev, singleCharMask); if (this->debug) { cout << "ColorFilter " << setw(3) << i << ". Mean: h: " << setw(7) << mean[0] << " s: " << setw(7) <<mean[1] << " v: " << setw(7) << mean[2] << " | Std: h: " << setw(7) <<stddev[0] << " s: " << setw(7) <<stddev[1] << " v: " << stddev[2] << endl; } if (mean[0] == 0 && mean[1] == 0 && mean[2] == 0) continue; hMeans.push_back(mean[0]); sMeans.push_back(mean[1]); vMeans.push_back(mean[2]); hStdDevs.push_back(stddev[0]); sStdDevs.push_back(stddev[1]); vStdDevs.push_back(stddev[2]); } if (hMeans.size() == 0) return; int bestHueIndex = this->getMajorityOpinion(hMeans, .65, 30); int bestSatIndex = this->getMajorityOpinion(sMeans, .65, 35); int bestValIndex = this->getMajorityOpinion(vMeans, .65, 30); if (sMeans[bestSatIndex] < MINIMUM_SATURATION) return; bool doHueFilter = false, doSatFilter = false, doValFilter = false; float hueMin, hueMax; float satMin, satMax; float valMin, valMax; if (this->debug) cout << "ColorFilter Winning indices:" << endl; if (bestHueIndex != -1) { doHueFilter = true; hueMin = hMeans[bestHueIndex] - (2 * hStdDevs[bestHueIndex]); hueMax = hMeans[bestHueIndex] + (2 * hStdDevs[bestHueIndex]); if (abs(hueMin - hueMax) < 20) { hueMin = hMeans[bestHueIndex] - 20; hueMax = hMeans[bestHueIndex] + 20; } if (hueMin < 0) hueMin = 0; if (hueMax > 180) hueMax = 180; if (this->debug) cout << "ColorFilter Hue: " << bestHueIndex << " : " << setw(7) << hMeans[bestHueIndex] << " -- " << hueMin << "-" << hueMax << endl; } if (bestSatIndex != -1) { doSatFilter = true; satMin = sMeans[bestSatIndex] - (2 * sStdDevs[bestSatIndex]); satMax = sMeans[bestSatIndex] + (2 * sStdDevs[bestSatIndex]); if (abs(satMin - satMax) < 20) { satMin = sMeans[bestSatIndex] - 20; satMax = sMeans[bestSatIndex] + 20; } if (satMin < 0) satMin = 0; if (satMax > 255) satMax = 255; if (this->debug) cout << "ColorFilter Sat: " << bestSatIndex << " : " << setw(7) << sMeans[bestSatIndex] << " -- " << satMin << "-" << satMax << endl; } if (bestValIndex != -1) { doValFilter = true; valMin = vMeans[bestValIndex] - (1.5 * vStdDevs[bestValIndex]); valMax = vMeans[bestValIndex] + (1.5 * vStdDevs[bestValIndex]); if (abs(valMin - valMax) < 20) { valMin = vMeans[bestValIndex] - 20; valMax = vMeans[bestValIndex] + 20; } if (valMin < 0) valMin = 0; if (valMax > 255) valMax = 255; if (this->debug) cout << "ColorFilter Val: " << bestValIndex << " : " << setw(7) << vMeans[bestValIndex] << " -- " << valMin << "-" << valMax << endl; } Mat imgDebugHueOnly = Mat::zeros(hsv.size(), hsv.type()); Mat imgDebug = Mat::zeros(hsv.size(), hsv.type()); Mat imgDistanceFromCenter = Mat::zeros(hsv.size(), CV_8U); Mat debugMask = Mat::zeros(hsv.size(), CV_8U); bitwise_not(debugMask, debugMask); for (int row = 0; row < charMask.rows; row++) { for (int col = 0; col < charMask.cols; col++) { int h = (int) hsv.at<Vec3b>(row, col)[0]; int s = (int) hsv.at<Vec3b>(row, col)[1]; int v = (int) hsv.at<Vec3b>(row, col)[2]; bool hPasses = true; bool sPasses = true; bool vPasses = true; int vDistance = abs(v - vMeans[bestValIndex]); imgDebugHueOnly.at<Vec3b>(row, col)[0] = h; imgDebugHueOnly.at<Vec3b>(row, col)[1] = 255; imgDebugHueOnly.at<Vec3b>(row, col)[2] = 255; imgDebug.at<Vec3b>(row, col)[0] = 255; imgDebug.at<Vec3b>(row, col)[1] = 255; imgDebug.at<Vec3b>(row, col)[2] = 255; if (doHueFilter && (h < hueMin || h > hueMax)) { hPasses = false; imgDebug.at<Vec3b>(row, col)[0] = 0; debugMask.at<uchar>(row, col) = 0; } if (doSatFilter && (s < satMin || s > satMax)) { sPasses = false; imgDebug.at<Vec3b>(row, col)[1] = 0; } if (doValFilter && (v < valMin || v > valMax)) { vPasses = false; imgDebug.at<Vec3b>(row, col)[2] = 0; } //if (pixelPasses) // colorMask.at<uchar>(row, col) = 255; //else //imgDebug.at<Vec3b>(row, col)[0] = hPasses & 255; //imgDebug.at<Vec3b>(row, col)[1] = sPasses & 255; //imgDebug.at<Vec3b>(row, col)[2] = vPasses & 255; if ((hPasses) || (hPasses && sPasses))//(hPasses && vPasses) || (sPasses && vPasses) || this->colorMask.at<uchar>(row, col) = 255; else this->colorMask.at<uchar>(row, col) = 0; if ((hPasses && sPasses) || (hPasses && vPasses) || (sPasses && vPasses)) { vDistance = pow(vDistance, 0.9); } else { vDistance = pow(vDistance, 1.1); } if (vDistance > 255) vDistance = 255; imgDistanceFromCenter.at<uchar>(row, col) = vDistance; } } vector<Mat> debugImagesSet; if (this->debug) { debugImagesSet.push_back(addLabel(charMask, "Charecter mask")); //debugImagesSet1.push_back(erodedCharMask); Mat maskCopy(colorMask.size(), colorMask.type()); colorMask.copyTo(maskCopy); debugImagesSet.push_back(addLabel(maskCopy, "color Mask Before")); } Mat bigElement = getStructuringElement( 1, Size( 3 + 1, 3+1 ), Point( 1, 1 ) ); Mat smallElement = getStructuringElement( 1, Size( 1 + 1, 1+1 ), Point( 1, 1 ) ); morphologyEx(this->colorMask, this->colorMask, MORPH_CLOSE, bigElement); //dilate(this->colorMask, this->colorMask, bigElement); Mat combined(charMask.size(), charMask.type()); bitwise_and(charMask, colorMask, combined); if (this->debug) { debugImagesSet.push_back(addLabel(colorMask, "Color Mask After")); debugImagesSet.push_back(addLabel(combined, "Combined")); //displayImage(config, "COLOR filter Mask", colorMask); debugImagesSet.push_back(addLabel(imgDebug, "Color filter Debug")); cvtColor(imgDebugHueOnly, imgDebugHueOnly, CV_HSV2BGR); debugImagesSet.push_back(addLabel(imgDebugHueOnly, "Color Filter Hue")); equalizeHist(imgDistanceFromCenter, imgDistanceFromCenter); debugImagesSet.push_back(addLabel(imgDistanceFromCenter, "COLOR filter Distance")); debugImagesSet.push_back(addLabel(debugMask, "COLOR Hues off")); Mat dashboard = drawImageDashboard(debugImagesSet, imgDebugHueOnly.type(), 3); displayImage(config, "Color Filter Images", dashboard); } }
int main() { // Load images cv::Mat img1 = cv::imread("./output/ps0-1-a-1.png"); std::cout << img1.type() << std::endl; cv::Mat img2 = cv::imread("./output/ps0-1-a-2.png"); if (!img1.data) { std::cerr << "Could not open or find image 1" << std::endl; return -1; } else if (!img2.data){ std::cerr << "Could not open or find image 2" << std::endl; return -1; } // Extract color channels from image 1 std::vector<cv::Mat> channels(3); cv::split(img1, channels); // Swap channels cv::Mat temp(channels[0]); // Store blue channels[0] = channels[2]; // Swap blue with red channels[2] = temp; // Swap red with blue; // Save swapped image cv::Mat swapped1; cv::merge(channels, swapped1); cv::imwrite("./output/ps0-2-a-1.png", swapped1); cv::split(img1, channels); // Save red and img1_green channels of image 1 cv::Mat img1_green(channels[1]); cv::Mat img1_red(channels[2]); cv::imwrite("./output/ps0-2-b-1.png", img1_green); cv::imwrite("./output/ps0-2-c-1.png", img1_red); //Take the center square region of 100x100 pixels of img1_green // and insert them into the center of red cv::Rect r(img1_green.cols / 2 - 50, img1_green.rows / 2 - 50, 100, 100); cv::Mat combined = img1_red, green_roi = img1_green(r); green_roi.copyTo(combined(cv::Rect(combined.cols/2 - 50, combined.rows/2 - 50, 100, 100))); cv::imwrite("./output/ps0-3-a-1.png", combined); // Subtract the mean from all pixels, then divide by standard deviation, // then multiply by 10 and add the mean back in cv::Mat modified, mean, stdDev; cv::meanStdDev(img1_green, mean, stdDev); cv::subtract(img1_green, mean, modified); cv::divide(modified, stdDev, modified); cv::multiply(modified, 10, modified); cv::add(modified, mean, modified); cv::imwrite("./output/ps0-4-b-1.png", modified); // Shift img1_green to the left by 2 pixels cv::Mat shifted = cv::Mat::zeros(img1_green.size(), img1_green.type()); img1_green(cv::Rect(2, 0, img1_green.cols - 2, img1_green.rows)).copyTo( shifted(cv::Rect(0, 0, img1_green.cols - 2, img1_green.rows))); cv::imwrite("./output/ps0-4-c-1.png", shifted); // Subtract shifted from img1_green cv::Mat subtracted; cv::subtract(img1_green, shifted, subtracted); cv::imwrite("./output/ps0-4-d-1.png", subtracted); // Add Gaussian noise to img1's green channel cv::split(channels, img1); cv::Mat noise(img1.cols, img1.rows, img1.type()); cv::randn(noise, 0, 5); cv::normalize(noise, noise, 0, 255, CV_MINMAX, img1.type()); channels[1] += noise; cv::Mat green_noise; cv::merge(channels, green_noise); // display images // cv::imshow("Original Image 1", img1); // cv::imshow("Swapped Image 1", swapped1); cv::imshow("Green Image 1", img1_green); // cv::imshow("Red Image 1", img1_red); // cv::imshow("Combined", combined); // cv::imshow("Modified", modified); // cv::imshow("Shifted", shifted); // cv::imshow("Subtracted", subtracted); cv::imshow("Green Noise", green_noise); // std::string window2 = "Image 2"; // cv::namedWindow(window2); // cv::imshow(window2, img2); cv::waitKey(0); return 0; }
/* Any key combination is released. */ bool Controls::release(const int& pressedKey, const int& downedKey) const { return !combined(pressedKey, downedKey); }
void Traverse(State* state, ASTNode* node) { bool recurse = true; StructureScope scope; StructureScope* backup; // PRE switch (node->GetType()) { case ASTNode::Type::Root: *state->Data += string_format("namespace reflector {\n"); backup = state->StructScope; state->StructScope = &scope; state->StructScope->Name = "~ROOT~"; break; case ASTNode::Type::File: *state->Data += string_format("// FILE: \"%s\"\n", node->ToString().c_str()); break; case ASTNode::Type::Namespace: *state->Data += string_format("// NAMESPACE: \"%s\"\n", node->ToString().c_str()); break; case ASTNode::Type::Public: state->StructScope->VisibilityType = "Public"; break; case ASTNode::Type::Protected: state->StructScope->VisibilityType = "Protected"; break; case ASTNode::Type::Private: state->StructScope->VisibilityType = "Private"; break; case ASTNode::Type::Class: case ASTNode::Type::Struct: backup = state->StructScope; state->StructScope = &scope; state->StructScope->Name = node->ToString(); break; case ASTNode::Type::DclHead: // recurse these break; case ASTNode::Type::AntFwd: // ignore these case ASTNode::Type::AntBack: case ASTNode::Type::DclSub: recurse = false; break; default: *state->Data += string_format("// UNKNOWN: %s \"%s\"\n", node->GetTypeString(), node->ToString().c_str()); recurse = false; }; // recurse if (recurse) { auto& children = node->Children(); for (size_t i = 0; i < children.size(); i++) { Traverse(state, children[i]); } } // POST switch (node->GetType()) { case ASTNode::Type::DclSub: { ASTType* typeNode = (ASTType*)node; ASTType combined(typeNode->tokenSource); if (typeNode->head != 0) combined = typeNode->CombineWithHead(); else combined.MergeData(typeNode); state->StructScope->Members[Types::Member].push_back(vCount); *state->Data += string_format("StructureMember m_%d = { VisibilityEnum::%s, \"%s\", \"%s\", reflector_offsetof(%s, %s), reflector_sizeof(%s, %s), 1 };\n", vCount++, state->StructScope->VisibilityType, combined.ToIdentifierString().c_str(), combined.ToString(false).c_str(), state->StructScope->Name.c_str(), combined.ToIdentifierString().c_str(), state->StructScope->Name.c_str(), combined.ToIdentifierString().c_str()); recurse = false; break; } case ASTNode::Type::Root: *state->Data += string_format("} // end namespace reflector\n\n"); state->StructScope = backup; break; case ASTNode::Type::File: *state->Data += string_format("// END FILE: \"%s\"\n", node->ToString().c_str()); break; case ASTNode::Type::Class: case ASTNode::Type::Struct: // collect members std::string memberLocation = "0"; if (state->StructScope->Members[Types::Member].size() > 0) { std::string members; for (auto it : state->StructScope->Members[Types::Member]) { members += string_format("&m_%d,", it); } if (members.size() > 0) members.pop_back(); *state->Data += string_format("StructureMember* sm_%d[] = { %s };\n", vCount, members.c_str()); memberLocation = "sm_" + intToString(vCount); } const char* type = "Class"; if (node->GetType() == ASTNode::Type::Struct) type = "Struct"; *state->Data += string_format("Structure s_%d(VisibilityEnum::%s, Structure::Type::%s, \"%s\", %d, %s, 0, 0);\n", vCount++, state->StructScope->VisibilityType, type, node->ToString().c_str(), state->StructScope->Members[Types::Member].size(), memberLocation.c_str()); // return structscope state->StructScope = backup; break; }; }
int main(int argc, char *argv[]) { clock_t tStart, tStop; argc = 2; argv = new char*[argc]; argv[0] = "D:\\PCDs\\20140817\\0001.pcd"; argv[1] = "D:\\PCDs\\20140817\\0003.pcd"; std::vector <CloudPtr> clouds; int *returnVal = new int[1]; tStart = clock(); (*returnVal) = Utils::readPointClouds(argc, argv, clouds); if ((*returnVal) != 0) std::cerr << "An error occoured." << (*returnVal) << std::endl; tStop = clock(); std::cout << clouds.size() << " cloud(s) have been loaded." << std::endl << "Duration : " << (double)(tStop - tStart) / CLK_TCK << std::endl; CloudPtr cache(new Cloud()); Matrix4f matrix; GrayScaleRegistration gsr; gsr.getGrayScaleRegMatrix(clouds[0], clouds[1], matrix); Utils::transformPointCloud(clouds[1], cache, matrix); cache->swap(*clouds[1]); cache.reset(); pcl::KdTreeFLANN<Point>::Ptr tree(new pcl::KdTreeFLANN<Point>()); std::vector<int> kIndices; std::vector<float> kDistances; CloudPtr combined(new Cloud()); (*combined) = (*clouds[0]); (*combined) += (*clouds[1]); tree->setInputCloud(combined); int sum = 0; double colorRankMean = 0; tStart = clock(); for (int i = 0; i < combined->points.size() / 2; i++) { if (combined->points[i].z == combined->points[i].z) { tree->nearestKSearch(combined->points[i], 16, kIndices, kDistances); //tree->radiusSearch(combined->points[i], 0.015, kIndices, kDistances); int minIndice = -1; double minDistance = 1; for (int j = 1; j < kIndices.size(); j++) { if (kIndices[j] > combined->points.size() / 2 && kDistances[j] < minDistance) { minDistance = kDistances[j]; minIndice = j; } } if (minIndice != -1) { colorRankMean += colorRank(&(combined->points[i]), &(combined->points[kIndices[minIndice]])); markPair(combined->points[i], combined->points[kIndices[minIndice]]); sum++; } } } tStop = clock(); std::cout << "Find neighbors completed." << std::endl << "Pairs:" << sum << " Color Rank:" << colorRankMean << " Color Rank Mean:" << colorRankMean / sum << std::endl << "Duration : " << (double)(tStop - tStart) / CLK_TCK << std::endl; clouds.clear(); clouds.push_back(combined); Visualization::showMultiClouds(clouds, 1); delete returnVal; }
void AutoCaptureMechanism::CaptureAll() { // start from the first page m_notebook->SetSelection(0); wxYield(); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for (ControlList::iterator it = m_controlList.begin(); it != m_controlList.end(); ++it) { Control &ctrl = *it; if (ctrl.flag == AJ_TurnPage) // Turn to next page { m_notebook->SetSelection(m_notebook->GetSelection() + 1); wxYield(); continue; } // create the screenshot wxBitmap screenshot(1, 1); Capture(&screenshot, ctrl); if(ctrl.flag & AJ_Union) { // union screenshots until AJ_UnionEnd #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ do { ++it; it->name = ctrl.name; //preserving the name wxBitmap screenshot2(1, 1); Capture(&screenshot2, *it); wxBitmap combined(1, 1); Union(&screenshot, &screenshot2, &combined); screenshot = combined; } #if defined(__INTEL_COMPILER) && 0 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ while(!(it->flag & AJ_UnionEnd)); } // and save it Save(&screenshot, ctrl.name); } }
int main(int argc, char *argv[]) { int n = 10; int ierr = 0; double reltol = 1.0e-14; double abstol = 1.0e-14; int MyPID = 0; try { // Initialize MPI #ifdef HAVE_MPI MPI_Init(&argc,&argv); #endif // Create a communicator for Epetra objects #ifdef HAVE_MPI Epetra_MpiComm Comm( MPI_COMM_WORLD ); #else Epetra_SerialComm Comm; #endif MyPID = Comm.MyPID(); // Create the map Epetra_Map map(n, 0, Comm); bool verbose = false; // Check for verbose output if (argc>1) if (argv[1][0]=='-' && argv[1][1]=='v') verbose = true; // Seed the random number generator in Teuchos. We create random // bordering matrices and it is possible different processors might generate // different matrices. By setting the seed, this shouldn't happen. Teuchos::ScalarTraits<double>::seedrandom(12345); // Create and initialize the parameter vector LOCA::ParameterVector pVector; pVector.addParameter("Param 1", 1.69); pVector.addParameter("Param 2", -9.7); pVector.addParameter("Param 3", 0.35); pVector.addParameter("Param 4", -0.78); pVector.addParameter("Param 5", 2.53); // Create parameter list Teuchos::RCP<Teuchos::ParameterList> paramList = Teuchos::rcp(new Teuchos::ParameterList); Teuchos::ParameterList& nlParams = paramList->sublist("NOX"); Teuchos::ParameterList& nlPrintParams = nlParams.sublist("Printing"); nlPrintParams.set("MyPID", MyPID); if (verbose) nlPrintParams.set("Output Information", NOX::Utils::Error + NOX::Utils::Details + NOX::Utils::OuterIteration + NOX::Utils::InnerIteration + NOX::Utils::Warning + NOX::Utils::TestDetails + NOX::Utils::StepperIteration + NOX::Utils::StepperDetails); else nlPrintParams.set("Output Information", NOX::Utils::Error); // Create global data object Teuchos::RCP<LOCA::GlobalData> globalData = LOCA::createGlobalData(paramList); Epetra_Vector clone_vec(map); NOX::Epetra::Vector nox_clone_vec(clone_vec); Teuchos::RCP<NOX::Abstract::Vector> x = nox_clone_vec.clone(NOX::ShapeCopy); x->random(); Teuchos::RCP<NOX::Abstract::MultiVector> dx1 = nox_clone_vec.createMultiVector(3); Teuchos::RCP<NOX::Abstract::MultiVector> dx2 = nox_clone_vec.createMultiVector(1); Teuchos::RCP<NOX::Abstract::MultiVector> dx3 = nox_clone_vec.createMultiVector(2); Teuchos::RCP<NOX::Abstract::MultiVector> dx4 = nox_clone_vec.createMultiVector(2); dx1->random(); dx2->random(); dx3->init(0.0); dx4->random(); Teuchos::RCP<NOX::Abstract::MultiVector> dx_all = dx1->clone(NOX::DeepCopy); dx_all->augment(*dx2); dx_all->augment(*dx3); dx_all->augment(*dx4); NOX::Abstract::MultiVector::DenseMatrix dp1(dx1->numVectors(), pVector.length()); NOX::Abstract::MultiVector::DenseMatrix dp2(dx2->numVectors(), pVector.length()); NOX::Abstract::MultiVector::DenseMatrix dp3(dx3->numVectors(), pVector.length()); NOX::Abstract::MultiVector::DenseMatrix dp4(dx4->numVectors(), pVector.length()); dp1.random(); dp2.random(); dp3.random(); dp4.random(); NOX::Abstract::MultiVector::DenseMatrix dp_all(dx_all->numVectors(), pVector.length()); for (int j=0; j<dp_all.numCols(); j++) { for (int i=0; i<dp1.numRows(); i++) dp_all(i,j) = dp1(i,j); for (int i=0; i<dp2.numRows(); i++) dp_all(dp1.numRows()+i,j) = dp2(i,j); for (int i=0; i<dp3.numRows(); i++) dp_all(dp1.numRows()+dp2.numRows()+i,j) = dp3(i,j); for (int i=0; i<dp4.numRows(); i++) dp_all(dp1.numRows()+dp2.numRows()+dp3.numRows()+i,j) = dp4(i,j); } std::vector< Teuchos::RCP<LOCA::MultiContinuation::ConstraintInterface> > constraintObjs(4); Teuchos::RCP<LinearConstraint> linear_constraint; linear_constraint = Teuchos::rcp(new LinearConstraint(dx1->numVectors(), pVector, nox_clone_vec)); linear_constraint->setDgDx(*dx1); linear_constraint->setDgDp(dp1); linear_constraint->setIsZeroDX(false); constraintObjs[0] = linear_constraint; linear_constraint = Teuchos::rcp(new LinearConstraint(dx2->numVectors(), pVector, nox_clone_vec)); linear_constraint->setDgDx(*dx2); linear_constraint->setDgDp(dp2); linear_constraint->setIsZeroDX(false); constraintObjs[1] = linear_constraint; linear_constraint = Teuchos::rcp(new LinearConstraint(dx3->numVectors(), pVector, nox_clone_vec)); linear_constraint->setDgDx(*dx3); linear_constraint->setDgDp(dp3); linear_constraint->setIsZeroDX(true); constraintObjs[2] = linear_constraint; linear_constraint = Teuchos::rcp(new LinearConstraint(dx4->numVectors(), pVector, nox_clone_vec)); linear_constraint->setDgDx(*dx4); linear_constraint->setDgDp(dp4); linear_constraint->setIsZeroDX(false); constraintObjs[3] = linear_constraint; // Check some statistics on the solution NOX::TestCompare testCompare(globalData->locaUtils->out(), *(globalData->locaUtils)); LOCA::MultiContinuation::CompositeConstraint composite(globalData, constraintObjs); composite.setX(*x); LinearConstraint combined(dx_all->numVectors(), pVector, nox_clone_vec); combined.setDgDx(*dx_all); combined.setDgDp(dp_all); combined.setX(*x); // // test computeConstraints() // composite.computeConstraints(); combined.computeConstraints(); int numConstraints = dx_all->numVectors(); const NOX::Abstract::MultiVector::DenseMatrix& g_composite = composite.getConstraints(); const NOX::Abstract::MultiVector::DenseMatrix& g_combined = combined.getConstraints(); ierr += testCompare.testMatrix( g_composite, g_combined, reltol, abstol, "CompositeConstraint::computeConstraints()"); // // test computeDP() // std::vector<int> paramIDs(3); paramIDs[0] = 1; paramIDs[1] = 2; paramIDs[2] = 4; NOX::Abstract::MultiVector::DenseMatrix dgdp_composite( numConstraints, paramIDs.size()+1); NOX::Abstract::MultiVector::DenseMatrix dgdp_combined( numConstraints, paramIDs.size()+1); dgdp_composite.putScalar(0.0); dgdp_combined.putScalar(0.0); composite.computeDP(paramIDs, dgdp_composite, false); combined.computeDP(paramIDs, dgdp_combined, false); ierr += testCompare.testMatrix( dgdp_composite, dgdp_combined, reltol, abstol, "CompositeConstraint::computeDP()"); // // test multiplyDX() // composite.computeDX(); combined.computeDX(); int numMultiply = 5; Teuchos::RCP<NOX::Abstract::MultiVector> A = nox_clone_vec.createMultiVector(numMultiply); A->random(); NOX::Abstract::MultiVector::DenseMatrix composite_multiply(numConstraints, numMultiply); NOX::Abstract::MultiVector::DenseMatrix combined_multiply(numConstraints, numMultiply); composite.multiplyDX(2.65, *A, composite_multiply); combined.multiplyDX(2.65, *A, combined_multiply); ierr += testCompare.testMatrix(composite_multiply, combined_multiply, reltol, abstol, "CompositeConstraint::multiplyDX()"); // // test addDX() (No Trans) // int numAdd = 5; NOX::Abstract::MultiVector::DenseMatrix B1(numConstraints, numAdd); B1.random(); NOX::Abstract::MultiVector::DenseMatrix B2(numAdd, numConstraints); B2.random(); Teuchos::RCP<NOX::Abstract::MultiVector> composite_add1 = nox_clone_vec.createMultiVector(numAdd); composite_add1->random(); Teuchos::RCP<NOX::Abstract::MultiVector> composite_add2 = nox_clone_vec.createMultiVector(numAdd); composite_add2->random(); Teuchos::RCP<NOX::Abstract::MultiVector> combined_add1 = composite_add1->clone(NOX::DeepCopy); Teuchos::RCP<NOX::Abstract::MultiVector> combined_add2 = composite_add2->clone(NOX::DeepCopy); composite.addDX(Teuchos::NO_TRANS, 1.45, B1, 2.78, *composite_add1); combined.addDX(Teuchos::NO_TRANS, 1.45, B1, 2.78, *combined_add1); ierr += testCompare.testMultiVector( *composite_add1, *combined_add1, reltol, abstol, "CompositeConstraint::addDX() (No Trans)"); // // test addDX() (Trans) // composite.addDX(Teuchos::TRANS, 1.45, B2, 2.78, *composite_add2); combined.addDX(Teuchos::TRANS, 1.45, B2, 2.78, *combined_add2); ierr += testCompare.testMultiVector( *composite_add2, *combined_add2, reltol, abstol, "CompositeConstraint::addDX() (Trans)"); LOCA::destroyGlobalData(globalData); } catch (std::exception& e) { std::cout << e.what() << std::endl; ierr = 1; } catch (const char *s) { std::cout << s << std::endl; ierr = 1; } catch (...) { std::cout << "Caught unknown exception!" << std::endl; ierr = 1; } if (MyPID == 0) { if (ierr == 0) std::cout << "All tests passed!" << std::endl; else std::cout << ierr << " test(s) failed!" << std::endl; } #ifdef HAVE_MPI MPI_Finalize() ; #endif return ierr; }
bool WebSocketHandshake(nsTArray<nsCString>& aProtocolString) { nsresult rv; bool isWebSocket = false; nsCString version; nsCString wsKey; nsCString protocol; // Validate WebSocket client request. if (aProtocolString.Length() == 0) return false; // Check that the HTTP method is GET const char* HTTP_METHOD = "GET "; if (strncmp(aProtocolString[0].get(), HTTP_METHOD, strlen(HTTP_METHOD)) != 0) { return false; } for (uint32_t i = 1; i < aProtocolString.Length(); ++i) { const char* line = aProtocolString[i].get(); const char* prop_pos = strchr(line, ':'); if (prop_pos != nullptr) { nsCString key(line, prop_pos - line); nsCString value(prop_pos + 2); if (key.EqualsIgnoreCase("upgrade") && value.EqualsIgnoreCase("websocket")) { isWebSocket = true; } else if (key.EqualsIgnoreCase("sec-websocket-version")) { version = value; } else if (key.EqualsIgnoreCase("sec-websocket-key")) { wsKey = value; } else if (key.EqualsIgnoreCase("sec-websocket-protocol")) { protocol = value; } } } if (!isWebSocket) { return false; } if (!(version.Equals("7") || version.Equals("8") || version.Equals("13"))) { return false; } if (!(protocol.EqualsIgnoreCase("binary"))) { return false; } // Client request is valid. Start to generate and send server response. nsAutoCString guid("258EAFA5-E914-47DA-95CA-C5AB0DC85B11"); nsAutoCString res; SHA1Sum sha1; nsCString combined(wsKey + guid); sha1.update(combined.get(), combined.Length()); uint8_t digest[SHA1Sum::HashSize]; // SHA1 digests are 20 bytes long. sha1.finish(digest); nsCString newString(reinterpret_cast<char*>(digest), SHA1Sum::HashSize); Base64Encode(newString, res); nsCString response("HTTP/1.1 101 Switching Protocols\r\n"); response.Append("Upgrade: websocket\r\n"); response.Append("Connection: Upgrade\r\n"); response.Append(nsCString("Sec-WebSocket-Accept: ") + res + nsCString("\r\n")); response.Append("Sec-WebSocket-Protocol: binary\r\n\r\n"); uint32_t written = 0; uint32_t size = response.Length(); while (written < size) { uint32_t cnt; rv = mOutputStream->Write(const_cast<char*>(response.get()) + written, size - written, &cnt); if (NS_FAILED(rv)) return false; written += cnt; } mOutputStream->Flush(); return true; }
int main() { // read the image cv::Mat image= cv::imread(IMAGE_FOLDER "/boldt.jpg"); if (!image.data) return 0; // show original image cv::namedWindow("Original image"); cv::imshow("Original image",image); // convert into HSV space cv::Mat hsv; cv::cvtColor(image, hsv, CV_BGR2HSV); // split the 3 channels into 3 images std::vector<cv::Mat> channels; cv::split(hsv,channels); // channels[0] is the Hue // channels[1] is the Saturation // channels[2] is the Value // display value cv::namedWindow("Value"); cv::imshow("Value",channels[2]); // display saturation cv::namedWindow("Saturation"); cv::imshow("Saturation",channels[1]); // display hue cv::namedWindow("Hue"); cv::imshow("Hue",channels[0]); // image with fixed value cv::Mat newImage; cv::Mat tmp(channels[2].clone()); // Value channel will be 255 for all pixels channels[2]= 255; // merge back the channels cv::merge(channels,hsv); // re-convert to BGR cv::cvtColor(hsv,newImage,CV_HSV2BGR); cv::namedWindow("Fixed Value Image"); cv::imshow("Fixed Value Image",newImage); // image with fixed saturation channels[1]= 255; channels[2]= tmp; cv::merge(channels,hsv); cv::cvtColor(hsv,newImage,CV_HSV2BGR); cv::namedWindow("Fixed saturation"); cv::imshow("Fixed saturation",newImage); // image with fixed value and fixed saturation channels[1]= 255; channels[2]= 255; cv::merge(channels,hsv); cv::cvtColor(hsv,newImage,CV_HSV2BGR); cv::namedWindow("Fixed saturation/value"); cv::imshow("Fixed saturation/value",newImage); // Testing skin detection // read the image image= cv::imread(IMAGE_FOLDER "/girl.jpg"); if (!image.data) return 0; // show original image cv::namedWindow("Original image"); cv::imshow("Original image",image); // detect skin tone cv::Mat mask; detectHScolor(image, 160, 10, // hue from 320 degrees to 20 degrees 25, 166, // saturation from ~0.1 to 0.65 mask); // show masked image cv::Mat detected(image.size(), CV_8UC3, cv::Scalar(0, 0, 0)); image.copyTo(detected, mask); cv::imshow("Detection result",detected); // A test comparing luminance and brightness // create linear intensity image cv::Mat linear(100,256,CV_8U); for (int i=0; i<256; i++) { linear.col(i)= i; } // create a Lab image linear.copyTo(channels[0]); cv::Mat constante(100,256,CV_8U,cv::Scalar(128)); constante.copyTo(channels[1]); constante.copyTo(channels[2]); cv::merge(channels,image); // convert back to BGR cv::Mat brightness; cv::cvtColor(image,brightness, CV_Lab2BGR); cv::split(brightness, channels); // create combined image cv::Mat combined(200,256, CV_8U); cv::Mat half1(combined,cv::Rect(0,0,256,100)); linear.copyTo(half1); cv::Mat half2(combined,cv::Rect(0,100,256,100)); channels[0].copyTo(half2); cv::namedWindow("Luminance vs Brightness"); cv::imshow("Luminance vs Brightness",combined); cv::waitKey(); }