我通過一個實時兩個相機流提取2個blob的x位置。我可以得到第一個x位置沒有問題,因爲它是作爲元組給出的(ex = ... object at(455,69))。問題是我需要第二個blob左下角的x位置,但它返回爲一個numpy數組,'blob.x'不起作用。我怎樣才能得到numpy數組的x位置?任何幫助/指導非常感謝。從numpy數組中提取X座標
我收到以下錯誤: ValueError:具有多個元素的數組的真值是不明確的。使用a.any()或a.all()
from SimpleCV import *
def getscoreforrgb(rgb):
return rgbmap[rgb]
mog1 = MOGSegmentation(history = 200, nMixtures = 5, backgroundRatio = 0.9, noiseSigma = 16, learningRate = 0.9)
mog0 = MOGSegmentation(history = 200, nMixtures = 5, backgroundRatio = 0.9, noiseSigma = 16, learningRate = 0.9)
cam1 = SimpleCV.Camera(1, {'width': 640, 'height': 480 })
cam0 = SimpleCV.Camera(0, {'width': 640, 'height': 480 })
pixcol = Image('/home/pi/Darts/score/scoreboardpy.png')
while True:
frame1 = cam1.getImage()
frame0 = cam0.getImage().flipHorizontal()
mog1.addImage(frame1)
mog0.addImage(frame0)
segmentedImage1 = mog1.getSegmentedImage()
segmentedImage0 = mog0.getSegmentedImage()
#### second blob below, does not print x position
blobs0 = segmentedImage0.findBlobs()
if blobs0 is not None:
blobs0.sortArea()
blobs0[-1].draw(Color.BLUE, width=4)
first_blob = blobs0[-1]
bottomLeftCorner = second_blob.bottomLeftCorners()
print bottomLeftCorner
if bottomLeftCorner:
print bottomLeftCorner.x,
y = int(bottomLeftCorner.x)
print y * 2, 'Y'
y2 = y * 2
#### First blob below, code prints x position
blobs1 = segmentedImage1.findBlobs()
if blobs1 is not None:
blobs1.sortArea()
blobs1[-1].draw(Color.RED, width=4)
second_blob = blobs1[-1]
if second_blob:
print second_blob.x,
x = int(second_blob.x)
print x * 2, 'X'
x2 = x * 2
colrgb = pixcol[x2, y2]
print colrgb
哪一行會拋出錯誤? – Julien
當我嘗試將'bottomLeftCorner.x'作爲'y2'輸入到'colrgb = pixcol [x2,y2]' –
這發生在多行中。哪條確切線?它應該在錯誤信息中說。 – Julien