Форум программистов, компьютерный форум, киберфорум
C# .NET
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
0 / 0 / 0
Регистрация: 16.05.2015
Сообщений: 1
1

Сохранение видеопотока потока в файл

22.05.2015, 00:45. Показов 1214. Ответов 0
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Доброго времени суток форумчане! Возникла проблема с записью потока(веб камеры)
в файл.решил сделать простенький дипломный проект- основанный на системе видеонаблюдение. Использую библиотеку Aforge.Простите за "быдлокод"Ещё новичок в шарпе Просьба: Объяснить как делать запись потока в файл. Облазил уже весь форум, но так и не нашел дельных тем. За дельные советы + к карме
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using AForge;
using AForge.Imaging;
using AForge.Imaging.Filters;
using AForge.Video;
using AForge.Video.DirectShow;
using AForge.Vision;
using AForge.Vision.Motion;
using AForge.Video.VFW;
 
//Думал сделать через Emgu, но так и не смог
using Emgu.Util;
using Emgu.CV.Util;
using Emgu.CV.UI;
 
 
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
// подключение видеокамер
        FilterInfoCollection videoDevices;
// создание переменных для записи в файл
        AVIWriter writer1 = new AVIWriter("DIB ");
        AVIWriter writer2 = new AVIWriter("DIB ");
        AVIWriter writer3 = new AVIWriter("DIB ");
        AVIWriter writer4 = new AVIWriter("DIB ");
 
        //Датчик движение 
        MotionDetector detector1;
        MotionDetector detector2;
        MotionDetector detector3;
        MotionDetector detector4;
     
            
        float motion1, motion2, motion3, motion4;
        int width = 320;
        int height = 240;
        public Form1()
        {
            InitializeComponent();
 
            writer1.Codec = "DivX";
            writer2.Codec = "DivX";
            writer3.Codec = "DivX";
            writer4.Codec = "DivX";
            
         
            detector1 = new MotionDetector(new TwoFramesDifferenceDetector(), new MotionBorderHighlighting());
            detector2 = new MotionDetector(new TwoFramesDifferenceDetector(), new MotionBorderHighlighting());
            detector3 = new MotionDetector(new TwoFramesDifferenceDetector(), new MotionBorderHighlighting());
            detector4 = new MotionDetector(new TwoFramesDifferenceDetector(), new MotionBorderHighlighting());
 
            motion1 = 0;
            motion2 = 0;
            motion3 = 0;
            motion4 = 0;
 
            videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            if (videoDevices.Count == 0)
            {
                throw new Exception() ;
            }
 
            for (int i = 1, n = videoDevices.Count; i <= n; i++)
            {
                string cameraName = i + " : " + videoDevices[i - 1].Name;
 
                comboBox1.Items.Add(cameraName);
                comboBox2.Items.Add(cameraName);
                comboBox3.Items.Add(cameraName);
                comboBox4.Items.Add(cameraName);
                comboBox1.SelectedIndex = 0;
                comboBox2.SelectedIndex = 0;
                comboBox3.SelectedIndex = 0;
                comboBox4.SelectedIndex = 0;
 
 
 
            }
        }
 
 
 
        private void камераToolStripMenuItem_Click(object sender, EventArgs e)
        {
            groupBox1.Visible = true;
            groupBox2.Visible = false;
            groupBox3.Visible = false;
            groupBox4.Visible = false;
 
 
        }
 
        private void камерыToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            groupBox1.Visible = true;
            groupBox2.Visible = true;
            groupBox3.Visible = false;
            groupBox4.Visible = false;
        }
 
        private void камерыToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            groupBox1.Visible = true;
            groupBox2.Visible = true;
            groupBox3.Visible = true;
            groupBox4.Visible = false;
        }
 
        private void камерыToolStripMenuItem3_Click(object sender, EventArgs e)
        {
            groupBox1.Visible = true;
            groupBox2.Visible = true;
            groupBox3.Visible = true;
            groupBox4.Visible = true;
        }
 
        private void камераToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            comboBox1.Visible = true;
            button1.Visible = true;
            button2.Visible = true;
            button3.Visible = true;
            button13.Visible = true;
            button17.Visible = true;
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            comboBox1.Visible = false;
            button1.Visible = false;
            button2.Visible = false;
            button3.Visible = false;
            button13.Visible = false;
            button17.Visible = false;
        }
 
        private void камераToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            comboBox2.Visible = true;
            button4.Visible = true;
            button5.Visible = true;
            button6.Visible = true;
            button14.Visible = true;
            button18.Visible = true;
        }
 
        private void камераToolStripMenuItem3_Click(object sender, EventArgs e)
        {
            comboBox3.Visible = true;
            button7.Visible = true;
            button8.Visible = true;
            button9.Visible = true;
            button15.Visible = true;
            button19.Visible = true;
        }
 
        private void камераToolStripMenuItem4_Click(object sender, EventArgs e)
        {
            comboBox4.Visible = true;
            button10.Visible = true;
            button11.Visible = true;
            button12.Visible = true;
            button16.Visible = true;
            button20.Visible = true;
        }
 
        private void button4_Click(object sender, EventArgs e)
        {
            comboBox2.Visible = false;
            button4.Visible = false;
            button5.Visible = false;
            button6.Visible = false;
            button14.Visible = false;
            button18.Visible = false;
        }
 
        private void button7_Click(object sender, EventArgs e)
        {
            comboBox3.Visible = false;
            button7.Visible = false;
            button8.Visible = false;
            button9.Visible = false;
            button15.Visible = false;
            button19.Visible = false;
        }
 
        private void button10_Click(object sender, EventArgs e)
        {
            comboBox4.Visible = false;
            button10.Visible = false;
            button11.Visible = false;
            button12.Visible = false;
            button16.Visible = false;
            button20.Visible = false;
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
 
 
            VideoCaptureDevice videoSource1 = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString);
       
 
            videoSource1.DesiredFrameRate = 10;
 
           
            videoSourcePlayer1.VideoSource = videoSource1;
            videoSourcePlayer1.Start();
        }
 
        private void button6_Click(object sender, EventArgs e)
        {
            VideoCaptureDevice videoSource2 = new VideoCaptureDevice(videoDevices[comboBox2.SelectedIndex].MonikerString);
            videoSource2.DesiredFrameRate = 10;
 
            videoSourcePlayer2.VideoSource = videoSource2;
            videoSourcePlayer2.Start();
        }
 
        private void button9_Click(object sender, EventArgs e)
        {
            VideoCaptureDevice videoSource3 = new VideoCaptureDevice(videoDevices[comboBox3.SelectedIndex].MonikerString);
            videoSource3.DesiredFrameRate = 10;
 
            videoSourcePlayer3.VideoSource = videoSource3;
            videoSourcePlayer3.Start();
        }
 
        private void button12_Click(object sender, EventArgs e)
        {
            VideoCaptureDevice videoSource4 = new VideoCaptureDevice(videoDevices[comboBox4.SelectedIndex].MonikerString);
            videoSource4.DesiredFrameRate = 10;
 
            videoSourcePlayer4.VideoSource = videoSource4;
            videoSourcePlayer4.Start();
        }
 
      
   
 
        
        private void button11_Click(object sender, EventArgs e)
        {
            videoSourcePlayer4.Stop();
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
          
            videoSourcePlayer1.Stop();
            }
        
 
        private void button8_Click(object sender, EventArgs e)
        {
            videoSourcePlayer3.Stop();
        }
 
        private void button5_Click(object sender, EventArgs e)
        {
            videoSourcePlayer2.Stop();
        }
 
        private void videoSourcePlayer1_NewFrame(object sender, ref Bitmap image1)
        {
           
            motion1 = detector1.ProcessFrame(image1);
       
        }
 
        private void videoSourcePlayer2_NewFrame(object sender, ref Bitmap image2)
        {
 
            motion2 = detector2.ProcessFrame(image2);
        }
 
        private void videoSourcePlayer3_NewFrame(object sender, ref Bitmap image3)
        {
            motion3 = detector3.ProcessFrame(image3);
 
        }
 
        private void videoSourcePlayer4_NewFrame(object sender, ref Bitmap image4)
        {
 
            motion4 = detector4.ProcessFrame(image4);
        }
 
        private void всеКамерыToolStripMenuItem_Click(object sender, EventArgs e)
        {
            comboBox1.Visible = true;
            comboBox2.Visible = true;
            comboBox3.Visible = true;
            comboBox4.Visible = true;
            button1.Visible = true;
            button2.Visible = true;
            button3.Visible = true;
            button4.Visible = true;
            button5.Visible = true;
            button6.Visible = true;
            button7.Visible = true;
            button8.Visible = true;
            button9.Visible = true;
            button10.Visible = true;
            button11.Visible = true;
            button12.Visible = true;
            button13.Visible = true;
            button14.Visible = true;
            button15.Visible = true;
            button16.Visible = true;
            button17.Visible = true;
            button18.Visible = true;
            button19.Visible = true;
            button20.Visible = true;
 
 
        }
 
        private void Камера1_Tick(object sender, EventArgs e)
        {
 
 
            textBox1.Text = String.Format("{0:00.0000}", motion1);
            textBox2.Text = String.Format("{0:00.0000}", motion2);
            textBox3.Text = String.Format("{0:00.0000}", motion3);
            textBox4.Text = String.Format("{0:00.0000}", motion4);
        }
 
        private void RecordingCam1_Tick(object sender, EventArgs e)
        {
            var date = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Hour + "-"
                + DateTime.Now.Minute + "-" + DateTime.Now.Second + ".Jpeg";
 
               
        }
 
        private void button13_Click(object sender, EventArgs e)
        {
            
        }
 
        private void button17_Click(object sender, EventArgs e)
        {
            writer1.Close();
        }
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
22.05.2015, 00:45
Ответы с готовыми решениями:

Сохранение потока данных в файл
Здравствуйте. Помогите написать верный код для сохранения потока данных в файл, чтото я уже что...

Запись видеопотока с экрана в файл
Здравствуйте, как работает приложение которое записывает видеопоток с экрана в файл? (bandicam...

Сохранение файла на уровне потока
Как из этой функции сохранения файла на уровне операционки сделать функцию сохранения файла на...

Сохранение звука с потока в Delphi. (Recording)
Воспроизвожу несколько аудио одновременно. Используя фунцию mciSendString таким способом:...

0
22.05.2015, 00:45
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
22.05.2015, 00:45
Помогаю со студенческими работами здесь

Добавить к программе след действия: Сохранение и загрузка информации в текст. файл. Сохранение и загрузка информации в типизированный файл.
Помогите добавить к программе след действия: Сохранение и загрузка информации в текст. файл....

Сохранение положения компонента на форме (Сохранение параметра в Ini-файл)
Не знаю верно ли назвал тему. Доброго вечера тебе, всяк сюда входящий. Подскажите пожалуйста с...

При сохранение файла word (права доступа на сохранение ограничены) появляется пустой файл
Добрый день! Проблема такая: Допустим есть пользователь, у которого ограничены права (может...

Сохранение файла Excel, заполненного из не основного потока
Доброго всем времени суток, господа. Помогите решить следующею проблемку. Данный код, открывает...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
1
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru