WIP: benchmark mature trackers and bounded occlusion recovery before host integration
这个提交包含在:
1 父节点
1f430a164a
当前提交
7aece444b0
7 个文件已更改
+204
没有与搜索条件相匹配的文件
@@ -0,0 +1,17 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#include "../../大鱼调色/Plugin/MaskCore/DYObjectTracker.hpp"
|
||||
#include <fstream>
|
||||
#include <chrono>
|
||||
int main(int argc,const char**argv){@autoreleasepool{
|
||||
if(argc!=9)return 2;int w=atoi(argv[2]),h=atoi(argv[3]);double fps=atof(argv[8]);dy::TrackerROI roi{float(atof(argv[4])),float(atof(argv[5])),float(atof(argv[6])),float(atof(argv[7])),0};
|
||||
std::ifstream input(argv[1],std::ios::binary);std::vector<uint8_t> bytes(size_t(w)*h*4);dy::ObjectTracker tracker;NSMutableArray *frames=[NSMutableArray new];double total=0,maximum=0;
|
||||
while(input.read((char*)bytes.data(),bytes.size())){@autoreleasepool{
|
||||
for(size_t i=0;i<bytes.size();i+=4)std::swap(bytes[i],bytes[i+2]);
|
||||
auto start=std::chrono::steady_clock::now();dy::ObjectStep step;bool initial=frames.count==0;
|
||||
if(initial){step.valid=tracker.reset(bytes.data(),w,h,false,roi,fps);step.box={roi.cx,roi.cy,roi.width,roi.height,1};}
|
||||
else step=tracker.track(bytes.data(),w,h,false);
|
||||
auto r=tracker.result(step);double ms=std::chrono::duration<double,std::milli>(std::chrono::steady_clock::now()-start).count();total+=ms;maximum=std::max(maximum,ms);
|
||||
[frames addObject:@{@"cx":@(r.cx),@"cy":@(r.cy),@"width":@(roi.width*r.scaleX),@"height":@(roi.height*r.scaleY),@"confidence":@(r.confidence),@"valid":@(r.valid),@"predicted":@(step.predicted),@"recovered":@(step.recovered),@"gap":@(step.gap),@"ms":@(ms)}];if(!step.valid)break;
|
||||
}}
|
||||
NSData *data=[NSJSONSerialization dataWithJSONObject:@{@"frames":frames,@"milliseconds":@(total),@"maximumMs":@(maximum)} options:NSJSONWritingPrettyPrinted error:nil];fwrite(data.bytes,1,data.length,stdout);return 0;
|
||||
}}
|
||||
@@ -0,0 +1,22 @@
|
||||
"""Compare official OpenCV trackers on local caller-decoded frames; no GUI/media upload."""
|
||||
import argparse,json,time,pathlib
|
||||
import cv2 as cv
|
||||
import numpy as np
|
||||
p=argparse.ArgumentParser();p.add_argument('frames');p.add_argument('algorithm',choices=['csrt','vit']);p.add_argument('--model');p.add_argument('--output',required=True);a=p.parse_args()
|
||||
cv.setNumThreads(2)
|
||||
if a.algorithm=='csrt':tracker=cv.TrackerCSRT_create()
|
||||
else:
|
||||
params=cv.TrackerVit_Params();params.net=a.model;tracker=cv.TrackerVit_create(params)
|
||||
roi=(round((.486-.085/2)*640),round((.238-.155/2)*360),round(.085*640),round(.155*360))
|
||||
results=[]
|
||||
with open(a.frames,'rb') as stream:
|
||||
while data:=stream.read(640*360*4):
|
||||
assert len(data)==640*360*4
|
||||
image=np.frombuffer(data,np.uint8).reshape(360,640,4)[:,:,:3].copy()
|
||||
start=time.perf_counter()
|
||||
if not results:tracker.init(image,roi);ok=True;box=roi;score=1.
|
||||
else:
|
||||
ok,box=tracker.update(image);score=tracker.getTrackingScore() if a.algorithm=='vit' else float(ok)
|
||||
elapsed=(time.perf_counter()-start)*1000;x,y,w,h=box
|
||||
results.append(dict(valid=bool(ok),confidence=float(score),cx=(x+w/2)/640,cy=(y+h/2)/360,width=w/640,height=h/360,ms=elapsed))
|
||||
pathlib.Path(a.output).write_text(json.dumps(dict(algorithm=a.algorithm,opencv=cv.__version__,threads=2,frames=results,milliseconds=sum(x['ms'] for x in results)),indent=2)+'\n')
|
||||
@@ -0,0 +1,23 @@
|
||||
// Read-only local media benchmark. No host app, uploads, or persisted images.
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Vision/Vision.h>
|
||||
#import <CoreVideo/CoreVideo.h>
|
||||
#include <fstream>
|
||||
#include <chrono>
|
||||
int main(int argc,const char**argv){@autoreleasepool{
|
||||
if(argc!=9)return 2;int w=atoi(argv[2]),h=atoi(argv[3]);
|
||||
CGRect box=CGRectMake(atof(argv[4])-atof(argv[6])/2,1-atof(argv[5])-atof(argv[7])/2,atof(argv[6]),atof(argv[7]));
|
||||
VNSequenceRequestHandler *sequence=[VNSequenceRequestHandler new];
|
||||
VNTrackObjectRequest *track=[[VNTrackObjectRequest alloc]initWithDetectedObjectObservation:[VNDetectedObjectObservation observationWithBoundingBox:box]];
|
||||
track.trackingLevel=atoi(argv[8])?VNRequestTrackingLevelAccurate:VNRequestTrackingLevelFast;
|
||||
CVPixelBufferRef buffer=nullptr;CVPixelBufferCreate(kCFAllocatorDefault,w,h,kCVPixelFormatType_32BGRA,(__bridge CFDictionaryRef)@{(id)kCVPixelBufferIOSurfacePropertiesKey:@{}},&buffer);
|
||||
if(!buffer)return 3;std::ifstream input(argv[1],std::ios::binary);std::vector<uint8_t> bytes(size_t(w)*h*4);NSMutableArray *frames=[NSMutableArray new];double total=0,maximum=0;
|
||||
while(input.read((char*)bytes.data(),bytes.size())){@autoreleasepool{
|
||||
CVPixelBufferLockBaseAddress(buffer,0);auto dst=(uint8_t*)CVPixelBufferGetBaseAddress(buffer);for(int y=0;y<h;y++)memcpy(dst+y*CVPixelBufferGetBytesPerRow(buffer),bytes.data()+size_t(y)*w*4,w*4);CVPixelBufferUnlockBaseAddress(buffer,0);
|
||||
auto start=std::chrono::steady_clock::now();NSError *error=nil;BOOL ok=[sequence performRequests:@[track] onCVPixelBuffer:buffer orientation:kCGImagePropertyOrientationUp error:&error];
|
||||
double ms=std::chrono::duration<double,std::milli>(std::chrono::steady_clock::now()-start).count();total+=ms;maximum=std::max(maximum,ms);
|
||||
VNDetectedObjectObservation *r=track.results.firstObject;CGRect b=r.boundingBox;
|
||||
[frames addObject:@{@"cx":@(CGRectGetMidX(b)),@"cy":@(1-CGRectGetMidY(b)),@"width":@(b.size.width),@"height":@(b.size.height),@"confidence":@(r.confidence),@"valid":@(ok&&r!=nil),@"ms":@(ms)}];if(!ok||!r)break;track.inputObservation=r;
|
||||
}}
|
||||
CVPixelBufferRelease(buffer);NSData *data=[NSJSONSerialization dataWithJSONObject:@{@"frames":frames,@"milliseconds":@(total),@"maximumMs":@(maximum)} options:NSJSONWritingPrettyPrinted error:nil];fwrite(data.bytes,1,data.length,stdout);return 0;
|
||||
}}
|
||||
在新工单中引用
屏蔽一个用户