注册 登录
编程论坛 C++教室

各位大神 opencv 骨架提取代码求解

chen_le 发布于 2019-03-08 13:26, 2266 次点击
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;
}
3 回复
#2
rjsp2019-03-08 14:47
为什么连你想问什么都不肯告诉别人?
#3
chen_le2019-03-10 10:34
回复 楼主 chen_le
抱歉 最开始是没看懂程序,后来运行发现提示ThiningDIBSkeleton(imagedata, src->width, src->height)仅有一个参数,请问一下怎么解决
#4
Jonny02012019-03-10 11:41
我查了一下官方文档
OpenCV 的库里面好像没有自带这个骨架化的函数
所以这个应该是你自己写的
你把这个函数也贴出来看一下
1