好的,我一直在尝试通过网络摄像头做一些特定的视频.我有一个Lumenera Infinity 2显微镜,我试图从中提取饲料,并希望能够在进入时修改饲料.由于我找不到使用Video Source Player的方法,我决定改为拉动每个帧(相机的最大15fps)作为位图,以便我可以在那里进行修改.
问题是:我有一个巨大的内存泄漏.当我使用videoSourcePlayer运行视频时,它使用大约30兆的徘徊.当我将帧拉动为位图时,它会在几秒钟内打破1 gig的内存.
我错过了什么,这里?我认为自动垃圾收集会在旧框架无法访问时挖出旧框架.我应该尝试强制在位图上进行垃圾回收吗?或者它完全是另一回事,而且我还是错过了它.
FilterInfoCollection captureDevices;
VideoCaptureDevice cam;
Bitmap bitmap;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
captureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (captureDevices.Count == 0)
throw new ApplicationException();
CameraSelectComboBox.Items.Clear();
foreach (FilterInfo device in captureDevices)
{
CameraSelectComboBox.Items.Add(device.Name);
}
CameraSelectComboBox.SelectedIndex = 0;
CameraSelectComboBox.Enabled = true;
}
catch (ApplicationException)
{
CameraSelectComboBox.Enabled = false;
}
}
private void connectButton_Click(object sender, EventArgs e)
{
cam = new VideoCaptureDevice(captureDevices[CameraSelectComboBox.SelectedIndex].MonikerString);
cam.NewFrame -= Handle_New_Frame; //Just to avoid …Run Code Online (Sandbox Code Playgroud) 我目前正在与AForge合作,并有一个新的帧事件,将帧作为位图发布到图片框中.它有90%的时间很棒......除非我在winform上捣乱.更改组合框,移动窗口或任何类似的风险会导致Picturebox从视频切换到大红色X.下面的代码示例:
private void connectButton_Click(object sender, EventArgs e)
{
try
{
cam = new VideoCaptureDevice(captureDevices[CameraSelectComboBox.SelectedIndex].MonikerString);
cam.NewFrame -= Handle_New_Frame; //Just to avoid the possibility of a second event handler being put on
cam.NewFrame += new AForge.Video.NewFrameEventHandler(Handle_New_Frame);
cam.Start();
}
catch
{
MessageBox.Show("An error has occured with connecting to the specified webcam. The application will now close!");
Application.Exit();
}
}
private void Handle_New_Frame(object sender, NewFrameEventArgs eventArgs)
{
try
{
if (bitmap != null)
bitmap.Dispose(); //Without this, memory goes nuts
bitmap = new Bitmap(eventArgs.Frame);
} …Run Code Online (Sandbox Code Playgroud) 我最近一直在努力学习python,遇到了一些我很难理解它是如何工作的事情.首先,它是一个列表的设计.
有问题的列表来自这篇安全文章,讨论了一个简单的模糊测试工具:http://blog.securestate.com/post/2009/10/06/How-a-simple-python-fuzzer-brought-down-SMBv2-在-2- seconds.aspx
有问题的实际清单是:
#Negotiate Protocol Request
packet = [chr(int(a, 16)) for a in """
00 00 00 90
ff 53 4d 42 72 00 00 00 00 18 53 c8 00 00 00 00
00 00 00 00 00 00 00 00 ff ff ff fe 00 00 00 00
00 6d 00 02 50 43 20 4e 45 54 57 4f 52 4b 20 50
52 4f 47 52 41 4d 20 31 2e 30 …Run Code Online (Sandbox Code Playgroud) 我目前有一个查询,它总结了一组值并按日期对它们进行分组.结果看起来像这样:
Date Item2 Item2 Item3 Item4 Item5
2013-05-31 1 30 0 0 129
2013-06-03 0 90 0 15 78
2013-06-04 0 50 0 1 124
2013-06-05 0 100 0 17 58
2013-06-06 0 24 0 0 105
2013-06-07 0 50 0 1 83
2013-06-10 0 45 2 42 64
2013-06-11 3 43 0 14 90
2013-06-12 2 44 0 36 88
2013-06-13 1 34 0 15 92
Run Code Online (Sandbox Code Playgroud)
我用来检索该结果的查询看起来像这样
SELECT CONVERT(NVARCHAR(10), TheDate, 120) 'Date',
(SUM(CASE WHEN itemID = 1 THEN 1 …Run Code Online (Sandbox Code Playgroud) 我有一个 linq 语句,它对 DataTable 中的行进行平均并将它们显示在图表上,按日期和时间分组。
有一个大问题:由于一天中的特定时间根本没有任何事情发生,因此返回了许多 0 值。这些正在扭曲我的平均值
一天中的不同时间在不同的列中可能有 0,所以我不能只删除列中带有 0 的每一行(干净地),因为我最终会在数据表中没有剩余的行,或者至少我不能在任何情况下都想一个干净的方法来做到这一点。
这就是我所拥有的:
var results = from row2 in fiveDayDataTable.AsEnumerable()
group row2 by ((DateTime)row2["TheDate"]).TimeOfDay
into g
select new
{
Time = g.Key,
AvgItem1 = g.Average(x => (int)x["Item1"]),
AvgItem2 = g.Average(x => (int)x["Item2"]),
AvgItem3 = g.Average(x => (int)x["Item3"]),
AvgItem4 = g.Average(x => (int)x["Item4"]),
AvgItem5 = g.Average(x => (int)x["Item5"]),
};
Run Code Online (Sandbox Code Playgroud)
我不知道这是否可能,所以我想我会问 - 有没有办法在没有 0 的情况下做平均值?
谢谢!
我正在尝试使用Console.ReadKey()函数来拦截用户的击键并重建他们在屏幕上键入的内容(因为我需要经常清除屏幕,经常移动光标,这似乎比如最全面的方法,确保他们输入的内容不会消失或出现在整个屏幕上的随机点.
我的问题是:在做类似的事情时,有没有其他人经历过1个字符"滞后",因为缺乏更好的术语?说我想输入单词"This".当我按"T"时,无论我等多久都没有出现.当我按"h"时,出现"T"."我","h"出现.直到我按下另一个键,即使该键是空格键,我输入的字母也不会出现.有没有人对我做错了什么有任何建议?我确定它与我如何使用Console.Readkey有关,我只是看不出有什么替代方法可行.我在下面附上了一个简单的小例子.
谢谢!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ConsoleApplication2
{
class Program
{
private static string userInput = "";
static ConsoleKeyInfo inf;
static StringBuilder input = new StringBuilder();
static void Main(string[] args)
{
Thread tickThread = new Thread(new ThreadStart(DrawScreen));
Thread userThread = new Thread(new ThreadStart(UserEventHandler));
tickThread.Start();
Thread.Sleep(1);
userThread.Start();
Thread.Sleep(20000);
tickThread.Abort();
userThread.Abort();
}
private static void DrawScreen()
{
while (true)
{
Console.Clear();
Console.SetCursorPosition(0, 0);
Console.Write("> " + userInput);
Thread.Sleep(300);
}
}
private static void UserEventHandler() …Run Code Online (Sandbox Code Playgroud) 我有一个功能,它接收图像并调整大小以适应画布,同时保持其纵横比.此代码只是此答案中代码的微小修改版本: c#图像调整大小到不同大小,同时保留纵横比
对于此示例,我的画布高度为642,我的画布宽度为823.
当我运行以下功能时,该行
graphic.DrawImage(image, posX, posY, newWidth, newHeight);
Run Code Online (Sandbox Code Playgroud)
似乎对图像大小没有任何作用.进去:
Image.Height == 800,
Image.Width == 1280.
newHeight = 514,
newWidth == 823
Run Code Online (Sandbox Code Playgroud)
在运行graphic.DrawImage之后
Image.Height == 800,
Image.Width == 1280.
Run Code Online (Sandbox Code Playgroud)
如您所见,Image的高度和宽度保持不变.
有没有人看到会导致这种情况发生的明显错误?谢谢!
private Bitmap resizeImage(Bitmap workingImage,
int canvasWidth, int canvasHeight)
{
Image image = (Bitmap)workingImage.Clone();
System.Drawing.Image thumbnail =
new Bitmap(canvasWidth, canvasHeight);
double ratioX = (double)canvasWidth / (double)workingImage.Width;
double ratioY = (double)canvasHeight / (double)workingImage.Height;
double ratio = ratioX < ratioY ? ratioX : ratioY;
int newHeight = Convert.ToInt32((double)workingImage.Height * ratio);
int newWidth …Run Code Online (Sandbox Code Playgroud) c# ×5
aforge ×2
winforms ×2
aspect-ratio ×1
average ×1
datatable ×1
drawimage ×1
fuzzer ×1
graphics ×1
linq ×1
list ×1
memory-leaks ×1
picturebox ×1
python ×1
sql ×1
sql-server ×1
t-sql ×1
webcam ×1