I'm working on project which streams desktop image from Mac OS X computer to iOS device in realtime. My main problem is the screen capture. I'm not allowed to use ready libraries, which allow to write some lines of code in 5 mins and stream video over the World.
I've found a really good thing on GitHub which gets image of the whole screen using X11 and C++ :
https://github.com/Butataki/cpp-x11-make-screenshot
I've tested this code on my Ubuntu and everything works like a charm : it takes about 12ms just to capture 1 frame without saving data, and about 25ms with encoding to .jpg and saving on the disk.
To be able to build it, I've had done this :
$ sudo apt install libjpeg-dev libpng-dev libx11-dev
, changed 'true' to 'TRUE' in those lines :
//(screenshot.cpp : 232,233 lines)
jpeg_set_quality (&cinfo, quality, TRUE);
jpeg_start_compress(&cinfo, TRUE);
and changed Z_BEST_COMPRESSION to PNG_Z_DEFAULT_COMPRESSION
The problem is that I did almost the same operations in my XCode (Mac OS Mojave 10.14), downloaded and linked all necessary libraries, ran executable and finally....I got a blank image. No errors occured, everything works 'fine' and saves .jpg image in my folder on desktop.
Then I figured out that X11 has a something called the 'root window', which covers all of the desktop and you can just find this window and capture everyting on your screen. But I think it's true for Ubuntu, not for my Mac.
Actually, there is something about 'root window' in this article, but I just can't fix anything :
https://finkers.wordpress.com/running-x11/#intro.rootless
P.S If it's not a good way, maybe there are some another ways to acomplish my task (realtime screencapturing on Mac OS)?
Related
I developed a project on windows with visual studio 17 and it worked fine for me. Now I'm compiling it with cmake on a linux virtual machine (in virtualbox) and everything seems to be ok but when I run my program Assimp doesn't work.
When I create an importer to load an animation it prints an error:
ERROR::ASSIMP:: Expected different index count in <p> element.
but what drives me crazy is that it doesn't cause a crash in the program but it keeps going after printing this, it gets the scene like nothing happened, an assert is passed but when i take the animations i get a segmentation fault.
Here the code:
Assimp::Importer importer;
const aiScene* scene = importer.ReadFile(animationPath, aiProcess_Triangulate);
assert(scene && scene->mRootNode);
auto animation = scene->mAnimations[0];
Any ideas how to fix this?
To reproduce it:
Virtualbox with Ubuntu 22.04 LTS os.
the repo can be cloned from here
You need Conan installed.
When Conan is installed, just clone the repo and run the script called installer.sh
it just installs some dependencies like xorg-dev, build-essential etc with apt-get install and some libraries with conan and configures the makefile with cmake and build it. Then, go to the build dir and run the program called Reskinner.
This is a known bug in the collada-implementation. The number of indices does not fit to the kind of primitive. I am not sure if this is caused by a wrong expectation from our collada parser or from an invalid model.
You can find the issue-report here: Problem with wrong indices
I need to start a VNC server (x11vnc) in my Raspberry pi 3. It's running without X-server (Raspbian Lite). My app (C++ QT 5) writes directly to Linux framebuffer.
Following to some instructions in Qt creator forum, I've done some progress.
At this moment I can start a x11vnc server, connect to Raspberry via a regular VNC client and use my app with mouse and keyboard.
YES, IT'S WORKING.
BUT... If I change the Raspberry resolution (raspi-config) to something different from 1280x720, I don't know why, I can't see the screen perfectly. The VNC client shows a distorted display, like the image bellow.
(And, unfortunately I can't set a fixed resolution)
This is my actual settings to start x11vnc:
x11vnc -permitfiletransfer -nopw -rawfb +/dev/fb0 -forever -noxrecord -noxfixes -noxdamage -xrandr -bg -shared -pipeinput UINPUT:accel=0.7,reset=0 -cursor none -nodragging
I already tried to start with -clip 1280x720+0+0, -geometry 1280x720 and -scale 1280x720, (with other values too) but had the same problem. =/
And I start my application like this:
my-app -platform linuxfb
Both are started with root user.
If someone have an idea of how to fix this, please tell me know! Thanks!
I've used this in the past but I must have got lucky. Now both Linux OSes I had have been deleted or screwed up but I can't for the life of me remember how I got them installed last time.
I really haven't got a clue, but are these the right steps:
(1) Uninstall all the old stuff
(2) Download Virtualbox 5.1.8 and install it
(3) Set up a new machine (eg. "Ubuntu64") and accept most of the defaults
I now know that that doesn't give me an OS to run! I need a "VDI" file containing a suitable Linux:
(4) Download Linux VDI for Virtualbox, unzip/un7zip etc to .vdi
Now is the tricky bit: how to I link this file to the Virtualbox new VM? In Storage, it seems to be set up to this file:
c:\Users\xxxxxx\VirtualBox VMs\Ubuntu\Ubuntu.vdi
That file exists but is some 2MB. Do I just copy the big .vdi I've just downloaded into that? Because if I do, it gives me an error:
UUID {7bfdc68e-2717-4c80-8613-6a2220358337} of the medium 'C:\Users
\xxxxxx\VirtualBox VMs\Ubuntu\Ubuntu.vdi' does not match the value
{553bdd10-e133-492f-85b9-3ec2c2fa4e67} stored in the media registry
('C:\Users\xxxxxx\.VirtualBox\VirtualBox.xml').
I would have edited that .xml file to match, but the UUID figure in that is different from either of the above! Anyway it seems like there is some official way of telling VB about this vdi; what is it? And if not, what have I done wrong? I downloaded another vdi with the same result.
I recently saw this error on programs which used to work fine. I think that the error started appearing after I did a sudo apt-get upgrade, which might have upgraded the Qt libraries on my machine.
I've reproduced this error for newly created project containing this code:
QDesktopServices::openUrl(QUrl("/home/sashoalm/Has Spaces.txt"));
QDesktopServices::openUrl(QUrl::fromLocalFile("/home/sashoalm/Has Spaces.txt"));
This produces 2 message boxes saying the same - /home/sashoalm/Has%20Spaces.txt: No such file or directory. But the file exists - I've verified that, xdg-open "/home/sashoalm/Has Spaces.txt" works fine, for example.
Any workarounds? When did this bug happen? My OS is Debian Wheezy.
Edit: I checked Qt4's source code, and the relevant code is this (from qdesktopservices_x11.cpp):
return (QProcess::startDetached(client + QLatin1Char(' ') + QString::fromLatin1(url.toEncoded().constData())));
QUrl::toEncoded() returns the percent-encoded path as file:///home/sashoalm/Has%20Spaces.txt. What is strange is that there were no changes in that file save updating the copyright notices since at before 2011. So it can't be a change in Qt. But the command issued by QDesktopServices::openUrl() is xdg-open file:///home/sashoalm/Has%20Spaces.txt, and that doesn't work on my computer. Perhaps it used to work before, and an update to xdg-open itself broke it? Does anyone know if xdg-open should handle file:/// with percent encoding?
on Qt5
QDesktopServices::openUrl(QUrl::fromLocalFile("/home/sashoalm/Has Spaces.txt"));
worked just fine. I was having the same problem when loading the file purely from a QUrl like the first line
QDesktopServices::openUrl(QUrl("/home/sashoalm/Has Spaces.txt"));
but when used the QUrl::fromLocalFile it just did the thing
Either escape the space with \
QUrl("/home/sashoalm/Has\ Spaces.txt")
or add quotes to the path: -
QUrl("\"/home/sashoalm/Has Spaces\"")
I ran into an issue getting the standard open CV face detection (facedetect) working. The web cam light comes on but noting happens, the program is launched with a tiny sized window like this:
I am working from an excellent blog post and sample code. Here I what I have done:
Install OpenCV & get OpenCV source
brew tap homebrew/science
brew install --with-tbb opencv
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.6/opencv-2.4.6.tar.gz
tar xvzf opencv-2.4.6.tar.gz
Run the facedetect sample with the standard classifier.
cd ~/opencv-2.4.6/samples/c
chmod +x build_all.sh
./build_all.sh
./facedetect --cascade="../../data/haarcascades/haarcascade_frontalface_alt.xml"
I can modify the C++ sample code and recompile and run, but I have no idea what the issue is.
Does anyone have a suggestion?
Update The issue is the image from cvQueryFrame is empty:
IplImage* iplImg = cvQueryFrame( capture );
frame = iplImg;
if( frame.empty() )
{
cout << "FRAME EMPTY\n"; // This is getting logged
break;
}
Update: It works ok when the source is a static image, so the issue is something related to the webcam source.
You can try to localise the problem, did you try to capture an image from the and web cam show it, without running any other operation?
It seems there is a problem capturing image from the web cam via OpenCV, this kind of problems may happen due to hardware, for instance on my friends macbook pro captured image was 320x240 and on mine it was 640x480. My friend just changed a simple configuration from settings of the camera and his problem was solved. Your problem might be something like this.
Or you can try to run face detector just with some images, you need to change the code such that it loads an image from your disk and try to detect face on them. If it doesn't work that way either we can say that your problem is not camera, there is a bigger issue, or if it works we can surely say that the problem is web cam.
EDIT
If you are using IplImage type be sure to get couple more images from the camera, sometimes first image is empty.
This was due to a bug in OpenCV - its been fixed ( bug report here http://code.opencv.org/issues/3156) , but the version in homebrew/science is from before the fix.
You can get install a newer version by editing the brew formula for opencv ( based on this pull request https://github.com/Homebrew/homebrew-science/pull/540 )
edit /usr/local/Library/Formula/opencv.rb , and replace these lines:
url 'http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.6.1/opencv-2.4.6.1.tar.gz'
sha1 'e015bd67218844b38daf3cea8aab505b592a66c0'
with these ones
url 'https://github.com/Itseez/opencv/archive/2.4.7.1.tar.gz'
sha1 'b6b0dd72356822a482ca3a27a7a88145aca6f34c'
Then do
brew remove opencv
brew install opencv
Works on Mavericks (for me at least), should work on Mountain Lion
UPDATE: the version of OpenCV in homebrew/science has now been updated, so this answer is now out of date!
brew upgrade opencv
will make homebrew get the latest version, with fixed webcam capture.