我读了一段灰度的视频。我在视频的每一帧上标记了一个圆形轮廓,并尝试记录该轮廓上每个像素的强度:
frameCount += 1
currentTimestamp = timestamp + frameCount/fps
file = open("myRecord.txt", "a+") #a+ to append to file
file.write(str(currentTimestamp))
circleSegment = get_circle_segment(center_pt, 60, 360) #this function returns a list of tuples, where each tuple (x,y) contains x- and y-coordinates of a point along the circular contour
for el in circleSegment:
pixel = gray_frame[el[1],el[0]]
#log information
file.write('\t' + str(pixel))
file.write('\n')
file.close()
这非常适合最大180°甚至更大的圆弧(我也测试了181°)。但是,一旦我超出某个值,例如270°或359°或360°(一个完整的圆,这就是我想要的),所记录的数据仅包含汉字。
我不知道什么可能导致此问题!我的txt文件超过1000 KB会出问题吗?
注释后,此代码有效:
frameCount += 1
currentTimestamp = timestamp + frameCount/fps
storeData = []
storeData.append(currentTimestamp)
circleSegment = get_circle_segment(center_pt, 60, 360)
for el in circleSegment:
pixel = gray_frame[el[1],el[0]]
storeData.append(pixel)
#log information
file = open("myRecord.txt", mode="a+") #a+ to append to file
for element in storeData:
file.write('\t' + str(element))
file.write('\n')
file.close ()