我使用OpenCv库在python中编程。
我试图使用opencv删除阴影,所以之后我想计算NDVI(Arcpy库)。因此,如果我从原始图像计算NDVI,它工作正常,但如果我想在消除阴影后从结果计算NDVI,我得到了这个错误:
Traceback (most recent call last):
File "C:/Python27/sombras_ndvi.py", line 36, in <module>
NIR = arcpy.sa.Raster(sumada3+ '\Band_1')
TypeError: unsupported operand type(s) for +: 'numpy.ndarray' and 'str'
完整的代码是:
#I create a workspace to calculate NDVI..
arcpy.CheckOutExtension("spatial")
env.workspace = r'C:\python27\archivos'
#the first step is apply some filters to finally delete shades.
img = cv2.imread('C:\python27\Archivos\image02.jpg',0)
orig = cv2.imread('C:\python27\Archivos\image02.jpg')
thresh = 45
maxValue = 255
blur = cv2.blur(img, (15,15))
medianblur = cv2.medianBlur(blur,11)
th, dst = cv2.threshold(blur, thresh, maxValue, cv2.THRESH_BINARY_INV)
dst2_3channel= cv2.cvtColor(dst,cv2.COLOR_GRAY2BGR)
sumada3 = cv2.add(dst2_3channel,orig)
#NOW I TRY TO CALCULATE NDVI
NIR = arcpy.sa.Raster(sumada3+ '\Band_1')
red = arcpy.sa.Raster(sumada3+ '\Band_2')
#NDVI = (NIR-red)/(NIR+red)
num = arcpy.sa.Float(NIR-red)
denom = arcpy.sa.Float(NIR+red)
NDVI = arcpy.sa.Divide(num, denom)
ndvi_out = ('NDVI_sombras.jpg')
NDVI.save(ndvi_out)
答案 0 :(得分:0)
arcpy.sa.Raster
创建一个栅格对象。但是,它需要现有的栅格数据集作为输入。它不能接受numpy数组作为输入;适当的工具是arcpy.NumPyArrayToRaster
。