我應用了一個返回浮點數的移動平均邏輯。我轉換花車用它來繪製線OpenCV的,但得到以下錯誤Python:無法將浮點數NaN轉換爲整數
ValueError: cannot convert float NaN to integer
示例代碼
def movingAverage(avg, new_sample, N=20):
if (avg == 0):
return new_sample
avg -= avg/N;
avg += new_sample/N;
return avg;
x1 = int(avgx1) #avgx1 is returned from the movingaverage function
y1 = int(avgy1)
x2 = int(avgx2)
y2 = int(avgy2)
cv2.line(img, (x1, y1), (x2, y2), [255,255,255], 12)
如何解決它的任何建議之前詮釋?
您將分配給NaN的哪個整數值? – BlackBear