OpenNI 2 set min/max depth values - openni

I am making a C++ utility that uses OpenNI 2. Ideally I now need to set the minimum and the maximum thresholds for the depth image. I did this in the past with OpenCV or my own image processing functions and before going this way again I am wondering whether there's a feature in OpenNI that supports this natively.
Having a look to the downloadable documentation (comes with the OpenNI package) there's a couple of interesting functions defined in the class VideoStream in OpenNI.h. These are:
int VideoStream::getMinPixelValue()
int VideoStream::getMaxPixelValue()
which return the current limits I need; these seem to be hardware readings though. Nonetheless, the VideoStream class exposes also the setProperty function which allows setting one of the properties in the list of values defined in oniProperties.h.
Since neither the documentation nor the comments in that file specify if one property is read only or not, I tried to write the min and max values by doing
myVideoStream.setProperty<int>(openni::STREAM_PROPERTY_MIN_VALUE, myIntMinValue);
myVideoStream.setProperty<int>(openni::STREAM_PROPERTY_MAX_VALUE, myIntMaxValue);
As a result the values do not change.
My questions are:
Do you confirm that min and max pixel values in the VideoStream are read only?
Does OpenNI, in some way, support natively of setting these thresdolds?
Thank you for your attention.

I'm facing a similar issue, i.e., setting the maxDepthVlaue of a particular device. The status always return as a failure. However, when you run isPropertySupported(openni::STREAM_PROPERTY_MAX_VALUE), it returns true. So there is an internal means to set the max depth value. Don't quite know what that is though.

Related

Multi-Modal Image Alignment Issue

I am trying to align two multi-spectral images using multi-modal image registration techniques.
I built a prototype in MATLAB by first creating the optimizer and metric objects as follows:
[optimizer, metric] = imregconfig('Multimodal');
This creates an optimizer object of type OnePlusOneEvolutionaryOptimizer and metric of type MattesMutualInformation. The images are aligned as follows:
tform = imregtform(movingImage, fixedImage, 'rigid', optimizer, metric);
aligned = imwarp(movingImage,tform,'OutputView',imref2d(size(fixedImage)));
Then I went for a C++ implementation of the same algorithm which is offered by one of the examples in the ITK v4 library.
This example also gives correct results but here is the problem... The ITK version is way slower than the MATLAB version. I played around with the optimizer parameters and was able to speed it up a bit, but not comparable to MATLAB version.
MATLAB documentation of OnePlusOneEvolutionaryOptimizer states that the value of InitialRadius property is directly proportional to the algorithm's execution speed (compromising on robustness). The confusion here is that in ITK, the value of InitialRadius is inversely proportional to the execution speed as far as I tested.
I couldn't find literature/documentation describing how the optimizer parameters like InitialRadius and GrowthFactor are interpreted in ITK. Please help in providing explanation of these parameters and speeding up the algorithm.
The first thing to check is making sure you are compiling your program in Release mode, not Debug mode.
Documentation and source code for 1+1 optimizer in ITK are available online.

Is there a way to check the data in a matrix in opencv c++

I'm programming on Visual Studio c++ using OpenCV library for a project in Windows 7. I'm dealing with a lot of matrices of different types: uchar, float, double, Vec3d, Vec3b etc.
When I want to print out a value of an image, I stop the run, write the following line, cout << (int)mat.at<Veb3b>(i,j)[k];, and run from the beginning which is quite time consuming. In debug mode, I don't see the values of matrices, maybe the first index depending on the type. In Matlab, you can see the values, play with them on run time. (I'm fine with just seeing the values inside a matrix)
I'm wondering if there is a way to see the values on runtime using some external tool maybe. Many genius people have been working on OpenCV, some of them should have thought of it.
So, does anybody know about such a tool? I couldn't find anything related.
I'd recommend the Image Watch extension from Microsoft (link).
It has built-in support for OpenCV datatypes. Better for image data, though using it for regular matrices works well too. Can break at any point and view data in global or local variables and can even do some simple filtering on the data displayed. You can zoom in to view individual elements. Also supports exporting directly from the debugger.

Reduce a Caffe network model

I'd like to use Caffe to extract image features. However, it takes too long to process an image, so I'm looking for ways to optimize for speed.
One thing I noticed is that the network definition I'm using has four extra layers on top the one from which I'm reading a result (and there are no feedback signals, so they should be safe to delete).
I tried to delete them from the definition file but it had no effect at all. I guess I might need to remove the corresponding part of the file that contains pre-trained weights, too. That is, however, a binary file (a protobuffer) so editing it is not that easy.
Do you think that removing the four layers might have a profound effect of the net performance?
If so then how do I get familiar with the file contents so that I could edit it and how do I know which parts to remove?
first, I don't think removing the binary weights will have any effect.
Second, you can do it easily using the python interface: see this tutorial.
Last but not least, have you tried running caffe time to measure the performance of your net? this may help you identify the bottlenecks of your computations.
PS,
You might find this thread relevant as well.
Caffemodel stores data as key-value pair. Caffe only copies weight for those layers (in train.prototxt) having exactly same name as caffemodel. Hence I don't think removing binary weights will work. If you want to change network structure, just modify train.prototxt and deploy.txt.
If you insist to remove weights from binary file, follow this caffe example.
And to make sure you delete right part, this visualizing tool should help.
I would retrain on a smaller input size, change strides, etc. However if you want to reduce file size, I'd suggest quantizing the weights https://github.com/yuanyuanli85/CaffeModelCompression and then using something like lzma compression (xz for unix). We do this so we can deploy to mobile devices. 8 bit weights compress nicely.

min and max in opencv

I have a huge amount of points data set. so i want to find min and max values from these points set. now i am using normal for loop for this purpose nice it is working but i want to know posibility to use opencv library since i wish to use this library. so plese any one help me. thanks
There are several options. Using OpenCV for this may give you an easy way to use SSE or other partially par
http://docs.opencv.org/search.html?q=minMax&check_keywords=yes&area=default
Some of those can use the GPU to help. Of course, the GPU will only be faster if your data was already in the GPU. Pushing data across the bus onto your video card just for this kind of search would be a net loss.
Use std::max_element() with a single channel cv::Mat like this:
img = img / *max_element(img.begin<float>(), img.end<float>());
No need for OpenCV in this case: it's already in the standard library (std::min_element and std::max_element).

Connected Component Labeling in C++

I need to use the connected component labeling algorithm on an image in a C++ application. I can implement that myself, but I was trying to use Boost's union-find/disjoint sets implementation since it was mentioned in the union-find wiki article.
I can't figure out how to create the disjoint_sets object so that it'll work with the image data I have (unsigned shorts). What am I missing? The examples in the Boost documentation aren't making any sense to me. Do I need all the extra Graph mumbo-jumbo in those examples when I have an image? OR, is there already an OpenCV connected component labeling implementation. Currently we're using OpenCV 1.1pre1 and Boost 1.37.
Surprisingly, there is no CCL in OpenCV. However, there is a workaround that is described in the reference manual. See the example for cvDrawContours. When I tried to use it, I had some strange behaviour on first and last rows and columns of an image, but I probably did something wrong.
An alternative way is to use cvBlobs library.
We ended up writing the algorithms for CCL and Union-Find ourselves using the descriptions found on Wikipedia and elsewhere. It seemed easier and faster than adding another library to our application just for this purpose.
Another possibility is to use the source codes provided provided by Ali Rahimi, and you can have a look at this.
I was able to use disjoint_sets of the boost library for the connected component labeling.
But to test, I was trying to create an image with pixel intensities having the value same as its label.
This led to the problem which I haven't been able to handle yet. Have a look at the thread.