void Skeletonize(const DataTypes::BinaryImage& inputImage, DataTypes::BinaryImage& outputImage, int iterations) { static DataTypes::BinaryImage tempImage; tempImage.rows = tempImage.maxRows; tempImage.cols = tempImage.maxCols; static DataTypes::BinaryImage erodedImage; erodedImage.rows = erodedImage.maxRows; erodedImage.cols = erodedImage.maxCols; static DataTypes::BinaryImage skelImage; skelImage.rows = skelImage.maxRows; skelImage.cols = skelImage.maxCols; inputImage.CopyTo(outputImage); for(int y=0; y<skelImage.rows; y++) { for(int x=0; x<skelImage.cols; x++) { skelImage.data[y][x] = false; } } //cv::Mat skel(img.size(), CV_8UC1, cv::Scalar(0)); cv::Mat img(DEPTH_RES_Y, DEPTH_RES_X, CV_8U, (void*)outputImage.data); cv::Mat skel(DEPTH_RES_Y, DEPTH_RES_X, CV_8U, (void*)skelImage.data); cv::Mat temp(DEPTH_RES_Y, DEPTH_RES_X, CV_8U, (void*)tempImage.data); cv::Mat eroded(DEPTH_RES_Y, DEPTH_RES_X, CV_8U, (void*)erodedImage.data); cv::Mat element = cv::getStructuringElement(cv::MORPH_CROSS, cv::Size(3, 3)); bool done; do { cv::erode(img, eroded, element); cv::dilate(eroded, temp, element); // temp = open(img) cv::subtract(img, temp, temp); cv::bitwise_or(skel, temp, skel); eroded.copyTo(img); done = (cv::norm(img) == 0); } while (!done); skelImage.CopyTo(outputImage); return; }
void imageProcess::skelMaker() { cv::Mat skel(frame->size(), CV_8U, cv::Scalar(0)); cv::Mat temp(frame->size(), CV_8U); cv::Mat eroded(frame->size(), CV_8U); cv::Mat original(frame->size(), CV_8U); frame->copyTo(original); cv::Mat element = cv::getStructuringElement(cv::MORPH_CROSS, cv::Size(3, 3)); bool done; do { cv::erode(original, eroded, element); cv::dilate(eroded, temp, element); // temp = open(img) cv::subtract(original, temp, temp); cv::bitwise_or(skel, temp, skel); eroded.copyTo(original); done = (cv::countNonZero(original) == 0); } while (!done); //Copy the skeleton to the output variable skel.copyTo(*frame); }