How to display calculation results in namedWindow in opencv (c++) - visual-studio

I used this code to display multiple images in the same namedWindow. Now I want to display some of the calculation results (that I have calculated before with image processing functions).
The results should be displayed in the fourth position of the namedWindow, like I show in the red square in the image below:
Is there any way in opencv that can throw console window in the namedWindow? Can I copy the results from console window in any other way on the named window? Is it possible to create somehow scrolling window with all information and put them on ?

I would suggest creating an new Mat with either ones() or zeros() and then using the function putText to insert your text.
Afterwards show the Mat like the rest before

Related

Problems with plot size in preview window in RNotebook: Only latest plot of chunk is shown in full size, previous plots remain small

I have a problem with the preview window of plots from RNotebook.
I am running GAM-models for different tree species and store them in a nested dataframe. When I afterwards run some model diagnostics or plotting function in RNotebook an odd behaviour occurs.
So lets say I want to plot the smooths for each tree species gam model with customized function
# plotting the effects of the model with gratia
gam_plot_gratia_all(gam_base, group_var = group_var)
here my custom-function:
gam_plot_gratia_all = function(gam_input, group_var) {
map2(gam_input$fit_gam, gam_input[[group_var]], ~ show(gratia::draw(.x)))
}
gam_base is a nested dataframe which contains the gam-models in the fit_gam column. The function works and I get three plots:
When I open the plots in the preview window, the last plot (the very right one) is shown properly and after enlarging the preview window, adjusts the single ggplots to the proper size:
However, when selecting one of the previous plots, the single smooth-plots do not adjust to the larger window size, but remain in the default size:
Of course I can create multiple plots and split them on different pages, but for a quick preview, this is quite a nice feature or RNotebook. The example with the gratia-plots is just for demonstration. The behaviour remains the same when I plot other ggplots or use other plotting packages, so maybe there are some options in RNotebook, where I can tackle this problem?
I also tried "print" in my function calls, and also wrapped the print function around my map2-call. I use the latest version of RStudio (2022.07.2 Build 576) and Windows.

Is it possible to create a drawing, save it in such a format so then that drawing can be loaded back up?

I am working on a drawing app in processing and wanted to know if it is possible to create a drawing and then somehow save that drawing into some format and then load that drawing back up?
Yes.
You can output it as an image using the save() function.
Or you could output the drawing in some other format. For example, if your drawing consisted of a bunch of lines, you could save them as a text file that contained start points and end points.
How you save your data is up to you, and what you need.
Check out the input and output sections of the reference for some handy functions.
Good luck.

Matlab create image from array and save without displaying

Apologies if this is a dupe, I've been searching for over an hour but the search terms are all really broad and I just keep getting the same results. Also I'm fairly new to matlab so apologies for any misunderstandings.
Anywho, I have a matlab program which needs to frequently save an image generated from a matrix, but I just can't figure out how to do that without displaying it first. Basically I'm caught in between two functions, image and imwrite, both only do half of what I want.
image is able to take my matrix and create the desired output, but it just displays it to a figure window
imwrite is able to save an image to a file without displaying it, but the image is completely wrong and I can't find any parameters that would fix it.
Other questions I've seen deal with using imread and managing figures and stuff, but I'm just doing (for example)
matrix = rand(20);
colormap(winter);
image(matrix, 'CDataMapping', 'scaled');
or
matrix = rand(20);
imwrite(matrix, winter(256), 'filename.png');
Is there some way to call the image function such that it doesn't display a figure window and then gets saved to a file? Something analogous to calling imshow and then savefig in matplotlib.
Just do this:
matrix = rand(20);
f = figure('visible', 'off');
colormap(winter);
image(matrix, 'CDataMapping', 'scaled');
print(f, '-dpng', 'filename.png');

Matlab: How to clear the previous output image

I define values for the variables and call the function, it returns the output image in the figure. But when i want to test another set of data, the output image will come out, it's together with the previous output image. How can i solve it, do i need to add what code at the end of the function file?
Either close all before your generate the new figure if you're not interested in the old output figure, or make a figure call before creating the new image to ensure it pops up in a new figure window. Or, you can overwrite the current open figure by setting hold off first, although that's specifically for graphs.

Using opencv in Win32 application for image show

Is it possible to output images so that they all will be inside a single window?
Before, I used to output data using only opencv functions:
cvNamedWindow("Image 1");
cvShowImage("Image 1", img);
So I change image, then call: cvShowImage function and so on.
But If I want to look at more than one image, then every new image needs its own window to be shown there And what I want is to put every such an output opencv's window inside one big main window.
Is it possible to do it? And how?
You will have to construct a new image and place each img into it. I don't think there's a builtin function like MATLAB's subplot. I recommend using the ROI functions to quickly copy an image into a region-of-interest (ROI) of the big image (which holds the others).
You can show as many images as you want on a single window using hconcat function.
Let us suppose your original image was
Mat frame;
Now clone or make a copy of this image using
Mat frame1 = frame.clone();//or
Mat frame2;
frame.copyTo(frame1);
Now let us suppose your output images are
Mat img1,img2,img3,img4;
Now if you want to show images horizontally, use
hconcat(img1,img2,frame1)//hconcat(input_image1,input_image2,destination_image);
And if you want to show images vertically, use
frame2.push_back(img1);//main_image.push_back(image_to_be_shown_below);
This process processess images one at a time, so if you want to show 4 images side by side, you have to call this function 4 times as in
hconcat(img1,img2,frame1);
hconcat(frame1,img3,frame1);
hconcat(frame1,img4,frame1);
imshow("Final Image",frame1);
NOTE:
Clone process is done because the images have to be of same size.
Enjoy...

Resources