Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add alternative thinning method (skeletonize) #263

Merged
merged 1 commit into from
Sep 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions libs/ofxCv/include/ofxCv/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,30 @@ namespace ofxCv {
for(int i=0;i<n;i++){int j=q[i];if(!p[j+ic2]&&!p[j+ic1]&&!p[j+ib1]&&p[j+ia2]&&p[j+ib3]){p[j]=0;}}
for(int i=0;i<n;i++){int j=q[i];if(!p[j+ib1]&&!p[j+ia1]&&!p[j+ia2]&&p[j+ic2]&&p[j+ib3]){p[j]=0;}}
}

//same as above, different implementation taken from
//http://felix.abecassis.me/2011/09/opencv-morphological-skeleton/
template <class T>
void thin2(T& img) {

cv::Mat mat = toCv(img);
cv::Mat skel(mat.size(), CV_8UC1, cv::Scalar(0));
cv::Mat temp;
cv::Mat eroded;

cv::Mat element = cv::getStructuringElement(cv::MORPH_CROSS, cv::Size(3, 3));
bool done;
do{
cv::erode(mat, eroded, element);
cv::dilate(eroded, temp, element);
cv::subtract(mat, temp, temp);
cv::bitwise_or(skel, temp, skel);
eroded.copyTo(mat);
done = (cv::countNonZero(mat) == 0);
} while (!done);
skel.copyTo(mat);
return;
}

// given a vector of lines, this function will find the average angle
float weightedAverageAngle(const std::vector<cv::Vec4i>& lines);
Expand Down