I'm trying to take a screenshot of the screen in my C++ code. The code is executed in the terminal.
I only have few milliseconds to capture the screen so I would like to use a code that is possibly really fast.
So far I have tried:
System("import -window root screenshot.jpg");
but It fails stating that it doesn't recognize import.
I have also tried:
System("sudo scrot");
which fails as well with this error: "Can't open X display. It is running, yeah?"
Any ideas on how to take a screenshot of screen really fast?
Related
I'm trying to get back into programming with OCaml after a long time of not using it, and since I don't have Linux on my current computer, I've been trying to do it through WSL (Windows Subsystem for Linux).
After doing everything as I would have in Linux, whenever I try to compile a piece of code using the Graphics module, I get the following outcomes:
If I try to use the open_graph command, I get the following error:
Exception: Graphics.Graphic_failure "Cannot open display ".
I get that exact error if the argument of open_graph is an empty string, or starts with a space. If the string argument is not empty and doesn't start with a space (which, from what I've read, shouldn't be used anyway), the error message includes said argument as follows:
Exception: Graphics.Graphic_failure "Cannot open display [argument of open_graph]".
If the code only uses base OCaml commands and Graphics commands that doesn't require an open graph (like rgb), everything compiles normally.
I found this thread where users raised the question of the DISPLAY variable possibly being "wrong". The original poster of said thread has a different issue, but I felt it is relevant, as I was thinking that perhaps using WSL could have made my DISPLAY variable "off", or could require me to use a different value for DISPLAY than I would use on a complete Linux OS - but, to be perfectly honest, I have no idea what that would be.
I tried my best to understand everything I read and to explain my issue clearly, but I only have moderate experience with Linux and programming in general, so I'm sorry if I misunderstood something or if my explanations weren't the clearest. In that case, please let me know, and I will try my best to rectify it.
Cheers!
Example of complete code and exact error message:
#use "topfind";; #require "graphics";; Graphics.open_graph "";;
Error message returned:
Exception: Graphics.Graphic_failure "Cannot open display ".
According to https://github.com/ocaml/graphics/issues/21 you need to install a X11 server in your WSL environment.
I've followed a few tutorials on setting up Xming and putty, and also trying with cygwin but there is one particular C progam from a raspberry pi I'm having issues with over ssh to my windows machine. I've been somewhat successful as I can get Pygame and a few other small things to show up on my desktop. I'm now trying to do the same thing with the C program that uses SDL and OpenGL packages. When I try to run the program through ssh I get init_sdl() PuTTY X11 proxy: wrong authorisation protocol attempted
I also get the same error when trying to run it with MobaXterm.
at one point I did get init_sdl() without the error, but there should be two more lines that follow after that and then a GUI appear, and it isn't happening. So I think it's hanging on trying to initialize sdl? I'm not really sure. Are there any other resources I need for my windows side client?
If needed, here's the program I'm trying to run. It does work on the pi, just not over ssh. https://github.com/bear24rw/rgb_table/tree/master/code/table_drivers/beat_finder
Update: I can get init_sdl() to show every time now without the error following in cygwin, but still not getting a GUI to show or get the the full readout of
init_sdl()
init_gl()
init_fft()
init_serial() which is what should show.
EDIT2: There is a use_gui = TRUE/FALSE; option in the code, when I set this to false, I get init_fft() and init_serial() and the code works, but I would still like to have what's missing with SDL or GL to get the GUI part to work over SSH.
I have been using ARToolKit to calibrate my camera, everything went fine until I tried to save the result, it came up with this error:
Error (13): unable to open camera parameters file "camera_para.dat" for writing.
Result too large
Parameter write error!!
I used the ARToolKit's calib_camera example code.
Thank you in advance!
I've actually figured this out...it was just because my ARToolKit was installed in Program Files folder, which is read-only. To save the results successfully, all you need to do is to run as administrator at the beginning.
I am trying to write up a C++ program for a class using XCode. One of the things I wish to do, is to simply clear the screen. I've looked into how to do this, however the catch is that the code needs to run on both a Windows and Macintosh computer. I've looked at some other similar questions, but none of the answers help me. I know there is no "screen" but I want the system to clear the output window. I know that the command system("clear"); does what I want it to, but when XCode tests the program, instead of clearing the screen it prints TERM Variable not set
I've tried opening up the terminal and typing clear and it does in fact respond the way I want it to, so why doesn't the 'terminal' inside of XCode do the same? I just want to get the output window in XCode to respond to clear the same way that the terminal already does.
Here is something I have already tried;
I went to the terminal and ran echo $TERM, to which the terminal responded xterm-256color. I then went over to XCode and opened the "Scheme" settings, and found an Environment Variables setting under "Arguments". I added a variable (to the blank list) called TERM and gave it value xterm-256color. Upon running the program again, the output displays ¿[H¿[2J in the output window, positioned where the TERM Variable not set used to be printed.
Last thing, as a reminder, I cannot change the source code from the way it is now, or it could cause errors when the program is run on a Windows machine.
It does not work because you are "lying": The terminal in Xcode is not a xterm-256color, but it is dumb terminal. More precise, the display represents a NSTextStorage that collects stdout and/or (depending on target switch) stderr.
A dumb terminal is not able to clean the display. If you want to change this, you can write a plug-in similar to Xcode-Colors what adds the ability to understand ansi color codes.
However, if your requirement that the code simply run at Windows and OSX, you may stick with your solution system("clear"), since it works prefectly in the "normal" OSX terminal.
I am trying to set OpenCv up for my final year project and have run into a couple of problems. I successfully got it set up in Ubuntu following this tutorial.
The problem I am having now is keeping this sample program running. The program is face detection using a webcam.
It runs fine for 3 or 4 seconds and then the capture gets stuck with a single frame in the window. The console displays the following output.
tom#ubuntu:~/College/opencv/faceDetect_sample$ make
./faceDetect --cascade="haarcascade_frontalface_alt.xml" --nested-cascade="haarcascade_eye_tree_eyeglasses.xml"
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
init done
opengl support available
select timeout
select timeout
select timeout
select timeout
select timeout
select timeout
^Cmake: *** [run] Interrupt
If anybody has an idea of where to go from here, I would really appreciate some help !
Try this:
modprobe uvcvideo nodrop=1 timeout=6000
and if that works, simply make the changes permanent by editing /etc/modprobe.d/modprobe.conf
Try increasing the timeout to a ridiculously large number. That should fix the issue, or at least it worked for me. It's just that the call to select returns no ready descriptors, and that may be caused by the video driver, or device one.
If that does not work,
Enable module traces:
sudo echo 0xffff > /sys/module/uvcvideo/parameters/trace
Run the program until the error is found, and stop it as soon as possible. Then disable the traces:
sudo echo 0 > /sys/module/uvcvideo/parameters/trace
Search with dmesg for error messages.
It can be resolved if we add the following lines to the code:
VideoCapture capture(<device id>);
capture.set(CV_CAP_PROP_FRAME_WIDTH , 352);
capture.set(CV_CAP_PROP_FRAME_HEIGHT , 288);
Following is a good link where the solution is explained in detail:
http://derekmolloy.ie/beaglebone/beaglebone-video-capture-and-image-processing-on-embedded-linux-using-opencv/
I had the same issue with my Logitech C920. I tried the following solutions without any success. However, it worked like a charm with the C930e webcam so I guess the V4L API has something to do with it.