使用双阈值

发布于 2024-10-19 05:02:04 字数 1018 浏览 2 评论 0原文

我使用 Bitmapdata 对象的 Threshold 方法从相机视频源制作一些运动按钮。

它使用 1 个按钮(1 个矩形上的 1 个阈值,即屏幕上的按钮),如下所示:

//...
actualFrame.draw(oldFrame, new Matrix(), null, "difference"); 
 changedPixels = actualFrame.threshold(actualFrame,rect,pt1,">",0xFF111111,0xFF00FF00,0x00FFFFFF,false); 
    if (changedPixels > 200)  {
     //my actions
    }
//...

这是工作,阈值返回 2 个距离之间更改的像素数,如果 > 200(我必须调整这个),一个动作被提交。

问题是我需要超过 1 个按钮,并且

actualFrame.draw(oldFrame, new Matrix(), null, "difference"); 
changedPixels = actualFrame.threshold(actualFrame,rect,pt1,">",0xFF111111,0xFF00FF00,0x00FFFFFF,false); 
if (changedPixels > 200)  {
       //my actions
}

changedPixels2 = actualFrame.threshold(actualFrame,rect,pt2,">",0xFF111111,0xFF00FF00,0x00FFFFFF,false); 
if (changedPixels2 > 200)  {
    //my actions
}

我对按钮使用相同的尺寸(矩形 rect 相同),以及不同的 (X,Y) 位置:pt2 与 pt1

但这不起作用,changedPixels2 是始终为 0,(阈值未应用于图像)

我该如何纠正这个问题?

谢谢阿莱西奥

im using the Threshold method of the Bitmapdata object to make some motion buttons from a camera video source.

It's working with 1 button (1 threshold on 1 rectangle, that is my button onscreen), like this:

//...
actualFrame.draw(oldFrame, new Matrix(), null, "difference"); 
 changedPixels = actualFrame.threshold(actualFrame,rect,pt1,">",0xFF111111,0xFF00FF00,0x00FFFFFF,false); 
    if (changedPixels > 200)  {
     //my actions
    }
//...

This is working, threshold returns the number of changed pixel between 2 istants, if that is > of 200 (i have to tune this), an action is commited.

The problem is that i need more than 1 button, and

actualFrame.draw(oldFrame, new Matrix(), null, "difference"); 
changedPixels = actualFrame.threshold(actualFrame,rect,pt1,">",0xFF111111,0xFF00FF00,0x00FFFFFF,false); 
if (changedPixels > 200)  {
       //my actions
}

changedPixels2 = actualFrame.threshold(actualFrame,rect,pt2,">",0xFF111111,0xFF00FF00,0x00FFFFFF,false); 
if (changedPixels2 > 200)  {
    //my actions
}

i use the same dimension for the button (the rectangle rect is the same), and a different (X,Y) position: pt2 vs pt1

But this is not working, changedPixels2 is always 0, (the threshold isnt applied to the image)

how can i correct this?

Thanks

Alessio

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萝莉病 2024-10-26 05:02:04

我的理解是,阈值在满足正确条件时会更改 BitmapData。您是否尝试过创建另一个actualFrame实例,而不是在同一个实例上运行阈值两次?

actualFrame.draw(oldFrame, new Matrix(), null, "difference"); 
changedPixels = actualFrame.threshold(actualFrame,rect,pt1,">",0xFF111111,0xFF00FF00,0x00FFFFFF,false); 
if (changedPixels > 200)  {
       //my actions
}

actualFrame2.draw(oldFrame, new Matrix(), null, "difference");
changedPixels2 = actualFrame2.threshold(actualFrame2,rect,pt2,">",0xFF111111,0xFF00FF00,0x00FFFFFF,false); 
if (changedPixels2 > 200)  {
    //my actions
}

My understanding is that threshold changes the BitmapData when it meets the correct conditions. Have you tried creating another instance of actualFrame instead of running threshold on the same one twice?

actualFrame.draw(oldFrame, new Matrix(), null, "difference"); 
changedPixels = actualFrame.threshold(actualFrame,rect,pt1,">",0xFF111111,0xFF00FF00,0x00FFFFFF,false); 
if (changedPixels > 200)  {
       //my actions
}

actualFrame2.draw(oldFrame, new Matrix(), null, "difference");
changedPixels2 = actualFrame2.threshold(actualFrame2,rect,pt2,">",0xFF111111,0xFF00FF00,0x00FFFFFF,false); 
if (changedPixels2 > 200)  {
    //my actions
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文