I am using Data science toolbox running ubuntu 14.04 through vagrant in windows.
I installed OpenCV and tried a very simple python code.
import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread('image1.jpg' , cv2.IMREAD_GRAYSCALE)
cv2.imshow('image' , img)
cv2.waitKey(0)
cv2.destroyAllwindows()
When i run this code i get an error -
(image:1267): Gtk-WARNING **: cannot open display:
I have searched on internet but not able to find a solution working for me.
I have tried -
export DISPLAY=:0.0
export DISPLAY=:0
and many more.
I have also tried xhost +localhost but this gives another error
xhost: unable to open display ""
Anyone know a way to solve this problem.
You can forward the display to your host, in your Vagrantfile, add the following lines
config.ssh.forward_agent = true
config.ssh.forward_x11 = true
You will need a X-server running on your windows machine (I personally use Quartz on my mac, you would need to get an equivalent for windows, like Xming) and then when you vagrant up to boot your VM, when you will run an X-program it will pop-up on your host.
Related
Hy guys, i am trying to use vscode in kali linux.
But I ran into a problem.
The moment I start the python file from the play symbol in the terminal it gives me a permission error.
But if I boot from the terminal using sudo python main.py it works fine.
Would you know how to help me fix this problem?
i am used to launch with play, i find it annoying to type in the terminal every time.
Screen error
I also tried the solution found on the internet of sudo code --user-data-dir = "~ / .vscode-root" my/path, but it doesn't solve the problem.
the code to execute:
import socket
import struct
import binascii
s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0800))
while True:
print (s.recvfrom(2048))
Try to use :
sudo code
in the terminal
If it doesn't work try to remove it and install it again.
I try to take a screenshot and display it with the following code:
import pyautogui
im = pyautogui.screenshot()
im.show()
but it says in the console Access is denied. and pops a windows error:
same error if i save the picture and try to double click it from the explorer (not with python), but I can open it with sublime text for some reason.
code used for saving:
import pyautogui
import PIL
im = pyautogui.screenshot()
im.save(r'screenshot1.png')
im = PIL.Image.open(r'screenshot1.png')
im.show()
how do i solve this? should i change permissions on taking the screenshot somehow?
You need to change the startup type of your Windows license management service.
Search for "Services" in your computer, and open the Services Management. Find the Windows license management service, and change the startup type to "Automatic". Press "apply" and "ok".
Refer to this for visualization of the process.
I am trying to install OpenCv and run some code on PyCharm on Mac.
I have installed the opencv package as well as numpy but when I run the code this error shows up on Pycharm IDE: "cannot find reference 'VideoCapture' in __init__.py"
In fact, every time I write example_variable = cv2., PyCharm is not giving me any option to autocomplete with a function attached to cv2. Why is this happening?
Here's the code I am trying to run. I tried also running other codes but the same error displays:
import cv2
import numpy as np
cap = cv2.VideoCapture()
while True:
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & OxFF == ord('q'):
break
cap.release
cv2.destroyAllWindows()
Any tips on how to run this code smoothly? The end goal is to have my front webcam capture live video and react to it.
Try one of this solutions:
Right-click on source Directory
Mark Directory as -> source root
File --> Invalidate Caches / Restart... -> Invalidate and Restart
OR:
In your IDE, go to settings -> preferences -> django
Ensure your Root directory, your settings.py and your manage.py are in the right place
if you are in Django.
After all that, you can also delete the .idea folder in your root directory and restart the IDE.
pip install --force-reinstall --no-cache -U opencv-python==4.5.5.62
use this command line to avoid the reference issue.
Instead of import cv2 use from cv2 import cv2
I agree with "from cv2 import cv2"
there have an another way to solve problems:
** Do Not Use Pip Install **
I try to use download opencv_python-4.5.5.62-cp36-abi3-win_amd64.whl file and then manual double click to install
wait a minute, Pycharm IDE successfully Show code completion.
by the way,can your code run?
if code can run, above will help you a bit.
and your path(project python) should be Englisgh ; not be Chinese or other language.
This worked for
Before I was using python from Anaconda, instead
Choose the default python interpreter
So I'm just trying to run the basic OpenCV program
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRA)
# Display the resulting frame
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
But for some reason when I try to run it (with python 2 or 3) I get this weird abort statement
[1] 74309 abort python3 index.py
(I'm guessing the 5 digit number is the PID) However, it does work if I pass in a path to an already existing video in the VideoCapture function. I am a beginner in all of this so I'm not really sure what the problem is
Thanks :)
I found the solution!
I tried running the script using the default terminal that comes with mac and it worked :) So it seems there was some weird issue with the third party terminal (iTerm) I was using
You have to authorize iTerm to access the camera (in System Preferences). By default, neither Terminal nor iTerm has this permission. macOS Mojave just asks to allow iTerm and your Python program works fine!
It's not a problem with iTerm, or maybe was a problem.
I had the same problem running OpenCV from VSCode. It turned out to be indeed permission error for accessing the camera on the new macOS. I couldn't get VSCode to ask for the permission (or add it manually through system preferences).
My solution was to run VSCode as root using
sudo /Applications/Visual Studio Code.app/Contents/MacOS/Electron
It's not the cleanest solution, but it worked for me.
In VSCode ,
1.type cmd+shift+p
2.type "shell command: Install code in PATH"
3. Close vscode
4. Use "sudo code" to open vscode
5. It will give warning not to run as a root user
6. Ignore the warning and run the file , you will not get the "Abort trap: 6" error anymore.
I'm running this Python script on my (Debian) server to write out an animation from vtk data:
import paraview.simple as pv
pv.servermanager.LoadState('plot.pvsm')
pv.SetActiveView(pv.GetRenderView())
pv.WriteAnimation('images/bj.png', Quality=2)
It is supposed to create this animation while I'm not logged on the server. For that I use screen and run the script with:
pvbatch --use-offscreen-rendering plot3d.py &
It does its job well by writing the image files. However, when I detach from the screen session and log out the script stops completely.
In my understanding the option --use-offscreen-rendering should make sure that no rendering on my screen happens. This works on my client machine where I can run the same script and kill the terminal and the script continues.
Maybe relevant: For every image I get the error message:
libGL error: failed to authenticate magic 1
libGL error: failed to load driver: i965
where the number after "magic" increases with each image.
My system:
Debian Linux 3.16.7-ckt11-1 (2015-05-24), kernel 3.16.0-4-amd64
Paraview 4.1.0
Python 2.7.9
Screen 4.02.01
You still need access to X server even though you're using --use-offscreen-screen flag. If you want truly offscreen, you should rebuild your ParaView with OSMesa support as described here