如何在opencv中删除矩形边界的重叠

时间:2016-02-18 10:46:11

标签: python opencv overlap rectangles boundary

我必须在不同颜色的图像上绘制一个30 * 30的矩形。我可以根据要求绘制不同颜色的矩形,但边界重叠,因此颜色混合正在发生。我无法设置任何边界,因此边界不会重叠,每个矩形都可以清晰地看到。我将感谢你的帮助。

import cv2
from scipy import misc
import numpy as np
import matplotlib.pyplot as plt
# read image
img = misc.imread("img.tif")

csv = np.loadtxt("classes.csv" , dtype = str ,delimiter = ',')

color = np.loadtxt("colorlist1.csv" , dtype = str ,delimiter = ',')

row =0

for i in range(csv.shape[0]):
  col=0
  for j in range(csv.shape[1]):
     #print row, row+30
     #print col,col+30
     clr = int(csv[i][j])
     cv2.rectangle(img,(col,row),(col+30,row+30),(int(color[clr][0]),int(color[clr][1]),int(color[clr][2])),4,2)
     col = col+30
  row = row+30
print "************"


plt.imsave("img_crop_rect.tif",img)
print "Done"

Image with overlapped rectangular boundary

但我想要这样的矩形。 enter image description here

0 个答案:

没有答案