我有这个函数来确定列表是否是另一个列表的轮换:
def isRotation(a,b):
if len(a) != len(b):
return False
c=b*2
i=0
while a[0] != c[i]:
i+=1
for x in a:
if x!= c[i]:
return False
i+=1
return True
Run Code Online (Sandbox Code Playgroud)
例如
>>> a = [1,2,3]
>>> b = [2,3,1]
>>> isRotation(a, b)
True
Run Code Online (Sandbox Code Playgroud)
如何使用重复项进行此操作?例如
a = [3,1,2,3,4]
b = [3,4,3,1,2]
Run Code Online (Sandbox Code Playgroud)
它可以及时完成O(n)
吗?
我试图使用Media Flow Tracker根据区域跟踪我的手,但是一段时间后边界框会不断增加.它在前10秒左右正常工作.
这是一段代码片段:
def main():
display = SimpleCV.Display()
cam = Kinect()
ts = []
bb = None
img = cam.getDepth().flipHorizontal()
while display.isNotDone():
depth = cam.getDepth().flipHorizontal()
filtered = depth.stretch(0, 180).binarize().dilate(1)
if bb is None:
blobs = filtered.findBlobs()
if blobs:
hand = blobs.filter(abs(7000 - blobs.area()) < 500)
print hand
if hand:
bb = hand[0].boundingBox()
print bb
if bb is not None:
ts = filtered.track("mftrack", ts, img, bb)
if ts:
ts.drawBB()
ts.showPixelVelocityRT()
ts.drawPath()
filtered.show()
Run Code Online (Sandbox Code Playgroud)