void testA2VColor() { std::cout << "a2vectorTest testA2VColor" << std::endl; aam::Vertices2DList vertices(TOTAL_POINTS_NUMBER); aam::Vertices2DList basePoints(TOTAL_POINTS_NUMBER); for (int i = 0; i < TOTAL_POINTS_NUMBER; i++) { vertices[i].y = verticesAData[2 * i]; vertices[i].x = verticesAData[2 * i + 1]; basePoints[i].y = basePointsData[2 * i]; basePoints[i].x = basePointsData[2 * i + 1]; } std::vector<cv::Vec3i> triangles(TRIANGLES_NUMBER); for (int i = 0; i < TRIANGLES_NUMBER; i++) { triangles[i] = cv::Vec3i(&trianglesData[i * 3]); } try { cv::Mat im = cv::imread("data/01-1m.jpg"); cv::Mat_<cv::Vec<aam::RealType, 3> > colorImage = cv::Mat_<cv::Vec<aam::RealType, 3> >(im) / 255.0; cv::Mat objectPixels = cv::imread("data/object_pixels.bmp", cv::IMREAD_GRAYSCALE); int nCount = cv::countNonZero(objectPixels); cv::Mat J; aam::RealMatrix grayVector; aam::AAMFunctions2D::appearance2Vector(colorImage, vertices, basePoints, objectPixels, nCount, triangles, J, grayVector); // cv::imshow("test", J); // cv::waitKey(0); if (J.cols != objectPixels.cols || J.rows != objectPixels.rows) { std::cout << "%TEST_FAILED% time=0 testname=testA2VColor (a2vectorTest) message=Invalid output texture size" << std::endl; } else if (J.channels() != 3) { std::cout << "%TEST_FAILED% time=0 testname=testA2VColor (a2vectorTest) message=Invalid output texture channels count" << std::endl; } else if (grayVector.cols != 1 || grayVector.rows != 3 * 52314) { std::cout << "%TEST_FAILED% time=0 testname=testA2VColor (a2vectorTest) message=Invalid output vector size" << std::endl; } } catch (std::exception& e) { std::cout << "%TEST_FAILED% time=0 testname=testA2VColor (a2vectorTest) message=Exception occured: " << e.what() << std::endl; } }
void HeightMapUpdateTask::createHeightMapSegments() { for (SegmentStore::const_iterator I = mSegments.begin(); I != mSegments.end(); ++I) { Mercator::Segment* segment = *I; if (segment) { IHeightMapSegment* heightMapSegment = 0; Mercator::Matrix<2, 2, Mercator::BasePoint>& basePoints(segment->getControlPoints()); //If all of the base points are on the same level, and there are no mods, we know that the segment is completely flat, and we can save some memory by using a HeightMapFlatSegment instance. if (WFMath::Equal(basePoints[0].height(), basePoints[1].height()) && WFMath::Equal(basePoints[1].height(), basePoints[2].height()) && WFMath::Equal(basePoints[2].height(), basePoints[3].height()) && (segment->getMods().empty())) { heightMapSegment = new HeightMapFlatSegment(basePoints[0].height()); } else { HeightMapBuffer* buffer = mProvider.checkout(); if (buffer) { memcpy(buffer->getBuffer()->getData(), segment->getPoints(), sizeof(float) * segment->getSize() * segment->getSize()); heightMapSegment = new HeightMapSegment(buffer); } } if (heightMapSegment) { mHeightMapSegments.emplace_back(WFMath::Point<2>(segment->getXRef() / segment->getResolution(), segment->getZRef() / segment->getResolution()), heightMapSegment); } } } }
void testMakeAppearanceColor() { std::cout << "mappearanceTest testMakeAppearanceColor" << std::endl; aam::Vertices2DList verticesA(TOTAL_POINTS_NUMBER), verticesB(TOTAL_POINTS_NUMBER); aam::Vertices2DList meansVertices(TOTAL_POINTS_NUMBER); aam::Vertices2DList basePoints(TOTAL_POINTS_NUMBER); for (int i = 0; i < TOTAL_POINTS_NUMBER; i++) { verticesA[i].y = verticesAData[i * 2]; verticesA[i].x = verticesAData[i * 2 + 1]; verticesB[i].y = verticesBData[i * 2]; verticesB[i].x = verticesBData[i * 2 + 1]; meansVertices[i].y = meansData[i]; meansVertices[i].x = meansData[i + TOTAL_POINTS_NUMBER]; basePoints[i].y = basePointsData[2 * i]; basePoints[i].x = basePointsData[2 * i + 1]; } aam::ShapeData shapeData; shapeData.xMean = meansVertices; shapeData.lines = boost::assign::list_of<int> (0) (38) (37) (36) (31) (32) (33) (12) (11) (10) (9) (8) (7) (6) (5) (4) (3) (2) (1); shapeData.textureSize = cv::Size(255, 255); try { cv::Mat im = cv::imread("data/IMM/01-1m.jpg"); std::vector<aam::TrainModelInfo> trainData(2); trainData[0].setVertices(verticesA); trainData[0].setImage(im, false); im = cv::imread("data/IMM/01-2m.jpg"); trainData[1].setVertices(verticesB); trainData[1].setImage(im, false); aam::CommonFunctions::delaunay(verticesA, shapeData.triangles); aam::AppearanceData appearanceData; aam::AAMFunctions2D::makeAppearanceModel( trainData, shapeData, aam::AAMFunctions2D::DEFAULT_PCA_CUT_THRESOLD, appearanceData); cv::Mat objectPixels = cv::imread("data/object_pixels_synth.bmp", cv::IMREAD_GRAYSCALE); for (int i = 0; i < std::min(3, appearanceData.eigenVectors.cols); i++) { aam::RealMatrix eigv = appearanceData.eigenVectors.col(i); aam::RealType minElemR = *std::min_element(eigv.begin(), eigv.begin() + appearanceData.nPixels); aam::RealType maxElemR = *std::max_element(eigv.begin(), eigv.begin() + appearanceData.nPixels); aam::RealType minElemG = *std::min_element( eigv.begin() + appearanceData.nPixels, eigv.begin() + 2 * appearanceData.nPixels); aam::RealType maxElemG = *std::max_element( eigv.begin() + appearanceData.nPixels, eigv.begin() + 2 * appearanceData.nPixels); aam::RealType minElemB = *std::min_element( eigv.begin() + 2 * appearanceData.nPixels, eigv.begin() + 3 * appearanceData.nPixels); aam::RealType maxElemB = *std::max_element( eigv.begin() + 2 * appearanceData.nPixels, eigv.begin() + 3 * appearanceData.nPixels); cv::Mat result; aam::AAMFunctions2D::vector2Appearance( appearanceData.eigenVectors.col(i), objectPixels, cv::Size(255, 255), result); std::vector<cv::Mat> channels; cv::split(result, channels); channels[0] = (channels[0] - minElemR) / (maxElemR - minElemR); channels[1] = (channels[1] - minElemG) / (maxElemG - minElemG); channels[2] = (channels[2] - minElemB) / (maxElemB - minElemB); std::ostringstream winName; cv::Mat img; cv::merge(channels, img); winName << "eigen appearance " << i + 1; cv::imshow(winName.str(), img); } cv::waitKey(0); if (appearanceData.basePoints.size() != TOTAL_POINTS_NUMBER) { std::cout << "%TEST_FAILED% time=0 testname=testMakeAppearanceColor (mappearanceTest) message=Invalid base points array size" << std::endl; } else if (cv::countNonZero(cv::abs( aam::pointVector2Mat(aam::operator -(appearanceData.basePoints, basePoints))) > 1e-6)) { std::cout << "%TEST_FAILED% time=0 testname=testMakeAppearanceColor (mappearanceTest) message=Invalid base points array data" << std::endl; } } catch (std::exception& e) { std::cout << "%TEST_FAILED% time=0 testname=testMakeAppearance (mappearanceTest) message=Exception occured: " << e.what() << std::endl; } }