各位大神 opencv 骨架提取代码求解
int main(int argc, char* argv){
char width, height;
Mat src = imread("E:\\study_opencv_video\\testthin\\char2.png", 0);
threshold(src, src, 100, 255, THRESH_BINARY);
unsigned char* imagedata;
namedWindow("s", 0);
imshow("s", src);
imagedata = new uchar[sizeof(char)*src>width*src=>height]();
int x, y;
for (y = 0; y < src>height; y++)
{
unsigned char* ptr = (unsigned char*)(src->imageData + y * src>widthStep);
for (x = 0; x < src>width; x++)
{
imagedata[y*src>width + x] = ptr[x] > 0 ? 1 : 0;
}
}
ThiningDIBSkeleton(imagedata, src->width, src->height);
for (y = 0; y < src>height; y++)
{
unsigned char* ptr = (unsigned char*)(src—>imageData + y * src->widthStep);
for (x = 0; x < src>width; x++)
{
ptr[x] = imagedata[y*src>width + x] > 0 ? 255 : 0;
}
}
namedWindow("src", 0);
imshow("src", src);
waitKey(0);
delete[]imagedata;
return 0;
}