OpenCV trackbar performance in OSX - performance

I've just noticed that performance of openCV is drastically slowed down when a trackbar is present in a window with changing image from camera or a movie frame. What could be done resolve this issue?

The solution to that is to move trackbars to a separate window. For me on OSX the performance increased 4.7 times (from 3 FPS up to 14). I don't know if it works like this always or it's just like that on my computer but I haven't seen such a clue anywhere before so I decided to share.
string title = "My window";
int p = 2;
// Create a different window for controls
namedWindow(title + " - controls");
// I show an image once just to resize the window
imshow(title + " - controls", Mat::zeros(1, 500, CV_8UC1));
createTrackbar("Parameter", title + " - controls", &p, 3);
// Create a different window for actual image
namedWindow(title);
while (!done) {
// Do some calculations
flip(image, image, p);
imshow(title, image);
}

I also encountered the same problem in OSX-10.9.
And I have resolved the issue in the following ways:
port variants opencv
sudo port install opencv +qt4 +tbb +eigen +opencl
important option is "+qt4" only, the other options are extra.
OpenCV support Qt for GUI backend. And I suspect the cause of the problem is in the implementation of the default GUI backend.
I was able to virtually eliminates the problem by re-build OpenCV library with Qt support and re-install(update).

For me, this seemed to be an issue with the Anaconda distribution of OpenCV.
Installing OpenCV with pip fixed my performance issues.

Try to tune
cv2.waitKey(value)
I used cv2.waitKey(100) and works smoothly

Related

Why three.js pointcloud is not same rendering between mac and windows (Intel HD graphics 4000)?

I'm developing Huge PointCloud Viewer(over 10millions) using Three.js.
But, I got a strange result - not same rendering between mac and windows.
below figure is on Mac
On Mac, and next figureOn windows on Windows(7).
both uses Intel HD graphics 4000.
What's happens in Chrome Browser?
Addtionally informations: same situation are iPhoneSE, iPhoneX, iPad4, MacBook, MacBookAir, and MacBookPro. those machines display very sparsed point cloud(intel HD graphics series commonly)
But, only iMac(2017) displays Huge point cloud, successfully. It uses Radeon pro 555, not intel GPU.
I want to any message about info or/and err, but no error in "chrome_debug.log"
=== P.S. === below my code
if(data.point.position.length>0){
var geometry = new THREE.BufferGeometry();
geometry.addAttribute('position', new THREE.BufferAttribute(data.point.position, 3));
geometry.addAttribute('color', new THREE.BufferAttribute(data.point.color, 3));
var material = new THREE.PointsMaterial({
vertexColors: THREE.VertexColors,
size:0.8,
sizeAttenuation : true,
});
}
=== P.P.S. ===
For all
Try and Error, before I may find resolving it.
When pointMaterial.sizeAttenuation = false, FAR perspective view on Mac like on Windows. However, NEAR perspective view become sparse point cloud.
But if NEAR perspective, creating with pointMaterial.sizeAttenuation = true, I got better than before result.
Thanks a lot for your suggestion.
On both the working and the failing configuration, visit to http://webglreport.com/?v=1 and check the value of the OES_element_index_uint extension. My assumption is that this extension not supported on the failing machine/OS combination (driver support missing on MacOS).
This extension is required by three.js to render more than 64k vertices from a single BufferGeometry. On machines that don't support this extension, you'll need to split up your geometry.
Your problem is pixel density on Mac devices. Mac devices often have a pixel ratio of 2 or higher on retina displays. When you declare pointsMaterial.size, you're telling it how big each point is in pixels, so make sure you're taking window.devicePixelRatio into account when assigning their pixel size. Something like
pointsMaterial.size = mySize * window.devicePixelRatio;
should do the trick.
For Chrome users, disabling "Use hardware acceleration when available" could solve the sparse point cloud problem, but the fps may be very low.
I didn't dig into the further reason, if someone finds it, Pls let me know~

how to grab a OpenCV frame without showing it or without creating cvNamedWindow?

I do not understand why OpenCV doesn't work when we do not need to create OpenCV window using cvNamedWindow.
Actually, I do not want to use OpenCV GUI window, I want to use third party GUI in order to display grabbed frame, So for this, i do not need to create OpenCV window. But When I do not create OpenCV window, my application gets stuck, nothing works, and when I do create OpenCV window using cvNamedWindow, everything works fine.
Any suggestion, whats the reason? how can I grab OpenCV frame without creating its GUI window?
I am using OpenCV 2.4.3 (cvQueryFrame), VS2010 c++, WindowsXP
Thanks.
you probably need to skip the waitKey() call, too ;)
(also, do yourself a favour, and skip the c-api. it's a real PITA and will go away soon)
That's because you are grabbing images at a faster rate than what the camera can ouput. You need to add a little delay to your while cycle. If your camera does 25FPS, you should add ~1/25 of a second or so.
Solved: The problem was this, actually, I was creating a third party GUI window inside of the pthread which was causing its infinite updating. When I created window outside of the pthread, it works fine.
procedure is this:
void Init()
{
createGUIwin(w, h);
init_pthread();
}
void init_pthread(void*)
{
//createGUIwin(w, h); // before I was creating GUIwin here
while(ON)
{
frame = getOCVframe();
UpdateGUIwin(frame);
key = cvWaitKey(10);
}
}
Thanks everyone. I appreciate your answers.

GUI to view values in image using OpenCV in ubuntu12.04

Is it possible to simultaneously display an image and the pixel,coordinate values based on the mouse pointer positions?
I am asking an OpenCV equivalent of imview function in MATLAB.
You don't need Qt to do that. Just use default OpenCV function imshow to show image and SetMouseCallback to set callback on mouse click.
It can be done using mouse call back events. You can find a good example in \opencv\samples\cpp\grabcut.cpp
I had a few problems trying to do this with OpenCV alone using an old code I wrote a while back. At this point I'm not sure if I missed something or if it's a bug in OpenCV. I'll investigate this further.
But I shared a short, self contained, correct (compilable), example at my repository, check cvImage. It's written in C++ with Qt and OpenCV. It's a Qt application that loads an image with OpenCV and displays the RGB values as the title of the Qt window.
Move the mouse around and place the cursor on top of the pixel that you are interested at to see it's RGB value.
Opencv with Qt support will do that.

How to see image data using opencv in visual studio?

I wrote an OPENCV project in VS2010 and the results were not the ones as I expected so I ran the debugger to see where is the problem. When I wanted to see the data inside the image loaded I didn't know how to do it so if I want to see the data inside my images what should I do?
It is pretty simple in matlab for seeing different channel of an image i.e.
a=imread('test.jpg');
p1 = a(:,:,1)
p2 = b(:,:,2)
.
.
In opencv I wrote the same thing but I don't know how to see all the element at once just like Matlab.
a= imread("test.jpg")
split(a,planes);
vector<Mat> T1;
T1 = planes[0];
// How can I see the data inside T1 when debugging the code ?
I think this is what you are looking for - it's a great Visual Studio add-on
https://bitbucket.org/sergiu/opencv-visualizers
Just download the installer, make sure VS is closed, run it, re-open VS and voila! Now, when you point to an OpenCV data structure, all kinds of nice info is showed.
Limitations: I saw some problems with multichannel images (it only shows the first channel) and it also has trouble displaying large matrices. If you want to see raw data in a big matrix, you can use the old good VS trick with debug variables: Stop at a breakpoint, go to Watch tab, and write there
((float*)myMat.data) ,10
Where float is the matrix type, myMat is your matrix, and 10 is the number of values you want to print. It will display the first 10 values at the memory location of myMat.data. If you do not correctly choose the data type, you'll see garbage. In my example, myMat is of type cv::Mat.
And never forget the power of visualizers:
imshow("Image", myMat);
If your data fits into an image. You can use the contrib module's colormap to enhance your visualizers.
I can't actually believe that nobody suggested Image Watch yet. It's the most amazing add-in ever. It shows you a view with all your Mat variables (images (gray and color), matrices) while debugging, there's useful stuff like zooming or contrast-stretching and you can even apply more complex functions directly in the plugin in real-time. It makes debugging of any kind of image operations a breeze and it's immensely helpful if you do calculations and linear algebra stuff with your cv::Mat matrices.
I recommend to use a NativeViewer extension. It actually displays the content of an image in a preview window, not only the properly formatted info.
If you don't want to use a plug-in or extension to Visual Studio, you can access the elements one by one in the debugging watch tab by typing this:
T1.data[T1.step.buf[0]*i + T1.step.buf[1]*j];
where i is the row you want to look at and j is the column.
after downloading imagewatch use the command in watch window
(imagesLoc._Myfirst)[0]
index of image in the vector
You can use the immediate window and the extenshion method like this one
/// <summary>
/// Displays image
/// </summary>
public static void Display (this Mat m, Rect rect = default, string windowName = "")
{
if (string.IsNullOrEmpty(windowName))
{
windowName = m.ToString();
}
var img = rect == default ? m : m.Crop(rect);
double coef = Math.Min(1600d / img.Width, 800d / img.Height);
Cv2.ImShow(windowName, img.Resize(new Size(coef * img.Width, (coef * img.Height) > 1 ? coef * img.Height : 1)));
Cv2.WaitKey();
}
Then you stop at a breakpoint and call yourImage.Display() in the immediate window.
If you can use CLion you can utilize the OpenCV Image Viewer plugin, which displays matrices while debugging just on click.
https://plugins.jetbrains.com/plugin/14371-opencv-image-viewer
Disclaimer: I'm an author of this plugin

Cannot change font size in Tk

I'm trying, for the first time, to create a GUI in Ruby using Tk. I've copied a code snippet from one of the numerous web tutorials and try to change the font for one of the labels, but nothing seems to affect how the text is presented.
Here's the code:
require 'tk'
root = TkRoot.new('title'=>'MCIS')
defaultFont = TkFont.new("weight"=>'bold', "size"=>20)
Lbl = TkLabel.new(root) do
text "Boooo"
borderwidth 5
font defaultFont
foreground "red"
relief "groove"
grid('column'=>3, 'row'=>0)
end
Tk.mainloop()
I see the effects of all the parameters of the label but not the font. I've tried to change the size, the weight, give different family names, leave just one parameter; nothing works - the font stays default as it was. Surprisingly it doesn't report any errors, everything looks fine. Maybe it's versions problem? I run these:
Linux Centos 5
Tk 8.4.13
Ruby 1.8.5
ruby-tcltk 1.8.5
Also, don't know if it is important, I ran it via Xming from WinXP machine.
When I ran the above code it works as expected on my linux desktop with a connected display. If I had to guess, I'd say that Xming has extremely limited font support, maybe only supplying a handful of bitmapped (read: non-scaleable) fonts.
So, I would say the code is correct and the problem is related to the X server configuration.

Resources