0

I want to apply Gaussian blur to a particular edge of polygons. The code below generates 4 images like the below one but each of them has different white polygon. I want to apply the Gaussian blur just to that green edge but It raised error : blur= cv.blur(edge[i],(5,5)) TypeError: Expected Ptr for argument '%s'

enter image description here

import numpy as np
import matplotlib.pyplot as plt
import cv2 as cv

pixels = 600
my_dpi = 100
num_geo=3

coord = np.array([[[-150, -200], [300, -200], [300, 0], [150, 200], [-150, 200]],
                  [[-300, -200], [200, -300], [200, -50], [200, 300], [-150, 200]],
                  [[-140, -230], [350, -260], [350, 0], [140, 200], [-180, 220]],
                  [[-180, -240], [370, -270], [370, 0], [170, 200], [-190, 230]]])

for i in range(4):
    geo = coord[i, :, :]
    fig = plt.figure(num_geo,figsize=( pixels/my_dpi,  pixels/my_dpi),facecolor='k', dpi=my_dpi)  
    plt.axes([0,0,1,1])
    rectangle = plt.Rectangle((-300, -300), 600, 600, fc='k')
    plt.gca().add_patch(rectangle)
    polygon = plt.Polygon(coord[i],color='w')
    plt.gca().add_patch(polygon)
    edge=plt.plot([coord[i][0][0], coord[i][-1][0]], [coord[i][0][1], coord[i][-1][1]], color='#008000', lw=4)
    blur = cv.blur(edge[i],(5,5))
    plt.axis('off')
    plt.axis([-300,300,-300,300])
    plt.savefig('figure2/%d.png' % i, dpi=my_dpi)
    plt.close()
Hamed
  • 73
  • 2
  • 10
  • I can't replicate your error message. If I use your code as is then it gives me a TypeError: 'Line2D' object is not subscriptable. Only if I try cv.blur(edge[i],(5,5)) then I get TypeError: Expected Ptr for argument 'src'. Also a possible helpful reference: https://stackoverflow.com/questions/55066764/how-to-blur-feather-the-edges-of-an-object-in-an-image-using-opencv – Deep-B Feb 03 '20 at 21:03
  • @Deep-5 Yes, that was a typo. The link you have attached, applying Gaussian blur to entire edges. There are some minor noises (contours) in other edges as well which I don't want to apply Gaussian blur to them. Is it any possible way to detect just that particular line and apply the Gaussian blur to it. – Hamed Feb 04 '20 at 03:11
  • This line 'edge=plt.plot([coord[i][0][0], coord[i][-1][0]], [coord[i][0][1], coord[i][-1][1]], color='#008000', lw=4)' plots that green edge. I am wondering how can I choose that line in my for-loop. It seems that blur = cv.blur(edge[i],(5,5)) it's not correct. – Hamed Feb 04 '20 at 03:14

0 Answers0