- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在使用我的网络摄像头、opencv 和 emgucv 捕获图片时遇到了一个特殊问题。
我以前用过这个功能,一直很好用,但是现在不知道为什么,图片框显示的是之前拍的照片。让我解释一下:
我启动程序 - 我按下按钮并在拍照前等待几秒钟 - 我使用 img = capturez.QueryFrame() 拍照 - 我在 PictureBox 中显示图片。这是代码:
Private Sub startButton_Click() Handles startButton.Click
Dim timeToWait As Integer
PictureBox1.Image = Nothing
If globalGMT <> Nothing And globalLatitude <> Nothing And globalLongitude <> Nothing Then
'If TextBox_GMT.Text IsNot Nothing And TextBox_LAT.Text IsNot Nothing And TextBox_LON.Text IsNot Nothing Then
SunPosition(globalGMT, globalLatitude, globalLongitude, ELEVACIONDELSOL, AZIMUTDELSOL)
End If
startButton.Enabled = False
SetDefaultTimeButton.Enabled = False
SetParameters.Enabled = False
TextBoxTime.Text = System.DateTime.UtcNow
timeToWait = globalTimeLeft
For i = 0 To timeLeft
wait()
i += 1
timeToWait -= 1
timeLabel.Text = timeToWait & " seconds"
Next
Dim img As Image(Of Bgr, Byte) = capturez.QueryFrame()
For x = 0 To img.Width - 1
For y = 0 To img.Height - 1
Dim pixelColor As Bgr = img(y, x)
If (pixelColor.Blue >= 200 And pixelColor.Blue <= 255) And
(pixelColor.Green >= 200 And pixelColor.Green <= 255) And (pixelColor.Red >= 200 And pixelColor.Red <= 255) Then
pixelColor.Blue = 255
pixelColor.Green = 255
pixelColor.Red = 255
img(y, x) = pixelColor
Else
pixelColor.Blue = 0
pixelColor.Green = 0
pixelColor.Red = 0
img(y, x) = pixelColor
End If
Next
Next
PictureBox1.Image = img.ToBitmap
startButton.Enabled = True
SetParameters.Enabled = True
SetDefaultTimeButton.Enabled = True
SetForm()
End Sub
函数 wait() 如下所示:
Private Sub wait()
Dim seconds As Integer = 1
For i As Integer = 0 To seconds * 100
System.Threading.Thread.Sleep(10)
'Application.DoEvents()
Next
End Sub
也许你会问,为什么不用定时器呢?这是因为使用计时器我遇到了完全相同的问题。下面是使用定时器的代码:
'This function will start the activity of the form
Private Sub startButton_Click() Handles startButton.Click
Dim timeToWait As Integer
PictureBox1.Image = Nothing
If globalGMT <> Nothing And globalLatitude <> Nothing And globalLongitude <> Nothing Then
'If TextBox_GMT.Text IsNot Nothing And TextBox_LAT.Text IsNot Nothing And TextBox_LON.Text IsNot Nothing Then
SunPosition(globalGMT, globalLatitude, globalLongitude, ELEVACIONDELSOL, AZIMUTDELSOL)
End If
startButton.Enabled = False
SetDefaultTimeButton.Enabled = False
SetParameters.Enabled = False
TextBoxTime.Text = System.DateTime.UtcNow
StartButtonTimer.Start()
End Sub
'This function will start the timer of the form
Private Sub StartButtonTimer_Tick() Handles StartButtonTimer.Tick
Dim X As Integer
Dim Y As Integer
If timeLeft > 0 Then
timeLeft -= 1
timeLabel.Text = timeLeft & " seconds"
'DLE prueba tomar foto después del tiempo especificado - pongo a negro el fondo del picturebox
PictureBox1.BackColor = Color.Black
Else
'DLE prueba tomar foto después del tiempo especificado - hago foto de lo que ve la camara
Dim img As Image(Of Bgr, Byte) = capturez.QueryFrame()
For X = 0 To img.Width - 1
For Y = 0 To img.Height - 1
Dim pixelColor As Bgr = img(Y, X)
If (pixelColor.Blue >= 200 And pixelColor.Blue <= 255) And
(pixelColor.Green >= 200 And pixelColor.Green <= 255) And
(pixelColor.Red >= 200 And pixelColor.Red <= 255) Then
pixelColor.Blue = 255
pixelColor.Green = 255
pixelColor.Red = 255
img(Y, X) = pixelColor
Else
pixelColor.Blue = 0
pixelColor.Green = 0
pixelColor.Red = 0
img(Y, X) = pixelColor
End If
Next
Next
StartButtonTimer.Stop()
PictureBox1.Image = img.ToBitmap
startButton.Enabled = True
SetParameters.Enabled = True
SetDefaultTimeButton.Enabled = True
SetForm()
End If
End Sub
函数 SetForm() 只启用了一些按钮。
问题是:我拍第一张照片 - 图片框显示第一张照片。我拍第二张照片 - 图片框再次显示第一张照片。我拍了第三张照片 - 图片框显示了第二张照片。我拍了第四张照片 - 图片框显示了第三张照片。......拍照后,我只识别一种颜色,并以白色显示该颜色,以黑色显示图片的其余部分(如果有人需要此解释)
感谢您能给我的任何帮助!
编辑:如果我在函数末尾添加这一行:Dim image As Image(Of Bgr, Byte) = capturez.QueryFrame(),效果很好:
...
...
Next
StartButtonTimer.Stop()
PictureBox1.Image = img.ToBitmap
startButton.Enabled = True
SetParameters.Enabled = True
SetDefaultTimeButton.Enabled = True
SetForm()
End If
Dim image As Image(Of Bgr, Byte) = capturez.QueryFrame()
End Sub
下课
我不会无缘无故地使用最后一个变量,只是我声明它而不使用它。我不明白为什么用这条线效果很好,而当我删除它时,它不起作用..
最佳答案
我花了一段时间才弄明白这个问题,但我相信问题在于您没有Dispose
您的捕获。由于您仅在单击按钮时捕获一帧(并且您没有实时网络摄像头流),因此您应该在使用后 Dispose
处理 Capture
对象。现在发生的事情是您请求一个新框架,Capture
对象将返回旧框架,然后开始检索另一个准备好供下次使用的框架。因此,如果您将另一个 QueryFrame()
放在方法的末尾,它会再次运行,因为旧框架已被覆盖。
这应该可以解决您的问题:
'Make sure you can use your retrieved image even after the dispose
Dim img As Image(Of Bgr, Byte);
'Create a new capture object
Using capturez As New Capture
'Since it's a new object the webcam is forced to retrieve a frame now
'Also, use Copy() to make sure your image is still available after diposing
img = capturez.QueryFrame().Copy()
End Using 'Dispose the object now
'Now do with your img object whatever you want!
关于vb.net - 拍摄一张并显示之前的一张 - VB - OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43211664/
我的一个页面上有一个 map 控件,我希望拍摄它的照片并将其显示在不同的屏幕上。有谁知道我怎样才能实现这一目标?该 map 位于 范围内. 最佳答案 您应该使用 WriteableBitmap 类的
我正在使用 Qt 4.5 和 qgraphicsscene/view 向用户显示视频。 我想提供一个“获取快照”按钮,我相信有一种非常简单的方法可以让我想到的一切都简单得多。 我怎样才能优雅地做到这一
使用以下代码拍摄 AGSMapView 的快照 此代码将设置 kEAGLDrawablePropertyRetainedBacking 属性,这是必需的,否则它将拍摄白色快照。 let layer =
我目前正在使用 direct X 用 c++ 编写游戏,目前有一个 vector 来存储绘制我所有的 Sprite 。我无法让子弹在 vector 中工作。子弹射了,但应该有 50 颗却只射出一颗 /
如何获取安卓手机的打印屏幕??我正在用 GPS 做一个应用程序。所以我无法使用模拟器拍摄打印照片。有没有应用程序可以做到这一点? 最佳答案 通过 USB 连接您的手机,转到 Eclipse 中的调试透
我有以下 JSON Firebase 数据库: { "fruits": { "apple": { "name": "Gala", "ur
我正在做一个项目,它应该获取 iPhone 中视频图标内的视频。任何人都可以通过提供链接或其他方式来帮助我吗?如有任何帮助,我们将不胜感激。 谢谢 最佳答案 这是不可能的,因为我们无法从一个应用程序内
如何链接到嵌入 Flash 视频的快照而不是实际的 Flash 视频,以减少网站的加载时间? 最佳答案 是的,事实上这是一种经常使用的方法。您从带有播放按钮覆盖层的图像开始。单击后,图像元素将替换为播
我正在用这个截取 avPlayer 的屏幕截图.. print(startTime) print(Float64(startTime)) var time: CMTime =
我试图从 nib 加载一个 View ,配置它,并拍摄它的快照,而不是将它添加到屏幕上: + (void)composeFromNibWithImage:(UIImage*)catImage comp
我正在制作一个 tvOS 应用程序,我希望它看起来与电影应用程序相似。因此我有一个 UICollectionView。现在我的单元格不仅仅是简单的 UIImageView,而是更复杂一些。 我仍然想要
Apple 建议从提交给应用商店的屏幕截图中裁剪掉状态栏。在预览版中手动执行此操作非常繁琐且容易出错。 是否有任何开发人员有任何最佳实践建议或自动化技术来加速此过程?目标是将 iPad 和/或 iPh
我所有的搜索都涉及更一般的 arc/sin/cos 用法或射击到鼠标位置。我希望用键盘瞄准并发射射弹,并且作为网络类(class)中的菜鸟做一个项目,我已经从头开始做了很多工作,但我陷入了困境。我当前
假设我有一个服务: public interface ICustomersService { IObservable Customers { get; } }
在我的 IOS 应用程序中,我正在截取 UIImageView 的屏幕截图。如附件照片所示,它非常完美。但是在这里,我采用了 UIImageView content mode aspect fit 。
我正在使用 WebRTC 在两个用户之间建立视频聊天。我想拍一张显示其中一个人的 localView View 。 这是我的类,它使用 configureLocalPreview 方法将视频流与 UI
EBS 文档指出: As an example, volumes that operate with 20 GB or less of modified data since their most r
import qualified Data.Vector as V import Control.Lens import Data.Vector.Lens v = V.fromList [V.from
我在我的应用程序中的“查看”按钮中有一个用于使用以下代码拍摄快照的按钮 open func takeScreenshot(_ shouldSave: Bool = true) -> UIImage?
我基本上是在尝试在我的 Activity 中捕获相对布局的屏幕截图并将其保存为 PNG 图像。然后我需要将它作为位图文件检索。我编写了一些代码来完成此操作,但遗憾的是屏幕截图未保存在我的设备上。 XM
我是一名优秀的程序员,十分优秀!