示例#1
0
    private void onImageUpdate(WebCamTexture tex)
    {
        TrackPointsJob pointJob = trackPointJob(tex);
        JobHandle      handle   = pointJob.Schedule();

        handle.Complete();

        int l = pointJob.r[1];

        while (pointObjs.Count < l)
        {
            pointObjs.Add(Instantiate(pointObj, transform));
        }

        int x = 0;

        foreach (var o in pointObjs)
        {
            o.SetActive(false);
            if (x < l)
            {
                o.transform.position = new Vector3(pointJob.result[x].x * Width, pointJob.result[x].y * Height, 0f);
                o.SetActive(true);
                x++;
            }
        }

        pointJob.Dispose();
    }
示例#2
0
    private TrackPointsJob trackPointJob(WebCamTexture tex)
    {
        TrackPointsJob pointsJob = new TrackPointsJob();

        pointsJob.color               = math.pow(new float3(Color.r, Color.g, Color.b), GammaCorrection);
        pointsJob.threshold           = Threshold;
        pointsJob.mergeDistance       = MergeDistance;
        pointsJob.minSpacingThreshold = MinSpacingThreshold;
        pointsJob.width               = tex.width;
        pointsJob.height              = tex.height;

        values = tex.GetPixels32(values);

        int l = values.Length;

        pointsJob.values    = new NativeArray <Color32>(values, Allocator.TempJob);
        pointsJob.result    = new NativeArray <float2>(l, Allocator.TempJob);
        pointsJob.r         = new NativeArray <int>(l, Allocator.TempJob);
        pointsJob.r2        = new NativeArray <float>(l, Allocator.TempJob);
        pointsJob.pixels    = new NativeArray <float2>(l, Allocator.TempJob);
        pointsJob.positions = new NativeArray <PointValues>(l, Allocator.TempJob);

        return(pointsJob);
    }