美文网首页
查看检测和轨迹

查看检测和轨迹

作者: ad丶leo | 来源:发表于2019-01-03 20:12 被阅读0次
    def see_det(name):
      files=glob.glob(name+/'*.mp4')
      for file in files:
        cap=cv2.VideoCapture(file)
        locs=open(file.replace('.mp4','.txt'),'r').readlines()
        cv2.namedWindow('frame', 0)
        cv2.resizeWindow('frame', 1200,750)
        cv2.moveWindow('frame',100,-10)
        for loc in locs:
          loc = loc.strip().split(' ')
          x1 = int(float(loc[1]))
          y1 = int(float(loc[2]))
          x2 = int(float(loc[3]))
          y2 = int(float(loc[4]))
          frameid=int(loc[0])
          cap.set(1,frameid)
          if cv2.waitKey(1) & 0xFF == ord('q'):
            break
          success,frame=cap.read()
          cv2.rectangle(frame, (x1, y1), (x2, y2), (255, 255, 0), 2)
          cv2.imshow('frame',frame)
          cv2.waitKey(3)
        cap.release()
    
    import pandas as pd
    import cv2
    import math
    def see_track(name):
      files=glob.glob(name+/'*.mp4')
      for file in files:
        cap=cv2.VideoCapture(file)
        track=open(file.replace('.mp4','.txt'),'r')
        locs=pd.readtable(track,header=None,delimiter=',')
        points={}
        cv2.namedWindow('frame', 0)
        cv2.resizeWindow('frame', 1200,750)
        cv2.moveWindow('frame',100,-10)
        frames=int(max(locs[0]))
        for i in range(frames):
          cap.set(1,frameid)
          if cv2.waitKey(1) & 0xFF == ord('q'):
            break
          success,frame=cap.read()
          locsi=locs.loc[locs[0]==i]
          ids=[]
          for row_index,row in locsi.iterrows():
            x1=int(row[2])
            y1=int(row[3])
            x2=int(row[4])+x1
            y2=int(row[5])+y1
            x=(x1+x2)/2
            y=(y1+y2)/2
            fid=int(row[1])
            if fid not in ids:
                ids.append(fid)
            if fid not in points:
                points[fid]=[(x,y)]
            else:
                points[fid].append((x,y))
            
          for index,id in enumerate(ids):
            tmp=points[id][0]
            for point in points[id]:
                c=(255,255,0)
                frame=cv2.line(frame,tmp,point,c,2)
                tmp=point
        cv2.imshow('frame',frame)
        cv2.waitKey(3)
    

    相关文章

      网友评论

          本文标题:查看检测和轨迹

          本文链接:https://www.haomeiwen.com/subject/jybqrqtx.html