OpenCV FileStorage - how to use in C# with EmguCV? - c#

Is it possible to rewrite examples from XML/YAML Persistence page from OpenCV to EmguCV?
I mean code in first two subchapters: "XML/YAML file storages. Writing to a file storage" and "Reading data from a file storage."
I am mostly interested in saving and loading int-s and sequences.
I have found EmguCV cvOpenFileStorage doc - most arguments are IntPtrs and it is not clear for me how to use it for mentioned types (concerning matrices - I have found working examples).

Emgu does not support completely the OpenCV functions related to FileStorage operations: you must wrap the missing methods using Interop (System.Runtime.InteropServices).
At the following link you can find a code example: http://www.emgu.com/forum/viewtopic.php?f=7&t=1877

Related

How to convert Dicom to BMP image in C#?

I am currently using the evil-dicom library for opening DICOM files in c#. I am able to access the dicom file with:
var dcm = DICOMObject.Read('dicomfilename');
Then open up the pixel stream using
dcm.PixelStream
How can I save the pixelstream as a bmp image?
I never used the toolkit; but at least till Oct-2014, author of the toolkit was saying following:
Evil DICOM does not have any image classes to help with this. While that might seem strange to not include image tools in a DICOM library, it is not the original intent of the the library. Evil DICOM is more for manipulating and analysis of DICOM data. I used to have some image parts in the old library which I believe is still available on SourceForge. You can take a look, but the PixelData tag has the raw bits to put together an image. .NET has several classes that can help with that, but I don't have anything to write here in this post. If I get some time, I will write a blog post about how to do it on the website (rexcardan.com).
Source: GitHub
Apparently, it was not original intent of the toolkit to include imaging support in toolkit. Not sure if this is changed since then. Author was planning to write an article to achieve this through DotNet; not sure if he wrote any then after. Old library from SourceForge may create other issues as it might not have been updated since long.
You can find some example code here.

How to access Image sequence in a HEIC file ( using C#)?

I want to access Image sequence contained in a Heic Container using C#.
In windows 10, the HEIF Image Extensions enables reading (HEIF) files. It is supposed to be extended to WIC to be used by developers if the previously mentioned extension is installed on the device.
Other libraries I found about this topic:
- Magick.NET Can only handle a Single image in a HEIC Container.
- HEIF-Utility-Native-DLL and HEIF.NET Have the same issue as the one before.
- libheif is a C++ Library. I don't know how to use PInvoke even tho i have been trying extensively to understand how it works (I cant read C++)
How can I use my code to check if the extension is Installed?
How can I use C# to access Image sequence from a HEIC container?
And how can I do the reverce by packing Image sequences into a Heic Container?
As an alternative, how could I port this JavaScript to C#, or use it with C# in a project to access Images?

How to preprocess in EmguCV with Leptonica as done in Capture2Text

I am developing an OCR application in EmguCV. My target is to achieve the same results as done by Capture2Text.
Capture2Text uses Tesseract engine for OCR and Leptonica library for Preprocessing. As we know EmguCV is using Tesseract engine for OCR therefore we are left with Preprocessing.
Preprocessing in Capture2Text is done by calling the functions of Leptonica in the following order with specific values. The actual code file is available in the leptonica_util.c uner the folder ...\Capture2Text_v3.5\Capture2Text\SourceCode\leptonica_util
Read in source image
Convert to grey scale
Perform auto negate image
Scale the image (linear interpolation)
Apply unsharp mask
Perform Otsu Binarize
Out of these two possible options, which one is better to follow and how ?
Use Leptonica library in EmguCV by including it in the code and then calling the same functions with same parameters.
Try to find and use equivalent functions already available in EmguCV.
I have tried to go for option 1, but could not do it properly. For 2nd option I am not sure where to look specifically in EmguCV.
Finally, I managed to solve the problem by using Leptonica library in EmguCV. The main issue I found was the mismatch between 'bitness' of Leptonica libraries and EmguCV installation on my system.
What worked for me was to set both of them to be used in a 32 bit environment and build them for x86 machine.
Now the OCR recognition level is same as in Capture2Text (which is very accurate for my application).

Edit tif files with C#

I need to create a program that reads tif files from a directory and then trims the bottom inch of the file and resaves the file. I know how to open the files but how would I automate this process from c#?
If you need to handle TIFF images in C# then have a look at LibTIFF.Net
http://bitmiracle.com/libtiff/ - It is open source and Native .NET component and free for commercial use.
This library should also have the TIFF cropping functions you need. I am not sure if the native .NET libraries can handle all of the TIFF functions you may require whereas LibTIFF will.
The original LibTIFF for C/C++ can be found at http://www.remotesensing.org/libtiff/ which may help you with documentation and support if needed.
Included with libTiff is a program called tiffCrop which should also have source code. http://www.remotesensing.org/libtiff/man/tiffcrop.1.html which can be accessed via
http://www.remotesensing.org/libtiff/tools.html.
See here.

How to load EPS files and draw them using WinForms

Is it possible to load and display EPS file using plain WinForms GDI+? If not, is there a free library to help out?
I seem to remember that Windows GDI supported EPS files, but after Googling around a bit, I am starting to doubt that memory.
All I want to do is load the file and draw it using a Graphics context.
I am aware that I can just use any program to convert the file to PNG or something and render it that way, but because I am trying to render at multiple resolutions, I would prefer to keep the vector data in the EPS file.
Thanks!
All the free or open source libraries I know that can convert EPS to other vector or raster format are all based on Ghostscript. You can invoke ghostscript directly, with wrapper provided or alternatively look at imagemagick. It is a very popular library for manipulating image graphics and has been around for a long time. It also internally relies on Ghostscript for handling EPS format. There is a .NET wrapper for it that you can find at http://imagemagick.codeplex.com/. You can read a bit about its background here too http://www.codeproject.com/KB/dotnet/ImageMagick_in_VBNET.aspx. There is also pstoedit that is also based on ghostscript to read EPS and allow export to format like WMF. You will need to the call to pstoedit API using interop in .NET
Besides Ghostscript there are several commercial products that I known of like ImageGear and LeadTools which will let you take EPS to almost any other kind of graphic formats.
You can use GhostScript to produce images from an EPS. Once you have an image you can then display that within your application.
In your question you indicated you want the output in a vector format which would preclude bitmaps, jpeg etc. Here are a couple of ways of getting a XAML file which is a vector file with extensive support by Microsoft.
Microsoft Expression Blend 3 and Design 3 can both open .ai (eps) files and convert them to vector formats, design and XAML respectively, so it is definitely possible.
I know it is relatively easy to automate most Microsoft Office applications like Word and Excel, but I have not seen any documented com inter-op assemblies for these Expression products.
Perhaps you can use the converters that are part of Expression in an undocumented way?
If that doesn't work here is plan B:
Here is a free converter that will convert .ai (eps) files to XAML. To use it you need Adobe Illustrator however.

Categories

Resources