Replace Opencv Fillpoly functions with Halide Funcs - opencv

I'm trying to realize some opencv functions by Halide, one of the difficulty I have met is how to write the cv::fillpoly in Halide. This function, in opencv, fills a polygon according to the given vertex of this polygon. The details in Opencv: https://docs.opencv.org/2.4/modules/core/doc/drawing_functions.html
I wonder if it's possible to realize it in Halide?

It is possible, but likely difficult and not obviously productive as polygon rendering does not have a regular static data parallel pattern and is already really well optimized in various places. It would be interesting to see if it can be done and made performant but it is a lot of work and isn't obviously going to be as fast or faster than existing graphics libraries. Especially if running on GPU hardware where it has to compete with hardware rasterization. I'd look into using define_extern to call out to existing rendering routines.

Related

How to use OpenCV functions in Metal on iOS?

I have developed the Xcode project that uses OpenCV functions for image processing when the iPhone camera live stream.
It takes some time to process one frame and doesn't look like real time.
Is it possible to accelerate the calculation by integrating OpenCV and Metal?
For example, OpenCV function "grabCut" takes more than 1 second to detect certain foreground objects.
How can I reduce the processing time down to 10ms at least using Metal?
You can't call OpenCV functions from Metal.
If you want to speed up this algorithm, you could try porting it to Metal but that's only an option if the algorithm -- or major parts of it -- are highly parallel.
Now, it looks like grabCut has a CUDA implementation (which I found by googling for "grabcut cuda"), which means that implementing this in Metal might actually be worth doing. If you can find the CUDA source code, it's usually a relatively straightforward port.

What types of animation does VTK support for poygonal meshes?

I've a bunch of expereince in 3D rendering from a game-dev perspective but very little with serious toolkits like VTK.
We have a 3D model of a medical device which has a couple of degrees of motion, and we need to visualise this, animated, in a medical application alongside DICOM datasets.
In a 3D engine we'd likely have option to keyframes, morph-targets, skeletal rigging... but I cannot find out what VTK supports (skeleton/bone are bad search terms as most uses are medical!)
Can someone enumerate what options are provided and point me where in the docs this is covered?
I am not aware of any concise "documentation of VTK animation methods" (doesn't mean there isn't one though), but I will at least share what I know. First off, I doubt that there is some really great state-of-the-art solution included in the base VTK, personally I would look for algorithms that are good enough for me (produce high quality animation) and then try to find an open source implementation of them rather than the other way around. Try including "non-rigid transformation / animation" in your search.
Anyway, two things I know of that are in VTK: there is a filter for Mean Value Coordinates morphing, https://www.vtk.org/doc/nightly/html/classvtkDeformPointSet.html, which you can use for a cage-based deformation (which is perhaps not the most user friendly for creating animations) or in theory could be used for rigging as well (never tried that, but right now I can't see why it wouldn't work). Next, there is an Iterative Closest Point morphing filter https://www.vtk.org/doc/nightly/html/classvtkIterativeClosestPointTransform.html that you could use for morphing by key frames.

Compute planar geometry, vectorial math, and 3D equations in SWIFT/iOS

Working on a project here which will require some awesome math resourcefulness. I'm looking to make calculations to verify things like: if a point is within a volume / shape (in this case: rectangles or trapezoids) in a given 3D space, how to generate a class or some kind of object to hold the "equation" parameters of such a volume.
Also looking at ways to perform dot product computations in Swift.
Would there be a well-known library out there?
The only things I can seem to find are for SceneKit and graphics rendering Frameworks.. this project is purely computational, as in there is no UI output of the calculated results.
Any resources or examples are much appreciated!
For those who mind stumble upon this kind of issue,
I eventually found the built-in framework for making this kind of math possible.
Called Accelerate, it's even optimized per-OS.
https://developer.apple.com/reference/accelerate
Best of luck!

Stereovision algorithms

For my project, supposed to segment closest hand region from camera, I initially try openCV's stereovision example. However, disparity map looks very bad and its useless for me.
Is there any other method which is better than openCV implementation and have some output(image-video). Because, my time is limited, I must choose one better algorithm and implement this.
Thank you.
OpenCV implements a number of stereo block matching algorithms some of them pretty cutting edge.
Disparity maps always look bad except in very simple circumstances - the first step is to try and improve the source images, the lighting and the background. I
If it was easy then everybody would eb doing it and there would be no market for expensive 3D laser scanners.
Try the different block matching algorithms provided by OpenCV. The little bit of experimentation I've done so far seems to indicate that cv::StereoSGBM gives better disparity maps than cv::StereoBM, but is slower.
The performance of the block matching algorithms will depend on what parameters they are initialized with. Have a look at the stereo examples again here, notice line 195-222 where the algorithms are initialized.
I also suggest you use some basic GUI (OpenCV:s highgui for example) to manipulate these parameters real-time when finetuning the algorithm.

Computer Vision with Mathematica

Does anybody here do computer vision work on Mathematica? I would like to know what external libraries are available for doing that. The built in image processing functions are not enough. I am looking for things like SURF, stereo, camera calibration, multi-view geometry etc.
How difficult would it be to wrap OpenCV for use in Mathematica?
Apart from the extensive set of image processing tools that are now (version 8) natively present in Mathematica, and which include a number of CV algorithms like finding morphologic objects, image segmentation and feature detection (see figure below), there's the new LibraryLink functionality, which makes working with DLLs very easy. You wouldn't have to change OpenCV much to be able to call it from Mathematica. Just some wrappers for the functions to be called and you're basically done.
I don't think such a thing exists, but I'm getting started.
It has the advantage that you can perform some analytic methods... for example rather than hacking in openCV or even Matlab endlessly, you can compute analytically a quantity, and see that the method leading to this matrix is numerically unstable as a function of input variables. Thus you do not need to hack, as it would be pointless.
As for wrapping opencv, that doesn't seem to make sense. The correct procedure would be to fix bad implementations in opencv based on your analysis in Mathematica and on paper.
Agreeing with Peter, I don't believe that forcing Mathematica to use OpenCV is a great thing.
All of the computer vision people that I've talked to, read about, and seen examples are using Matlab and the Imaging toolkit. Its either that, or go with a OpenCV compatible language + OpenCV.
Mathematica has a rich set of tools for image processing, but I'm uncertain about the computer vision capabilities.

Resources