Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > อยากทราบวิธีแก้ปัญหาดึงภาพมาจากกล้องแล้วรีโซลูชั่นไม่ตรงกันครับ Aforge.net c#.net



 

อยากทราบวิธีแก้ปัญหาดึงภาพมาจากกล้องแล้วรีโซลูชั่นไม่ตรงกันครับ Aforge.net c#.net

 



Topic : 127529



โพสกระทู้ ( 0 )
บทความ ( 0 )



สถานะออฟไลน์




คือผมกำลังเขียนโค้ดให้ตัวโปรแกรมสามารถแสดงภาพจากกล้องได้ครับ ทีนี้ตอนตั้งค่า resolution ของกล้องจากภายนอกมันเป็น1920*1080i 59.94(out 29.97) ครับ แต่ว่าภาพที่เรียกมาในคอมโดยใช้ Aforge มันได้ ออกมาเป็น 720*486 ครับ ล็อกอยู่อย่างนั้นไม่สามารถที่จะปรับเปลี่ยนได้ครับทำให้ภาพไม่แสดงผลที่จอคอม กลายเป็นภาพสีดำครับ

ทางนี้เป็นโค้ดบางส่วนที่ใช้งานกับโปรแกรมครับ เอามาเฉพาะส่วนแสดงผลภาพครับ

Code (C#)
using System;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using Accord.Video.FFMPEG;
using AForge.Video;
using AForge.Video.DirectShow;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf;
using Microsoft.Win32;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO.Ports;
using Microsoft.Kinect;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Threading;




  private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            
            StopCameraPtz();
            Dispose();
            Thread.Sleep(1000);
           
        }

        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            StartCameraPTz();
        }

        private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            try
            {
                if (_recording)
                {

                    if (_firstFrameTime != null)
                    {
                        _writer.WriteVideoFrame(eventArgs.Frame, DateTime.Now - _firstFrameTime.Value);
                       
                    }
                    else
                    {
                        _writer.WriteVideoFrame(eventArgs.Frame);
                        _firstFrameTime = DateTime.Now;
                        Console.WriteLine(_firstFrameTime.Value);

                    }//
                }
               
                using (var bitmap = (Bitmap)eventArgs.Frame.Clone())
                {
                    Console.WriteLine (bitmap.Size.Width);
                    Console.WriteLine(bitmap.Size.Height);
                    
                    bi = bitmap.ToBitmapImage();
                   
                    bitmap.Dispose();
                }
                Console.WriteLine(bi.Width+"x"+bi.Height);
                bi.Freeze(); // avoid cross thread operations and prevents leaks
                Dispatcher.BeginInvoke(new ThreadStart(delegate { ImagePtz.Source = bi; }));
            }
            catch (Exception exc)
            {
                MessageBox.Show("Error on _videoSource_NewFrame:\n" + exc.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                StopCameraPtz();
            }
            Thread.Sleep(50);
        }

        private void btnStop_Click(object sender, RoutedEventArgs e)
        {
            StopCameraPtz();
        }
        private void btnStoprec_Click(object sender, RoutedEventArgs e)
        {
            _recording = false;
            _writer.Close();
            _writer.Dispose();
        }

        private void btnStartrec_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new SaveFileDialog();
            dialog.FileName = "Video1";
            dialog.DefaultExt = ".mp4";
            dialog.AddExtension = true;
            var dialogresult = dialog.ShowDialog();
            if (dialogresult != true)
            {
                return;
            }
            _firstFrameTime = null;
            _writer = new VideoFileWriter();
            Console.WriteLine(bi.Format);
            _writer.Open(dialog.FileName, (int)Math.Round(bi.Width, 0), (int)Math.Round(bi.Height, 0), 30, VideoCodec.H264 );
            
            // _writer.Open(dialog.FileName,   1920 , 1080, 60, VideoCodec.H264, 100000);
            _recording = true;
        }

        private void btnSavesnp_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new SaveFileDialog();
            dialog.FileName = "Snapshot1";
            dialog.DefaultExt = ".png";
            var dialogresult = dialog.ShowDialog();
            if (dialogresult != true)
            {
                return;
            }
            var encoder = new PngBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(bi));
            using (var filestream = new FileStream(dialog.FileName, FileMode.Create))
            {
                encoder.Save(filestream);
            }
        }

        public void Dispose()
        {
            if (_videoSource != null && _videoSource.IsRunning)
            {
                _videoSource.SignalToStop();
                _videoSource.WaitForStop();
                _videoSource = null;
            }
            _writer?.Dispose();
          
        }

        private void GetVideoDevices()
        {
            var devies = new FilterInfoCollection(FilterCategory.VideoInputDevice);
      
            foreach (FilterInfo filterInfo in devies)
            {
                Console.WriteLine(filterInfo.Name);
                VideoDevices.Add(filterInfo);
                
            }
         
            if (VideoDevices.Any())
            {
                CurrentDevice = VideoDevices[0];
            }
            else
            {
                MessageBox.Show("No video sources found", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            
        }

        private void StartCameraPTz()
        {
            if (CurrentDevice != null)
            {
                if (_videoSource != null && _videoSource.IsRunning)
                {
                    _videoSource.SignalToStop();
                    _videoSource.WaitForStop();
                    
                }
            
                videodevice = new VideoCaptureDevice(CurrentDevice.MonikerString);
                Thread.Sleep(200);
                _videoSource = videodevice;
                _videoSource.NewFrame += video_NewFrame;
                _videoSource.Start();
            }
        }

        private void StopCameraPtz()
        {
            if (_videoSource != null && _videoSource.IsRunning)
            {
                _videoSource.SignalToStop();
                _videoSource.NewFrame -= new NewFrameEventHandler(video_NewFrame);
                _videoSource = null;
                
            }
        }

        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = this.PropertyChanged;
            if (handler != null)
            {
                var e = new PropertyChangedEventArgs(propertyName);
                handler(this, e);
            }
        }




Tag : .NET, Class Library, C#, VS 2015 (.NET 4.x), VS 2017 (.NET 4.x)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2017-05-09 18:27:16 By : sarun52 View : 1257 Reply : 1
 

 

No. 1



โพสกระทู้ ( 1,458 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook Blogger

http://www.aforgenet.com/framework/docs/html/ff97965b-2ca0-7b5e-8223-dd13b3b91619.htm






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-07-09 12:51:06 By : PhrayaDev
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : อยากทราบวิธีแก้ปัญหาดึงภาพมาจากกล้องแล้วรีโซลูชั่นไม่ตรงกันครับ Aforge.net c#.net
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่