OpenCVCharp4でmp4の動画再生させたいのですが、
プロジェクトオプション→ビルド→対象プラットフォームを
x86にした時のみ、VideoCaptureオブジェクト作成時に失敗してしまうようです。
jpgの表示は32bitでもできるようです。
具体的には
mov.FrameWidth , mov.FrameWidth が0になってしまい(64bitコンパイル時には値が入ってくる)、
wb = New WriteableBitmap(mov.FrameWidth, mov.FrameHeight, 96, 96, PixelFormats.Bgr24, Nothing)
のところで、以下の例外が発生してしまいます。
System.ArgumentException: '値が期待される範囲内にありません。'
ArgumentException: 値が有効な範囲にありません。
ソースは以下のサイトのコピペです。
http://hiruandon.net/index.php?OpenCVSharp%E5%8B%95%E7%94%BB%E5%86%8D%E7%94%9F
C#
1using OpenCvSharp.WpfExtensions; 2using System.Threading.Tasks; 3using System.Windows; 4using System.Windows.Media; 5using System.Windows.Media.Imaging; 6 7namespace OpenCVTest 8{ 9 /// <summary> 10 /// MainWindow.xaml の相互作用ロジック 11 /// </summary> 12 public partial class MainWindow : Window 13 { 14 public MainWindow() 15 { 16 InitializeComponent(); 17 } 18 private async void Button_Click(object sender, RoutedEventArgs e) 19 { 20 var dialog = new Microsoft.Win32.OpenFileDialog(); 21 if (dialog.ShowDialog() == true) 22 { 23 Videopath.Text = dialog.FileName; 24 if (dialog.FileName.EndsWith("jpg")) 25 { 26 var src = OpenCvSharp.Cv2.ImRead(dialog.FileName); 27 imageResult.Source = src.ToWriteableBitmap(); 28 src.Dispose(); 29 } 30 else if (dialog.FileName.EndsWith("mp4")) 31 { 32 await CaptureAsync(dialog.FileName); 33 } 34 } 35 } 36 private WriteableBitmap wb; 37 private async Task CaptureAsync(string file) 38 { 39 while (true) 40 { 41 using (var mov = new OpenCvSharp.VideoCapture(file)) 42 { 43 44 wb = new WriteableBitmap(mov.FrameWidth, mov.FrameHeight, 96, 96, PixelFormats.Bgr24, null); 45 int interval = (int)(1000 / mov.Fps); 46 OpenCvSharp.Mat image; 47 while ((image = mov.RetrieveMat()) != null && !image.Empty()) 48 { 49 WriteableBitmapConverter.ToWriteableBitmap(image, wb); 50 imageResult.Source = wb; 51 await Task.Delay(interval); 52 image.Dispose(); 53 } 54 } 55 } 56 } 57 } 58}
WPF
1<Window x:Class="OpenCVTest.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 6 xmlns:local="clr-namespace:OpenCVTest" 7 mc:Ignorable="d" 8 Title="MainWindow" Height="450" Width="800"> 9 <Grid> 10 <Button Content="Button" HorizontalAlignment="Left" Margin="707,10,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/> 11 <Image x:Name="imageResult" HorizontalAlignment="Left" Height="399" Margin="10,10,0,0" VerticalAlignment="Top" Width="570"/> 12 <TextBlock x:Name="Videopath" HorizontalAlignment="Left" Margin="602,51,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Height="358" Width="180"/> 13 </Grid> 14</Window>
・動作環境
Windows10 64 bit .net 4.8
以下のNugetパッケージをインストールしました。
OpenCvSharp4
OpenCvSharp4.runtime.win
OpenCvSharp4.WpfExtensions
・Visual C++ 再配布可能パッケージ 2015-2019 x64/x86
・Visual C++ 再配布可能パッケージ 2012 x64/x86
・Visual C++ 再配布可能パッケージ 2010 x64/x86

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。