精华内容
下载资源
问答
  • Python,OpenCV骨架化图像并显示(skeletonize)

    Python,OpenCV骨架化图像并显示(skeletonize)

    1. 效果图

    自己画一张图,原图 VS 骨架效果图如下:
    在这里插入图片描述
    opencv logo原图 VS 骨架化效果图如下:
    在这里插入图片描述

    2. 源码

    # 图像骨架化~
    
    import cv2
    import imutils
    import numpy as np
    
    img = np.zeros((390, 390, 3), dtype="uint8")
    cv2.putText(img, "Beautiful Girl.....", (50, 190), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 3)
    cv2.imshow("img", img)
    cv2.waitKey(0)
    cv2.imwrite("j.jpg", img)
    
    # 骨架图依赖灰度图
    
    # 灰度图转换法一
    img = cv2.imread('opencv_logo.jpg')  # 读取为BGR图
    cv2.imshow("origin", img)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)  # BGR图转换灰度图
    
    # 灰度图转换二
    gray = cv2.imread('opencv_logo.jpg', 0)  # 直接读取为灰度图
    cv2.imshow("gray", gray)
    
    # 骨架化图像
    skeleton = imutils.skeletonize(gray, size=(3, 3))
    cv2.imshow("Skeleton", skeleton)
    cv2.waitKey(0)
    

    参考:

    展开全文
  • 思路其实不是特别好,也尝试过把激光线骨架化再拟合: #骨架化 import os import numpy as np import cv2 import sys from PIL import Image im = cv2.imread('0.jpg', 0) ret, im = cv2.threshold(im, 127, 255, cv...

    思路:

    1、摄像头和激光笔要产生夹角,人为让激光线产生落差

    2、降低摄像头亮度,不然会在提取激光线的产生各种光斑干扰

    3、BGR转HSV提取红色区域,如果效果不好再加OTSU二值分割

    4、霍夫直线检测

    5、检测直线对掩码图做差

    6、形态学操作处理噪点

    import os
    from PIL import Image
    import cv2
    import numpy as np
    import math
    index = 0
    def morphology(img):
        ret,thresh2 = cv2.threshold(img,0,255,cv2.THRESH_BINARY + cv2.THRESH_OTSU)
        kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(5,5))
        op_close = cv2.morphologyEx(thresh2, cv2.MORPH_CLOSE, kernel)
        op_open = cv2.morphologyEx(op_close, cv2.MORPH_OPEN, kernel)
        return op_open
    def mask(img_mask,raw):
        img_mask_1,img_mask_2,img_mask_3 = cv2.split(img_mask)
        x = np.zeros(img_mask_2.shape).astype('uint8')
        img_mask_x = cv2.merge([x,img_mask_1,x])
        masked = cv2.add(raw, img_mask_x)
        return masked
    def extract_red(img):
        img_hsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
        rows, cols, channels = img.shape
        lower_red = np.array([0, 43, 46])
        upper_red = np.array([10, 255, 255])
        mask0 = cv2.inRange(img_hsv,lower_red,upper_red)
        lower_red = np.array([156, 43, 46])
        upper_red = np.array([180, 255, 255])
        mask1 = cv2.inRange(img_hsv,lower_red,upper_red)
        maskpp = mask0 + mask1
        return maskpp
    def operation(img):
        img = cv2.resize(img, (1152,648))
        raw = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
        raw_gray = cv2.cvtColor(raw,cv2.COLOR_RGB2GRAY)
        kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(5, 5))
        eroded = cv2.erode(raw_gray,kernel)
        lines = cv2.HoughLinesP(eroded,1,np.pi/180,60,minLineLength=100,maxLineGap=20)     
        if lines is not None:
            line = lines[:,0,:]
            sums = np.zeros(raw_gray.shape).astype('uint8')
            for x1,y1,x2,y2 in line[:]:
                mask_line = np.zeros(raw_gray.shape).astype('uint8')
                cv2.line(mask_line,(x1,y1),(x2,y2),(255,255,255),1)        
                b,g,r  = cv2.split(raw)
                img2subtraction = cv2.subtract(mask_line,b)
                sums = sums + img2subtraction
                sums[ sums > 255 ] = 255
            return sums
        else:
            sums =  np.zeros(raw_gray.shape).astype('uint8')
            return sums
    def get_length(x1,y1,x2,y2):
        point1=np.array([x1,y1])
        point2=np.array([x2,y2])
        x=point2-point1
        res=math.hypot(x[0],x[1])
        return res
    def get_gradient(x1,y1,x2,y2):
        if x1 != x2 :
            k = (y2-y1) / (x2-x1)
            return k
        else:
            k = 0
            return k
    def start(img):
        masks = extract_red(img)
        sums = operation(masks)
        return sums
    
    
    cap = cv2.VideoCapture("0.mp4")
    while(1):
        ret, frame = cap.read()
        img = cv2.resize(frame, (1152,648))
        frame = start(img)
        img = cv2.resize(img, (1152,648))
        raw = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
        frame = start(img)
        frame = morphology(frame)
        
        #内容来自https://blog.csdn.net/Andrwin欢迎关注
        frame = cv2.merge([frame,frame,frame])
        sums = mask(frame,raw)
        frame = cv2.cvtColor(sums,cv2.COLOR_BGR2RGB)
        cv2.putText(frame, str(index), (50, 50), cv2.FONT_HERSHEY_TRIPLEX, 1.2, (255, 255, 255), 2)
        cv2.imshow("capture", frame)
        
        index = index+1
        if cv2.waitKey(100) & 0xFF == ord('q'):
            break
        if index == 85:
            cap.release()
            cv2.destroyAllWindows() 
    cap.release()
    cv2.destroyAllWindows() 

    我把缺口部分画成了绿色,看起来比较明显

    思路其实不是特别好,也尝试过把激光线骨架化再拟合:

    #骨架化
    import os
    import numpy as np
    import cv2
    import sys
    from PIL import Image
    im = cv2.imread('0.jpg', 0)
    ret, im = cv2.threshold(im, 127, 255, cv2.THRESH_BINARY)
    element = cv2.getStructuringElement(cv2.MORPH_CROSS, (3,3))
    skel = np.zeros(im.shape, np.uint8)
    erode = np.zeros(im.shape, np.uint8)
    temp = np.zeros(im.shape, np.uint8)
    i = 0
    while True:
        erode = cv2.erode(im,element)
        temp  = cv2.dilate(erode, element)
        temp = cv2.subtract(im, temp)
        skel = cv2.bitwise_or(skel, temp)
        im = erode.copy()
        if cv2.countNonZero(im)== 0:
            break;
        i += 1
    image10 = Image.fromarray(skel.astype('uint8'))
    display(image10)
    raw_show = cv2.merge([skel,skel,skel])
    lines = cv2.HoughLinesP(skel,  
                           1,      
                           np.pi/180,
                           20,  
                           minLineLength=100, 
                           maxLineGap=20)
    line = lines[:,0,:]
    for x1,y1,x2,y2 in line[:]:
        cv2.line(raw_show,  
                 (x1,y1), 
                 (x2,y2),  
                 (255,0,0), 
                 2)
    image6 = Image.fromarray(raw_show.astype('uint8')).convert('RGB')
    display(image6)

    并不能很好的覆盖缺口区域

    如果你有更好的思路,欢迎在下面留言,我会及时回复。

    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    增加了新的做法,考虑检测目标和上一帧的关系,并计算IoU

    #多目标+小目标+写回视频+多帧累计 计算IoU
    import os
    from PIL import Image
    import cv2
    import numpy as np
    import math
    index_i = 0
    N = 9
    is_show_log = False
    set_index_show_log = "422" #"416" 
    video_path = "3.mp4"
    writer_path = "trans.mp4"
    def compute_iou(y11,x11,y12,x12,y21,x21,y22,x22):
        rec1 = (y11,x11,y12,x12)
        rec2 = (y21,x21,y22,x22)
        S_rec1 = (rec1[2] - rec1[0]) * (rec1[3] - rec1[1])
        S_rec2 = (rec2[2] - rec2[0]) * (rec2[3] - rec2[1])
        sum_area = S_rec1 + S_rec2
        left_line = max(rec1[1], rec2[1])
        right_line = min(rec1[3], rec2[3])
        top_line = max(rec1[0], rec2[0])
        bottom_line = min(rec1[2], rec2[2])
        if left_line >= right_line or top_line >= bottom_line:
            return 0
        else:
            intersect = (right_line - left_line) * (bottom_line - top_line)
            return (intersect / (sum_area - intersect))*1.0
    def Converting_coordinates(f_last,f_curr):
        result_iou = []
        for i in f_last:
            for j in f_curr:
                top,left,width,heigh = i
                y11 = left 
                x11 = top
                y12 = left + heigh
                x12 = top + width
                x0 = x12-(x12-x11)/2
                y0 = y12-(y12-y11)/2
                new_x11 = x0-(x12-x11)/2-N
                new_y11 = y0-(y12-y11)/2-N
                new_x12 = x0+(x12-x11)/2+N
                new_y12 = y0+(y12-y11)/2+N
                top,left,width,heigh = j
                y21 = left
                x21 = top 
                y22 = left + heigh 
                x22 = top + width
                x0 = x22-(x22-x21)/2
                y0 = y22-(y22-y21)/2
                new_x21 = x0-(x22-x21)/2-N
                new_y21 = y0-(y22-y21)/2-N
                new_x22 = x0+(x22-x21)/2+N
                new_y22 = y0+(y22-y21)/2+N
                c = compute_iou(new_y11,new_x11,new_y12,new_x12,new_y21,new_x21,new_y22,new_x22)
                result_iou.append(c)
        if max(result_iou)!=0:
            return "hit"
            
        else:
            return "miss"
    cap = cv2.VideoCapture(video_path)
    frame_counter = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) 
    fps = cap.get(cv2.CAP_PROP_FPS)/4
    frameCount = cap.get(cv2.CAP_PROP_FRAME_COUNT)
    size = (1152,648)
    videoWriter = cv2.VideoWriter(writer_path, cv2.VideoWriter_fourcc(*'MP4V'), fps, size) 
    coor_list = []
    f_last = []
    f_curr = []
    while(1):
        ret, img = cap.read()
        img = cv2.resize(img, (1152,648))
        img_rgb = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
        img_hsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
        rows, cols, channels = img.shape
        lower_red = np.array([0, 43, 46])
        upper_red = np.array([10, 255, 255])
        part1 = cv2.inRange(img_hsv,lower_red,upper_red)
        lower_red = np.array([156, 43, 46])
        upper_red = np.array([180, 255, 255])
        part2 = cv2.inRange(img_hsv,lower_red,upper_red)
        mask = part1 + part2
        if (is_show_log and index_i == int(set_index_show_log)) or \
        (is_show_log and set_index_show_log == "all") :
            print(index_i,"HSV")
            image1 = Image.fromarray(mask.astype('uint8'))
            display(image1)
        raw = cv2.cvtColor(mask,cv2.COLOR_BGR2RGB)
        raw_gray = cv2.cvtColor(raw,cv2.COLOR_RGB2GRAY)
        raw_show = raw.copy()
        kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(5, 5))
        eroded = cv2.erode(mask,kernel)
        if (is_show_log and index_i == int(set_index_show_log)) or \
        (is_show_log and set_index_show_log == "all") :
            image2 = Image.fromarray(eroded.astype('uint8'))
            display(image2)
        lines = cv2.HoughLinesP(eroded,1,np.pi/180,60,minLineLength=100,maxLineGap=40) 
        line = lines[:,0,:]
        sums = np.zeros(raw_gray.shape).astype('uint8')  
        for x1,y1,x2,y2 in line[:]:
            curr_line = raw.copy()
            cv2.line(raw_show,(x1,y1),(x2,y2),(255,0,0),2)
            cv2.line(curr_line,(x1,y1),(x2,y2),(255,0,0),2) 
            mask = np.zeros(raw_gray.shape).astype('uint8')
            cv2.line(mask,(x1,y1),(x2,y2),(255,255,255),2) 
            b,g,r  = cv2.split(raw)
            img2subtraction = cv2.subtract(mask,b)
            sums = sums + img2subtraction
            sums[ sums > 255 ] = 255
        if (is_show_log and index_i == int(set_index_show_log)) or \
        (is_show_log and set_index_show_log == "all") :
            print(index_i,"所有检测线")
            image3 = Image.fromarray(raw_show.astype('uint8'))
            display(image3)
        if (is_show_log and index_i == int(set_index_show_log)) or \
        (is_show_log and set_index_show_log == "all") :
            print(index_i,"线段检测之后,去除孔洞以前")
            image4 = Image.fromarray(sums.astype('uint8'))
            display(image4)
        ret,thresh2 = cv2.threshold(sums,0,255,cv2.THRESH_BINARY + cv2.THRESH_OTSU)
        kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(3,3))
        op_close = cv2.morphologyEx(thresh2, cv2.MORPH_CLOSE, kernel)
        op_open = cv2.morphologyEx(op_close, cv2.MORPH_OPEN, kernel)
        if (is_show_log and index_i == int(set_index_show_log)) or \
        (is_show_log and set_index_show_log == "all") :
            print(index_i,"去除空洞")
            image5 = Image.fromarray(op_open.astype('uint8'))
            display(image5)
        b_mix  = np.zeros(op_open.shape,dtype='uint8')
        bmask = cv2.merge([b_mix,b_mix,b_mix])
        counts,hierarchy = cv2.findContours(op_open,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) 
        bucket = []
        if len(counts) >= 5 :
            op_open = np.zeros(op_open.shape,dtype='uint8')
        else :
            for index in range(len(counts)):
                rect = cv2.boundingRect(counts[index])
                if rect[2] <= 3 :#or rect[3] >=10
                    bucket.append(index)
            bucket = bucket[::-1]
            for i in bucket :
                counts.pop(i)
            cv2.drawContours(bmask,counts,-1,(255,255,255),-1)     
            b,g,r = cv2.split(bmask)
            ands = cv2.bitwise_and(b, op_open)
            if index_i == 0:
                for index in range(len(counts)):
                    rect = cv2.boundingRect(counts[index])
                    f_last.append(rect)
            else:
                for index in range(len(counts)):
                    rect = cv2.boundingRect(counts[index])
                    f_curr.append(rect)
                if len(f_curr)==0 or len(f_last)==0:
                    #pass
                    ands = np.zeros(op_open.shape,dtype='uint8')
                else:
                    flag = Converting_coordinates(f_last,f_curr)
                    if flag=="hit":
                        pass
                    else:
                        ands = np.zeros(op_open.shape,dtype='uint8')
    #             print(index_i,f_last,f_curr)
                f_last = f_curr
                f_curr = []
        if (is_show_log and index_i == int(set_index_show_log)) or \
        (is_show_log and set_index_show_log == "all") :
            print(index_i,"过滤")
            image6 = Image.fromarray(ands.astype('uint8'))
            display(image6)
        frame = cv2.merge([ands,ands,ands])
        img_mask_1,img_mask_2,img_mask_3 = cv2.split(frame)
        x = np.zeros(img_mask_2.shape).astype('uint8')
        img_mask_x = cv2.merge([x,img_mask_1,x])
        masked = cv2.add(img_rgb, img_mask_x)
        masked = cv2.cvtColor(masked,cv2.COLOR_BGR2RGB)
        cv2.putText(masked, str(index_i), (50, 50), cv2.FONT_HERSHEY_TRIPLEX, 1.2, (255, 255, 255), 2)
        cv2.imshow("Press [Q] to exit.", masked)
        #写检测结果图
        cv2.imwrite("str(index_i)+".jpg",masked)
        #写视频
        videoWriter.write(masked)
        index_i = index_i+1
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
        if index_i == 5000:
            cap.release()
            cv2.destroyAllWindows() 
    cap.release()
    cv2.destroyAllWindows() 

     

    展开全文
  • opencv 对象骨架化

    2018-11-27 09:18:27
    How to get the skeleton of an object using OPENCV http://pinkjade8848.spaces.live.com/blog/cns!E4159959CD42C507!195.entry   Skeletonization is a process for reducing foreground regions in a binary...

    How to get the skeleton of an object using OPENCV

    http://pinkjade8848.spaces.live.com/blog/cns!E4159959CD42C507!195.entry

     

    Skeletonization is a process for reducing foreground regions in a binary image to a skeletal remnant that largely preserves the extent and connectivity of the original region while throwing away most of the original foreground pixels. Generally speaking, there are 2 methods to obtain the skeleton.(I am not sure there are other methods.)

    thinning

    distance transform

     

    OpenCV doesnot provide functions for skeletonization, but provides some functions on distance transform, so I use distance transform to complete this task.

     

    Distance transform is an operator normally only applied to binary images. The result of the transform is a gray level image that looks similar to the input image, except that the gray level intensities of points inside foreground regions are changed to show the distance to the closest boundary from each point

      

     

    This figure show the distance transform.

     

    Following steps show how it achieves:

    Input:  one image

    Output:  skeleton image

     

    Step1:  convert the input image to grey image if the input one is a 3-channel image. convert the grey image to binary image using threshold:

                cvThreshold( src, src, 1, 255, CV_THRESH_BINARY );

     

    Step 2: using distance transform functions to get the  distance transform images.

                cvDistTransform( src_img, dist_img, CV_DIST_L2,3 ,NULL,NULL );

    notes :  dist_img is a 32 bit float image, so if it is be display by cvShowImage(), we will find that it is same as src_image. It is better to convert 32F image to 8U image (cvConvertScale(dist_img,dist_img_8u,1,0);), and then show it.

     

    Step 3: Take Laplacian (2nd derivative) of the distance transformed image.     cvLaplace(dist_img,dist_img_laplac,3);

    Step 4:  threshold the result of step 3. this is very important. Otherwise , you can not get it. (Till now. I am not sure how to select the threshold. )

     

     

    It is supposed that the central  ridge in the distance transform should be the same as thee medial axis or  skeleton.

     

    In order to remove noise, it is suppose to do some morphology before step 1.
     

    展开全文
  • opencv 骨架提取/图像细化

    万次阅读 2016-07-12 15:10:57
    骨架提取/图像细,相信很多人都听说过,图像细化原理 可以参看这篇博文。由于opencv没有现成的函数,因此,看懂了原理之后,自己写了一个函数出来。 现在分享一下代码。 现在越来越觉得C博客的好处,可以看到好多...

    骨架提取/图像细,相信很多人都听说过,图像细化原理 可以参看这篇博文。由于opencv没有现成的函数,因此,看懂了原理之后,自己写了一个函数出来。

    现在分享一下代码。

    现在越来越觉得C博客的好处,可以看到好多前辈分享的代码,大大缩短了自己掌握图像处理技巧的时间。

    这种乐于分享的氛围,必将极大的促进技术的进步和革新。

    本代码配置条件  opencv2.4.9+vs2013  应该其他版本的vs和opencv也可以跑起来

    输入的srcimage为二值化后的图像,其中白色为要细化的特征

    void chao_thinimage(Mat &srcimage)//单通道、二值化后的图像
    {
    	vector<Point> deletelist1;
    	int Zhangmude[9];
    	int nl = srcimage.rows;
    	int nc = srcimage.cols;
    	while (true)
    	{
    		for (int j = 1; j<(nl - 1); j++)
    		{
    			uchar* data_last = srcimage.ptr<uchar>(j - 1);
    			uchar* data = srcimage.ptr<uchar>(j);
    			uchar* data_next = srcimage.ptr<uchar>(j + 1);
    			for (int i = 1; i<(nc - 1); i++)
    			{
    				if (data[i] == 255)
    				{
    					Zhangmude[0] = 1;
    					if (data_last[i] == 255) Zhangmude[1] = 1;
    					else  Zhangmude[1] = 0;
    					if (data_last[i + 1] == 255) Zhangmude[2] = 1;
    					else  Zhangmude[2] = 0;
    					if (data[i + 1] == 255) Zhangmude[3] = 1;
    					else  Zhangmude[3] = 0;
    					if (data_next[i + 1] == 255) Zhangmude[4] = 1;
    					else  Zhangmude[4] = 0;
    					if (data_next[i] == 255) Zhangmude[5] = 1;
    					else  Zhangmude[5] = 0;
    					if (data_next[i - 1] == 255) Zhangmude[6] = 1;
    					else  Zhangmude[6] = 0;
    					if (data[i - 1] == 255) Zhangmude[7] = 1;
    					else  Zhangmude[7] = 0;
    					if (data_last[i - 1] == 255) Zhangmude[8] = 1;
    					else  Zhangmude[8] = 0;
    					int whitepointtotal = 0;
    					for (int k = 1; k < 9; k++)
    					{
    						whitepointtotal = whitepointtotal + Zhangmude[k];
    					}
    					if ((whitepointtotal >= 2) && (whitepointtotal <= 6))
    					{
    						int ap = 0;
    						if ((Zhangmude[1] == 0) && (Zhangmude[2] == 1)) ap++;
    						if ((Zhangmude[2] == 0) && (Zhangmude[3] == 1)) ap++;
    						if ((Zhangmude[3] == 0) && (Zhangmude[4] == 1)) ap++;
    						if ((Zhangmude[4] == 0) && (Zhangmude[5] == 1)) ap++;
    						if ((Zhangmude[5] == 0) && (Zhangmude[6] == 1)) ap++;
    						if ((Zhangmude[6] == 0) && (Zhangmude[7] == 1)) ap++;
    						if ((Zhangmude[7] == 0) && (Zhangmude[8] == 1)) ap++;
    						if ((Zhangmude[8] == 0) && (Zhangmude[1] == 1)) ap++;
    						if (ap == 1)
    						{
    							if ((Zhangmude[1] * Zhangmude[7] * Zhangmude[5] == 0) && (Zhangmude[3] * Zhangmude[5] * Zhangmude[7] == 0))
    							{
    								deletelist1.push_back(Point(i, j));
    							}
    						}
    					}
    				}
    			}
    		}
    		if (deletelist1.size() == 0) break;
    		for (size_t i = 0; i < deletelist1.size(); i++)
    		{
    			Point tem;
    			tem = deletelist1[i];
    			uchar* data = srcimage.ptr<uchar>(tem.y);
    			data[tem.x] = 0;
    		}
    		deletelist1.clear();
    
    		for (int j = 1; j<(nl - 1); j++)
    		{
    			uchar* data_last = srcimage.ptr<uchar>(j - 1);
    			uchar* data = srcimage.ptr<uchar>(j);
    			uchar* data_next = srcimage.ptr<uchar>(j + 1);
    			for (int i = 1; i<(nc - 1); i++)
    			{
    				if (data[i] == 255)
    				{
    					Zhangmude[0] = 1;
    					if (data_last[i] == 255) Zhangmude[1] = 1;
    					else  Zhangmude[1] = 0;
    					if (data_last[i + 1] == 255) Zhangmude[2] = 1;
    					else  Zhangmude[2] = 0;
    					if (data[i + 1] == 255) Zhangmude[3] = 1;
    					else  Zhangmude[3] = 0;
    					if (data_next[i + 1] == 255) Zhangmude[4] = 1;
    					else  Zhangmude[4] = 0;
    					if (data_next[i] == 255) Zhangmude[5] = 1;
    					else  Zhangmude[5] = 0;
    					if (data_next[i - 1] == 255) Zhangmude[6] = 1;
    					else  Zhangmude[6] = 0;
    					if (data[i - 1] == 255) Zhangmude[7] = 1;
    					else  Zhangmude[7] = 0;
    					if (data_last[i - 1] == 255) Zhangmude[8] = 1;
    					else  Zhangmude[8] = 0;
    					int whitepointtotal = 0;
    					for (int k = 1; k < 9; k++)
    					{
    						whitepointtotal = whitepointtotal + Zhangmude[k];
    					}
    					if ((whitepointtotal >= 2) && (whitepointtotal <= 6))
    					{
    						int ap = 0;
    						if ((Zhangmude[1] == 0) && (Zhangmude[2] == 1)) ap++;
    						if ((Zhangmude[2] == 0) && (Zhangmude[3] == 1)) ap++;
    						if ((Zhangmude[3] == 0) && (Zhangmude[4] == 1)) ap++;
    						if ((Zhangmude[4] == 0) && (Zhangmude[5] == 1)) ap++;
    						if ((Zhangmude[5] == 0) && (Zhangmude[6] == 1)) ap++;
    						if ((Zhangmude[6] == 0) && (Zhangmude[7] == 1)) ap++;
    						if ((Zhangmude[7] == 0) && (Zhangmude[8] == 1)) ap++;
    						if ((Zhangmude[8] == 0) && (Zhangmude[1] == 1)) ap++;
    						if (ap == 1)
    						{
    							if ((Zhangmude[1] * Zhangmude[3] * Zhangmude[5] == 0) && (Zhangmude[3] * Zhangmude[1] * Zhangmude[7] == 0))
    							{
    								deletelist1.push_back(Point(i, j));
    							}
    						}
    					}
    				}
    			}
    		}
    		if (deletelist1.size() == 0) break;
    		for (size_t i = 0; i < deletelist1.size(); i++)
    		{
    			Point tem;
    			tem = deletelist1[i];
    			uchar* data = srcimage.ptr<uchar>(tem.y);
    			data[tem.x] = 0;
    		}
    		deletelist1.clear();
    	}

    效果如下图所示



    展开全文
  • 1 骨架细化原理 思想: 公式: y = p0*2^0 + p1*2^1+ p2*2^2 + p3*2^3 + p4*2^4 + p5*2^5 + p6*2^6 +p7*2^7 前辈们对此作出了总结,得出每个点周围8领域的256种情况,放在一个char data[256]的数组中,不可以...
  • opencv骨骼

    2017-10-27 15:53:29
    一个基于opencv2.4.6 的完整的细化算法源代码程序,opencv的细化算法
  • OpenCV在Android上虽然有自己的开源库,能够处理很多的图像问题,但是一旦涉及到一些需要使用算法方面的问题比如骨架化或者像素点操作的问题时,其处理速度会变得很满,且处理效果并不是十分完美。 例如我最近需要...
  • Kinect2+Opencv显示骨架

    2016-08-22 12:56:20
    利用Opencv绘制骨骼,方便不熟悉Direct2D开发的童鞋使用~
  • 基于opencv和python的骨架提取代码,利用击中不击中变化实现细化操作。切分以后,结合深度学习识别技术,可以对字符 数字等印刷体有一个比较理想的分割和识别效果。本人亲测 有生成结果图片和原图片对照实例,可以...
  • opencv2实现形态学骨架提取

    万次阅读 2016-06-07 21:49:05
    因为opencv2中没有形态学骨架提取算法的实现,于是准备在opencv2上实现一个。 首先介绍下骨架提取算法,冈萨雷斯的书上已经说的很清楚了,我再重复一下。 集合A的骨架可以用腐蚀和开操作来表达, 即骨架可以表示为 ...
  • rs-opencv 使用RealSense传感器进行骨骼检测以在Blender Game Engine中可视 可视 依存关系 Debian 10克星 python3.7 oscpy 麻木 的OpenCVPython的 CUDA pygame-槲寄生 Opencv和CUDA 发射 python3 skeleton...
  • 这个包中的文件包含了一种对二进制图像进行骨架化的方法的 Matlab 实现。 这些是我自己的实现Alex Telea 向我传达的一种骨架化方法( http://www.win.tue.nl/~alext/ )。 有关更多详细信息,请参阅他的论文。 骨架...
  • OpenCV—python 图片细化(骨架提取)一

    千次阅读 多人点赞 2019-09-20 09:37:17
    图像细化主要是针对二值图而言,所谓骨架,可以理解为图像的中轴,,一个长方形的骨架,是它的长方向上的中轴线,圆的骨架是它的圆心,直线的骨架是它自身,孤立点的骨架也是自身。我们来看看典型的图形的骨架(用...
  • OpenCV—python 图片细化(骨架提取)二

    千次阅读 多人点赞 2020-07-14 10:10:31
    文章目录一、骨架提取函数 skeletonize()一、骨架提取函数 medial_axis() 一、骨架提取函数 skeletonize() 骨架提取,也叫二值图像细化。这种算法能将一个连通区域细化成一个像素的宽度,用于特征提取和目标拓扑表示...
  • 我想删除此车轮骨架标志的周长(标志的最外面的周长),除了里面的什么。我考虑一个函数findcontours()并删除我发现的最大轮廓这是输入图像:骨骼:不幸的是,这是我的输出图像:为什么它不只保留2个交叉的线段,...
  • 骨架提取,也叫二值图像细化。这种算法能将一个连通区域细化成一个像素的宽度,用于特征提取和目标拓扑表示。骨架提取与分水岭算法也属于形态学处理范畴,都放在morphology子模块内。 morphology子模块提供了两个...
  • imutils是在OPenCV基础上的一个封装,达到更为简结的调用OPenCV接口的目的,它可以轻松的实现图像的平移,旋转,缩放,骨架化等一系列的操作。 安装: pip install imutils 使用方法: 图像平移 OpenCV中也...
  • OpenCV 直方图均衡

    2021-04-25 11:54:42
    这种方法提高图像整体的对比度,特别是有用数据的像素值分布比较接近时,在X光图像中使用广泛,可以提高骨架结构的显示,另外在曝光过度或不足的图像中可以更好的突出细节。 dst = cv.equalizeHist(img) img: 灰度...
  • //根据上述细化算法,在OpenCV中采用3×3结构元素的细化代码如下: //函数名称:Mat thinning() //基本功能:对二值图像进行细化运算 //参数说明:待细化二值图像,该图像中背景色为0,前景色(目标)为255 //返回值:...
  • python3 OpenCV cv2 图像的细化(骨架抽取)_图像处理作业

    万次阅读 多人点赞 2018-05-13 23:46:11
    首先是算法原理介绍:图像细化:图像细化主要是针对二值图而言,所谓骨架,可以理解为图像的中轴,,一个长方形的骨架,是它的长方向上的中轴线,圆的骨架是它的圆心,直线的骨架是它自身,孤立点的...
  • 使用Kinect 2.0 + OpenCV 获取深度信息(Depth Data),骨架信息(Body Data),手势状态(Hand State)和人物二值图(Body Index Data)。
  • 昨天不是说同学问我怎么绘制出轮廓的中心线。然后我上网查了一下其实这个有专门的算法叫做细化...图像细化(Image Thinning),一般指二值图像的骨架化(Image Skeletonization)的一种操作运算。切记:前提条件一定是二...
  • 做项目时碰到特征的骨架提取,找了挺多相关资料,发现这篇博客讲的最完整,而且通俗易懂,完美解决碰到的问题,特转载如下,供更多的人学习。转自:https://www.cnblogs.com/mikewolf2002/p/3327183.html 本章我们...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 870
精华内容 348
关键字:

opencv骨架化