I want to record a video using JavaCV in JOGL (Java Binding for OpenGL).
This is the code to open the video file:
VideoWriter wv;
wv.open("video.avi", CV_FOURCC_DEFAULT, 30 , new Size(width, height), true);
The problem is that wv.isOpened() always returns false and no video file is created.
Things I've tried:
Change "video.avi" to "video.mp4"
Change CV_FOURCC_DEFAULT to -1
Change width, height, fps values
Anyone have achieved this?
My machine is running an Ubuntu 14.04 LTS with JavaCV v1.3.2 and JOGL v2.3.2.
When using OpenCV with C++ I had to define this constant:
const int VIDEO_CODEC_FOURCC = CV_FOURCC('M','J','P','G');
Try doing using the CV_FOURCC function and the use the .avi file extension as you had originally. Also try to make sure that the camera's frame dimensions are the same as the Size that you passed in your width and height.
Related
Below a screenshot of my application. I want to get rid of the white spaces after the last tables lines marked by red rectangles :
The horizontal size policy is expanding and the vertical one is minimum and for other tables it is both set to expanding.
I'm using this method I found in another SO question but as you can see the result is not flawless.
void verticalResizeTableViewToContents(QTableView* tableView)
{
tableView->resizeRowsToContents();
// does it work ?
tableView->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
int rowTotalHeight = 0;
// Rows height
int count = tableView->verticalHeader()->count();
for (int i = 0; i < count; ++i) {
// 2018-03 edit: only account for row if it is visible
if (!tableView->verticalHeader()->isSectionHidden(i)) {
rowTotalHeight += tableView->verticalHeader()->sectionSize(i);
}
}
// Check for scrollbar visibility
if (!tableView->horizontalScrollBar()->isHidden())
{
rowTotalHeight += tableView->horizontalScrollBar()->height();
}
// Check for header visibility
if (!tableView->horizontalHeader()->isHidden())
{
rowTotalHeight += tableView->horizontalHeader()->height();
}
tableView->setMaximumHeight(rowTotalHeight);
}
Somewhere, I'm using this code to setup one of the tables :
m_Internals->Ui.Measures->setModel(mm->getPh66MeasuresModel());
m_Internals->Ui.Measures->horizontalHeader()->setSectionsMovable(true);
m_Internals->Ui.Measures->horizontalHeader()->setHighlightSections(false);
m_Internals->Ui.Measures->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
m_Internals->Ui.Measures->horizontalHeader()->setStretchLastSection(true);
m_Internals->Ui.Measures->verticalHeader()->hide();
m_Internals->Ui.Measures->setSelectionBehavior(QAbstractItemView::SelectRows);
verticalResizeTableViewToContents(m_Internals->Ui.Measures);
I'm using Qt ModelView pattern to populate/update the tables.
Update : I made a small example to reproduce this issue with QTableView : https://github.com/embeddedmz/QTableViewAdjustPolicyNotWorkingProperly
Using the latest Qt version (from Qt official installer), there's no issue. However, using the Qt library provided by vcpkg (outdated for sure) the issue is there.
With Qt provided by vcpkg :
With the latest Qt provided by the Qt Company (update not the latest, it's 5.12.11) :
If you have something fully buildable on Ubuntu 20.04 LTS, post a link to the complete project (strip it down to just this part) and I will take an actual stab at it.
My gut, having worked with Qt for years, is telling me you are being burned by Margins.
https://doc.qt.io/qt-5/qwidget.html#contentsMargins
You probably need to set a bottom margin of Zero.
https://doc.qt.io/qt-5/qmargins.html#setBottom
If you retrieve the margins for those widgets you will probably find they are non-zero.
you can also fix your problem with one trick, this problem happens for you because your data is lower than the table size. I clone your project and change sizepolicy
Under Qt 5.12.11, the bug does not exist. So I took a look at the QAbstractScrollArea::sizeHint code of this version and compared it with the implementation used in recent versions of Qt and found that setting verticalScrollBarPolicy to "ScrollBarAlwaysOff" the "AdjustToContents" adjustment policy works. The default value was "ScrollBarAsNeeded", in fact we can see that this value is not handled but since in Qt 5.12.11 we only compare the vertical|horizontal]scrollBarPolicy to Qt::ScrollBarAlwaysOn it prevents this bug from appearing.
In Qt3D certain properties of rendered objects are not just simply set on the renderer, but they are globally (per view) or locally (on the material of a rendered object) added to the renderPasses - or so is my comprehension at least. (I'm using PySide2 - but the code is almost the same in C++)
For example when adding a geometry-renderer and using its primitive type point (Qt3DRender.QGeometryRenderer.Point) instead of rendering triangle-faces it displays the points of the geometry.
Here is an example figure with the default type.
The same only showing the points (renderer.setPrimitiveType(Qt3DRender.QGeometryRenderer.Points))
Hard to guess, but here the point-size has been already been changed - using the following code:
material = Qt3DExtras.QPhongMaterial(e)
for t in material.effect().techniques():
for rp in t.renderPasses():
pointSize = Qt3DRender.QPointSize(rp)
pointSize.setSizeMode(Qt3DRender.QPointSize.SizeMode.Fixed)
pointSize.setValue(5.0)
rp.addRenderState(pointSize)
According to the documentation the same mechanism can be used to change the line-width when rendering the object with Lines (LineStrip) as primitive type. Adding
lineWidth = Qt3DRender.QLineWidth(rp)
lineWidth.setValue(5.)
lineWidth.setSmooth(True)
rp.addRenderState(lineWidth)
does not change the line-width.
Why? Where do I need to add QLineWidth? Is it the material I chose which ignores the QLineWidth-state?
I'm fighting with similar problems at the moment. I tried to reproduce the behaviour with Qt3D line width test. When setting format version to 4.6 with CoreProfile, the maximum of linewidth seems to be 1 (or equivalently width=3 displayed by the line test).
It might be possible that this is the maximum supported range.
See:
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glLineWidth.xhtml
opengl glLineWidth() doesn't change size of lines
Note: I deliberately chose version 4.6 as that is the supported openGL version on my environment.
I ran into the same issue. It appears the problem is caused by Qt3DExtras::Qt3DWindow, which constructs a QSurfaceFormat with an OpenGL core profile. The glLineWidth function is not supported in the core profile.
Unfortunately there is no way to pass a QSurfaceFormat to Qt3DWindow. Setting a new format after the window is created also does not work.
The only way around this is to write your own window class with a QSurfaceFormat in compatibility mode. For example:
setSurfaceType(QSurface::OpenGLSurface);
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
format.setVersion(4, 3);
format.setProfile(QSurfaceFormat::CompatibilityProfile);
format.setDepthBufferSize(24);
format.setSamples(4);
format.setStencilBufferSize(8);
setFormat(format);
QSurfaceFormat::setDefaultFormat(format);
Fortunately Qt3DExtras::Qt3DWindow does not actually contain a lot of functionality and you can easily write a similar class with the QSurfaceFormat changes mentioned above.
You can find the original source here for reference:
https://code.woboq.org/qt5/qt3d/src/extras/defaults/qt3dwindow.cpp.html
I can succesfully save video which I captured from c++ opencv there is no problem.
Bu similar code not capturing the video. Just opening out.avi . and only 6 kb.
I put the code in showframe func. there is no resizing fyi.
Anybody has experience with the opencv videowriter on the Qt?
void Widget::show_frame(Mat &image)
{
Mat resized_image = image.clone();
video.write(image);
int width_of_label = ui->label_camera->width();
int height_of_label = ui->label_camera->height();
Size size(width_of_label, height_of_label);
// cv::resize(image, resized_image, size);
cvtColor(image,image,CV_BGR2RGB);
cvtColor(resized_image, resized_image, CV_BGR2RGB);
ps : Platform MacOSX
I encountered the same problem with you, and I have tried many solutions, I think you can make the fifth parameter of videowriter() be false. That is, VideoWriter out = VideoWriter(video_name, CV_FOURCC('D', 'I', 'V', 'X'),frame_fps,Size(frame_width,frame_height),false). This works for me!
make sure that your application has access to the opencv_ffmpeg*.dll. For example place it in the working directory or the PATH variable.
Try different codecs, too. Afaik, MJPG did work on all tested machines/systems so far.
I have a Friendly-ARM embedded board with a W35 3.5" Touchscreen. You can see the board via the following link: http://www.friendlyarm.net/sites/products/mini2440-35s.jpg. Also I write QT program for that using Qt Creator. I have to write a GUI using QT with Width x Height = 240 x 320. I mean width = 240 and height = 320. According to what I found at various online documents and pages, the dimensions of W35 are 320 x 240, it means width = 320 and height = 320. So when I run the program, there are large margins at left and right and some part of GUI is cut at top and button. How do I exchange the board width and height?
The closest page I found on Friendly-ARM site is: http://www.friendlyarm.net/forum/topic/2881.
At this page someone mentioned, there is a file s3c2410.c at drivers/video directory, or there is file mach-mini2440.c at arch/arm/mach-s3c2440 directory and we should tweak some C #define, but I don't have neither one on the board kernel. What should I do?
1) Reinstalling the Kernel?
2) Writing program for 320 x 240 instead of 240 x 320
3) Changing the touchscreen to similar ones like X35 or T35
FYI, when the board starts up, there is Qtopia with right dimensions.
TIA,
-- Saeed Amrollahi Boyouki
First of all cross-compile your Qt with -qt-gfx-transformed option.
Method 1:
You can rotate your Qt Application using
./myApp -qws -display ":Transformed:Rot90:0"
Method 2:
You can set Display Dimension using
export QWS_DISPLAY=Transformed:Rot90:0
and start your application using
./myApp -qws
What you need to look for are instructions to rotate the display from "landscape" mode to "portrait" mode. I am unsure if there is a hardware option on the ARM processor included in the FriendlyArm, but that gives you a place to start searching. I'd also look in the Qtopia forums for a similar switch, ie http://qt-project.org/forums/viewthread/8875 or similar.
I want to change the default icon that shows up at the top left corner of the frame.
I have tried many approaches- xpm, ico, bmp,
using SetIcon(wxIcon(wxT("icon.xpm"))); as suggested here.
I tried different icon sizes, 16x16, 24x24 and 32x32.
I've also tried adding MYICON1 ICON "Logo.ico" in the resource.rc file, #define MYICON1 101 in the resource.h file and SetIcon(wxIcon(MYICON1)); to the frame constructor..
btw, i'm using wxwidgets 2.8 on visual studio 2010
EDIT:
I've also tried adding MYICON1 ICON "Logo.ico" in the resource.rc file, #define MYICON1 101 in the resource.h file and SetIcon(wxIcon(MYICON1)); to the frame constructor..
With this approach, I get an error in the wxIcon(int) constructor..
1>xsframe.cpp(17): error C2248: 'wxString::wxString' : cannot access private member declared in class 'wxString'
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\wx/string.h(682) : see declaration of 'wxString::wxString'
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\wx/string.h(659) : see declaration of 'wxString'
PS, xsframe is my main frame. whose icon i'm trying to change.
SetIcon(wxICON(MYICON1));
in file gdicmn.h ,line 166
/* Useful macro for creating icons portably, for example:
wxIcon *icon = new wxICON(sample);
expands into:
wxIcon *icon = new wxIcon("sample"); // On Windows
wxIcon *icon = new wxIcon(sample_xpm); // On wxGTK/Linux
*/
I am quoting Vaclav's answer from here:
You can set your main frame's icon with wxFrame::SetIcon. Application
icon can be changed by adding a new icon resource to your .rc file:
appicon ICON "myapp.ico"
#include "wx/msw/wx.rc"
Note that this icon must be the first icon in your .rc file and it
must be the first one when you sort your icons alphabetically. This is
because MS developers weren't able to make their mind on how to
determine app's icon: it is the first one in .rc file under Windows 9x
and the alphabetically first one under NT (or vice versa).
Most people usually miss this. Hope that fixes things.
You wrote: MYICON1 ICON "Logo.ico" in the resource.rc file, and SetIcon(wxIcon(MYICON1)); to the frame constructor
That is the approach I use.
There is an extra step you need to do. In the resource.h file you need to define MYICON1 Something like this:
#define MYICON1 101
You have to ensure that the icon file contain ALL the required resolutions - I always ensure it has 16by16, 32by32 AND 256by256 The more the merrier!
It is a good idea if the application icon is the FIRST icon in the resource file.
I recommend upgrading to wxWidgets v2.9.4 - lots of things start working better.
Use the string name of the icon, not the numeric identifier. Look at any wxWidgets sample for an example.
A quick and dirty, non-portable, only-Windows solution (worked for me in Windows 7, wxWidgets 3.0.4, vc110):
#ifdef __WXMSW__
#include "wx/msw/private.h" //for wxGetInstance()
#endif
...
//in Frame's constructor:
HWND hWnd = this->GetHandle();
HINSTANCE hInstance = wxGetInstance();
HICON hIcon = ExtractIcon(hInstance, L"someicon.ico", 0);
SetClassLongPtr(hWnd, GCLP_HICONSM, (LONG_PTR)hIcon);
Could be useful for doing some other tricks on the window?