Comments (15)
Not support to load image data from Stream.
But DlibDotNet.Extensions supports to load from Bitmap.
https://github.com/takuya-takeuchi/DlibDotNet/tree/master/src/DlibDotNet.Extensions
However, these days. I did not take care of it and it may be include issues.
If you face issue, please let me know.
from dlibdotnet.
It seems that DlibDotNet.Extenstions could not be used in UWP ?
from dlibdotnet.
Yes.
For now, it support WinForms and WPF's Bitmap.
So you have to convert UWP writeablebitmap to byte array.
from dlibdotnet.
Hi ! I make a DlibDotNet.Extenstions by using .NET Core , However, it still don't work beacuse
In DlibDotNet.Extenstions, the WriteableBitmap is
namespace:
"System.Windows.Media.Imaging"
But in UWP, the WriteableBitmap is
namespace:
"Windows.UI.Xaml.Media.Imaging"
UWP could only use "Windows.UI.Xaml.Media.Imaging" rather than "System.Windows.Media.Imaging"
In short , DlibDotNet.Extentions could not convert WriteableBitmap in UWP to Array2D properly
So, How could I use Dlib to process the camera frame in UWP without save and read Image file frequently. The I/O cost too much
Thanks.
from dlibdotnet.
I tried every method that I thought.
In UWP, convert WriteableBitmap(parameter name "writeableBitmap") to byte[] (parameter name "ByteArray")
Use this method:
Dlib.LoadImageData<RgbPixel>(ByteArray , writeableBitmap.PixelHeight , writeableBitmap.PixelWidth , 1)
to load image from WriteableBitmap.
Result:"No faces detected".
Then I tried to overload your methods Dlib.LoadImage(byte [] str)
Removed some parts of your methods such as File.Exist()
and get byte[] from parameter str
directly
Result: SEHException
Oh, I don't want to do this : CameraImage->SaveImage-> Dlib.LoadImage(string path)
LoadImage->FaceDetect
What I expect is : CameraImage->Load Image in Memory(Without Disk I/O)->FaceDetect
Please help me .Thank you very much.
from dlibdotnet.
How dou you convert WPF WriteableBitmap to byte[]?
If you get Array2d from WriteableBitmap, you can check whether image is valid by using ImageWindow.
And If you can, please show sample code and sample image.
from dlibdotnet.
Sample Code Like this
temp is the Image that need to process
SoftwareBitmap temp;
WriteableBitmap wb = new WriteableBitmap(temp.PixelWidth, temp.PixelHeight);
temp.CopyToBuffer(wb.PixelBuffer);
var img = Dlib.LoadImageData<RgbPixel>(wb.ToByteArray(), (uint)wb.PixelHeight, (uint)wb.PixelWidth, 3);
ImageWindow im = new ImageWindow(img);
im.WaitUntilClosed();
WriteableBitmapEX provide the method to convert WriteableBitmap to byte[]
Tips: WriteableBitmap in UWP is different from WPF
By the way, I'm not quite understand "steps" parameter in
LoadImageData<T>(byte[] data, uint rows, uint columns, uint steps)
from dlibdotnet.
Thank you for your good report.
I'm in office now.
please wait untill I go home and check code :)
from dlibdotnet.
I'm sorry for delay response.
The last argument of LoadImageData should be specify horizontal byte length.
In the most case, it could be channel x width.
But windows bitmap data requires to be the width of a single row of pixels (a scan line), rounded up to a four-byte boundary.
In this case, the step is 32 if width is 10 and channle is 3.
stride = width * channel
if (stride % 4 != 0)
stride = stride + (stride % 4);
from dlibdotnet.
Here is the result
Because WriteableBitmap in UWP is RGBA8, So the Image has 4 channels
if (stride % 4 != 0)
Always False
And we can see the result is gray and separate
Thanks for your great work, but it still need to improve
What do you think ?
from dlibdotnet.
Ok. I guess library may not make a correct interpretation of image.
I do not expect different type buffer is passed for type argument.
Perhaps, you convert rgba to rgb before you use LoadImageData.
It is work around.
Basically I think I should provide convert api.
from dlibdotnet.
In UWP, WriteableBitmap is not easy to Convert ARGB to RGB.
It seems that every Bitmap in UWP is ARGB
I hope DotNetDlib could provide some method or overload so that we could easily use Image in memory rather than in hard disk
from dlibdotnet.
FYI. I was able to reproduce issues you faced on not UWP but WinFroms. This issue is not only for UWP.
using (var bitmap = new Bitmap("Lenna.png"))
{
Console.WriteLine(bitmap.PixelFormat);
var data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat);
try
{
var array = new byte[data.Stride * data.Height];
Marshal.Copy(data.Scan0, array, 0, array.Length);
using (var array2D1 = Dlib.LoadImageData<RgbPixel>(array, (uint)bitmap.Height, (uint)bitmap.Width, (uint)data.Stride))
using (var window1 = new ImageWindow(array2D1))
using (var array2D2 = Dlib.LoadImage<RgbAlphaPixel>("Lenna.png"))
using (var window2 = new ImageWindow(array2D2))
{
window1.WaitUntilClosed();
window2.WaitUntilClosed();
}
}
finally
{
bitmap.UnlockBits(data);
}
}
Edit
Pixles of PixelFormat.32bppArgb are alinged as the following:
[BGRA][BGRA[[BGRA]...
If convert above to RGB,
[BGR][ABG][RAB][GRA]...
from dlibdotnet.
Added new overload of LoadImageData. Commit is fd00056 on develop branch.
Array2D<T> LoadImageData<T>(ImagePixelFormat format, byte[] data, uint rows, uint columns, uint steps)
The format can be Bgr, Bgra, Rgb or Rgba. It means the pixel format of data argument.
So you can treat Rgba value as Rgb as the following.
[BGRA][BGRA[[BGRA]...
to
[RGB][RGB][RGB][RGB]...
And the next is sample code.
using (var bitmap = new Bitmap("Lenna.png"))
{
Console.WriteLine(bitmap.PixelFormat);
var data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat);
try
{
var array = new byte[data.Stride * data.Height];
Marshal.Copy(data.Scan0, array, 0, array.Length);
using (var array2D1 = Dlib.LoadImageData<RgbPixel>(array, (uint)bitmap.Height, (uint)bitmap.Width, (uint)data.Stride))
using (var window1 = new ImageWindow(array2D1))
using (var array2D2 = Dlib.LoadImage<RgbAlphaPixel>("Lenna.png"))
using (var window2 = new ImageWindow(array2D2))
using (var array2D3 = Dlib.LoadImageData<RgbPixel>(ImagePixelFormat.Bgra, array, (uint)bitmap.Height, (uint)bitmap.Width, (uint)data.Stride))
using (var window3 = new ImageWindow(array2D3))
using (var array2D4 = Dlib.LoadImageData<RgbAlphaPixel>(ImagePixelFormat.Bgra, array, (uint)bitmap.Height, (uint)bitmap.Width, (uint)data.Stride))
using (var window4 = new ImageWindow(array2D4))
{
window1.Title = "window1";
window2.Title = "window2";
window3.Title = "window3";
window4.Title = "window4";
window1.WaitUntilClosed();
window2.WaitUntilClosed();
window3.WaitUntilClosed();
window4.WaitUntilClosed();
}
}
finally
{
bitmap.UnlockBits(data);
}
}
from dlibdotnet.
Sorry late,
I'm very appreciate your improvment
It helps me a lot !
Thank you very much
from dlibdotnet.
Related Issues (20)
- How to dockerize an app that uses this library HOT 6
- create detector issue HOT 4
- Set minimum sensitivity for FrontalFaceDetector.Operator HOT 3
- Add CUDA 112 to document and publish script
- library does not depend on system libjpeg on OSX HOT 2
- How to using in .NET Core 6 HOT 1
- [Memory Leak] Disposing an Array2D<RgbPixel> does not dispose of contained RgbPixels HOT 11
- Extract face coordinates from upsampled image using Frontal Face Detector HOT 4
- BitmapExtensions.ToArray2D<RgbPixel>(image) throws always not supported exception HOT 4
- Rid of System.Drawing
- cuda HOT 4
- DlibDotNet.Xamarin is missing HOT 1
- ToBitmap() ambigous HOT 1
- Memory leak with Array2D HOT 2
- DlibDotNet with FaceRecognitionDotNet Not working HOT 1
- Face recognition in real time (using ar glass and unity and dlibdotnet)
- .NET 7.0 compatibility, Failed to find dll "DlibDotNetNative", for processor architecture AMD64 HOT 2
- Can't load DlibDotNetNativeDnn in Blazor WebAssembly project
- HeadPoseTraining with GPU Support possible ?
- Can't build DlibDotNet.Native.Dnn HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dlibdotnet.