एक परियोजना के लिए, मैं यह करने के लिए किया था। मैंने जो किया है वह आपकी सभी आवश्यकताओं को पूरा नहीं कर सकता है लेकिन यह आपको एक विचार दे सकता है। सबसे पहले मैंने एक अनुक्रमिक नामकरण के साथ स्थानीय ड्राइव में हर रंग फ्रेम छवि को बचाया। फिर ffmpeg के साथ मैंने उन अनुक्रमिक छवि को वीडियो फ़ाइल में परिवर्तित कर दिया, मेरे मामले में यह mp4 वीडियो था, avi नहीं।
रंग छवि फ्रेम क्रमिक रूप से बचाने के लिए, आप नीचे दिए गए जैसे कोड हो सकता है,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Kinect;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
namespace Kinect_Video_Recorder
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
KinectSensor ks;
ColorFrameReader cfr;
byte[] colorData;
ColorImageFormat format;
WriteableBitmap wbmp;
BitmapSource bmpSource;
int imageSerial;
public MainWindow()
{
InitializeComponent();
ks = KinectSensor.GetDefault();
ks.Open();
var fd = ks.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);
uint frameSize = fd.BytesPerPixel * fd.LengthInPixels;
colorData = new byte[frameSize];
format = ColorImageFormat.Bgra;
imageSerial = 0;
cfr = ks.ColorFrameSource.OpenReader();
cfr.FrameArrived += cfr_FrameArrived;
}
void cfr_FrameArrived(object sender, ColorFrameArrivedEventArgs e)
{
if (e.FrameReference == null) return;
using (ColorFrame cf = e.FrameReference.AcquireFrame())
{
if(cf == null) return;
cf.CopyConvertedFrameDataToArray(colorData, format);
var fd = cf.FrameDescription;
// Creating BitmapSource
var bytesPerPixel = (PixelFormats.Bgr32.BitsPerPixel)/8;
var stride = bytesPerPixel * cf.FrameDescription.Width;
bmpSource = BitmapSource.Create(fd.Width, fd.Height, 96.0, 96.0, PixelFormats.Bgr32, null, colorData, stride);
// WritableBitmap to show on UI
wbmp = new WriteableBitmap(bmpSource);
kinectImage.Source = wbmp;
// JpegBitmapEncoder to save BitmapSource to file
// imageSerial is the serial of the sequential image
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmpSource));
using (var fs = new FileStream("./img/" + (imageSerial++) + ".jpeg", FileMode.Create, FileAccess.Write))
{
encoder.Save(fs);
}
}
}
}
}
उदाहरण से ऊपर jpeg प्रारूप में छवियों को बचाता है। यदि आपको इसे पीएनजी प्रारूप के रूप में सहेजने की आवश्यकता है तो PngBitmapEncoder
का उपयोग करें।
अब हमने हार्ड ड्राइव में अनुक्रमिक छवियों को सहेजा है। इन अनुक्रमिक छवियों को वीडियो फ़ाइल में कनवर्ट करने के लिए आप ffmpeg का उपयोग कर सकते हैं। आप Aforge.net का भी उपयोग कर सकते हैं। लेकिन मैंने कभी इसका इस्तेमाल नहीं किया है। मेरे मामले में मैंने नीचे दिए गए मेरे सी # कार्यक्रम से ffmpeg.exe
प्रक्रिया को बुलाया।
Process.Start("ffmpeg.exe", "-framerate 10 -i ./img/%d.jpeg -c:v libx264 -r 30 -pix_fmt yuv420p kinect_video.mp4");
नोट:
- अपने लक्ष्य बिल्ड 64 बनाओ। इससे कार्यक्रम की स्मृति सीमा बढ़ जाएगी।
- मैंने इसके बारे में एक बुनियादी implementation कोड किया है। यदि आप चाहें तो आप देख सकते हैं।
आशा है कि यह मदद करता है :)
स्रोत
2015-06-25 06:01:06
हम AVI फ़ाइल के रूप में वीडियो को बचाने के लिए EmguCV में VideoWriter classs और WriteFrame समारोह का उपयोग कर सकते हैं, लेकिन इस समारोह स्ट्रीमिंग नहीं, –
मैं प्रोग्राम है जो लगातार Kinect रंग डेटा को बचा सकता है विकसित करना चाहते हैं हार्ड रैम पर फ़ाइल करने के लिए स्रोत, क्योंकि स्मृति पर्याप्त नहीं है –