Replace every production tracking path with Apple Vision; remove OpenCV linkage

这个提交包含在:
mac 于 2026-11-06 19:40:07 +08:00 提交
1 父节点 dbab2ab0cc
当前提交 8af7013ad4
22 个文件已更改
+600 -43

没有与搜索条件相匹配的文件

+21
查看文件
@@ -0,0 +1,21 @@
#import <Foundation/Foundation.h>
#include "../../大鱼调色/Plugin/MaskCore/DYVisionRegionTracker.hpp"
#include <cstdio>
#include <chrono>
float noise(int x,int y){uint32_t n=uint32_t(x)*73856093u^uint32_t(y)*19349663u;n^=n>>13;n*=1274126177u;return .15f+.7f*((n>>8)&255)/255.f;}
float texture(float u,float v){int x=std::floor(u),y=std::floor(v);float fx=u-x,fy=v-y;return (noise(x,y)*(1-fx)+noise(x+1,y)*fx)*(1-fy)+(noise(x,y+1)*(1-fx)+noise(x+1,y+1)*fx)*fy;}
dy::GrayFrame frame(int step,bool paired,bool rotate,bool flat=false){dy::GrayFrame f{320,192,{}};f.pixels.resize(320*192);for(int y=0;y<192;y++)for(int x=0;x<320;x++){
bool left=paired&&x<160;float cx=paired?(left?80:240):160,cy=96,scale=1+step*(paired?(left?-.025f:.035f):.01f),angle=rotate?.01f*step:0,tx=step*(paired?(left?-1.5f:2.f):2.f),ty=step*(paired?(left?1.f:-.75f):1.f);
float a=(x-cx-tx)/scale,b=(y-cy-ty)/scale,u=(cx+a*std::cos(angle)+b*std::sin(angle))/4,v=(cy-a*std::sin(angle)+b*std::cos(angle))/4;f.pixels[y*320+x]=flat?.4f:texture(u,v);}return f;}
int main(){@autoreleasepool{NSMutableArray *results=[NSMutableArray array];bool all=true;auto begin=std::chrono::steady_clock::now();
for(int mode=0;mode<4;mode++){
bool paired=mode>=2,rotate=mode==1;float cx=paired?(mode==2?.25:.75):.5;dy::VisionRegionTracker tracker;
std::vector<dy::FlowPoint> polygon={{-.5,-.5},{.5,-.5},{.5,.5},{-.5,.5}};
if(mode==1)polygon={{-.45,-.5},{.5,-.5},{.5,0},{0,0},{0,.5},{-.45,.5}};
tracker.setMask(polygon);bool ok=tracker.reset(frame(0,paired,rotate),{cx,.5,paired?.32f:.65f,paired?.54f:.65f,0});dy::TrackResult r=tracker.result();
NSMutableArray *steps=[NSMutableArray array];for(int i=1;i<6&&ok;i++){r=tracker.track(frame(i,paired,rotate));ok&=r.valid;[steps addObject:@{@"i":@(i),@"cx":@(r.cx),@"cy":@(r.cy),@"sx":@(r.scaleX),@"sy":@(r.scaleY),@"angle":@(r.rotation),@"confidence":@(r.confidence),@"valid":@(r.valid),@"failure":@(int(r.failure))}];}
float expectedX=cx+5*(paired?(mode==2?-1.5f:2.f):2.f)/320,expectedY=.5+5*(paired?(mode==2?1.f:-.75f):1.f)/192,expectedScale=1+5*(paired?(mode==2?-.025f:.035f):.01f);
bool precise=ok&&std::abs(r.cx-expectedX)<.006&&std::abs(r.cy-expectedY)<.008&&std::abs(r.scaleX-expectedScale)<.04&&std::abs(r.scaleY-expectedScale)<.04&&(!rotate||std::abs(r.rotation-.05)<.02);
bool loss=ok&&!tracker.track(frame(6,paired,rotate,true)).valid;all&=precise&&loss;[results addObject:@{@"mode":@(mode),@"geometryPass":@(precise),@"flatLossPass":@(loss),@"steps":steps}];
}
auto report=@{@"pass":@(all),@"milliseconds":@(std::chrono::duration<double,std::milli>(std::chrono::steady_clock::now()-begin).count()),@"results":results};NSData *data=[NSJSONSerialization dataWithJSONObject:report options:NSJSONWritingPrettyPrinted error:nil];fwrite(data.bytes,1,data.length,stdout);return all?0:1;}}