Ask Your Question

helxsz's profile - activity

2017-09-13 08:02:13 -0600 received badge  Famous Question (source)
2017-07-22 04:17:15 -0600 asked a question how to segment the connected area based on depth color in opencv

I have a picture like enter image description here, which i need to segment the picture into 8 blocks.

image description

I have tried this threshold method

img_gray = cv2.imread(input_file,cv2.IMREAD_GRAYSCALE) 
ret,thresh = cv2.threshold(img_gray,254,255,cv2.THRESH_BINARY)
kernel = np.array(cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3), (-1, -1)))

img_open = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel) cv2.imshow('abc',img_open) ret1,thresh1 = cv2.threshold(img_open,254,255,cv2.THRESH_BINARY_INV) contours, hierarchy = cv2.findContours(thresh1, cv2.RETR_CCOMP ,cv2.CHAIN_APPROX_NONE) for i in range(len(contours)): if len(contours[i]) > 20: x, y, w, h = cv2.boundingRect(contours[i]) cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 2) print (x, y),(x+w, y+h)

after the thresholding

image description

the end result is some blocks connected together are formed into a large segment, which is not what I hoped.

image description

Any other ways to get it around

2017-05-25 05:50:28 -0600 received badge  Notable Question (source)
2017-04-03 05:32:37 -0600 received badge  Popular Question (source)
2016-06-28 09:35:49 -0600 commented answer Replace a range of colors with a specific color in python

Thanks a lot, @Missing, it works perfectly and I learned a lot! if you can add it to the answer, I can score it. :)

2016-06-28 08:42:24 -0600 commented answer Replace a range of colors with a specific color in python

@Missing, thanks for reminding me this. I tried the approach, it works but only partially, there is some parts not being transformed. Any ideas? I have updated in the main content.

2016-06-28 08:32:32 -0600 received badge  Editor (source)
2016-06-28 05:58:25 -0600 commented answer Replace a range of colors with a specific color in python

Hi, @Missing, actually it works for the original image but it is strange that the resulted mask from inRange() can't be performed on same operation`enter code here.

frame = cv2.imread("/home/ad/Desktop/1.png")
lower_black = np.array([0,0,0], dtype = "uint16")
upper_black = np.array([70,70,70], dtype = "uint16")
black_mask = cv2.inRange(frame, lower_black, upper_black)
frame[np.where((frame == [0,0,0]).all(axis = 2))] = [0,255,255]     # it works
black_mask[np.where((black_mask == [0,0,0]).all(axis = 2))] = [0,255,255]   # it doesn't work
2016-06-28 04:47:06 -0600 commented answer Replace a range of colors with a specific color in python

@Missing, I tried " image[np.where((image==[0,0,0]).all(axis=2))] = [255,255,255] ", but returns " AttributeError: 'bool' object has no attribute 'all' ", so I guess it another way, image[np.where((image==[0,0,0])).all(axis=2)] = [255,255,255], but still telling me a error "AttributeError: 'tuple' object has no attribute 'all' "

2016-06-28 00:16:47 -0600 asked a question Replace a range of colors with a specific color in python

I have a image with white background, grey and black part, I want to segment three parts into different color.

so far I could segment the black and grey part with inRange, but I wonder Is there a python API that substitute one color with another color, for example to substitute the black part with red color.

original image
original image

   frame = cv2.imread("/home/ad/Desktop/1.png")
   cv2.imshow('frame',frame)

image after inrange image after inrange

lower_black = np.array([0,0,0], dtype = "uint16")
upper_black = np.array([70,70,70], dtype = "uint16")
black_mask = cv2.inRange(frame, lower_black, upper_black)
cv2.imshow('mask0',black_mask)

image description substitute the black color to white color

black_mask[np.where((black_mask == [0] ).all(axis = 1))] = [255]
cv2.imshow('mask1',black_mask)

However, in the last image when trying to substitute the black color into the white color, only a traction of black color has been transformed, there are some parts of the black part remains to be black

2016-06-28 00:07:25 -0600 answered a question Replace a range of colors with a specific color

Is there a python based API for doing this?

2015-09-19 11:25:57 -0600 received badge  Student (source)
2014-11-29 01:30:19 -0600 asked a question how blury the background apart from ROI

I have a road scene picture, and I can detect the vehicles on the road. What I want to do is to blur the whole picture except the vehicle detection areas, my solution is firstly I create a empty Mat and crop the vehicle detection area into the empty Mat, and secondly blur the whole picture, now the problem is how to combine the blury picture with the vehicle parts ?

image description

2013-10-21 06:33:30 -0600 received badge  Scholar (source)
2013-10-13 01:16:20 -0600 asked a question how to extract the Mat of non square object in opencv?

I am using opencv (both c++ and java) to segement a white paper in the picture showed below, this works , but now I have to split the paper into 8 small section and get the Mat of each section, since each section is not a pure square, it is hard to use submate(startrow, endrow, startcol, endcol).

Is there any way in opencv to extract the Mat for this kind of none square object?image description

2013-09-05 23:22:38 -0600 received badge  Supporter (source)