image not loading in opencv2 [duplicate] - python-3.x

This question already has answers here:
openCV imshow not rendering image on screen
(3 answers)
Closed 6 years ago.
I am using opencv2 in python to load image using the numpy
import numpy as np
import cv2
img=cv2.imgread('C:\im.jpg',0)
cv2.imshow('image',img)
when I execute this code the image window pops up but it doesn't show any image and crashes up.

You lack the waitKey() function after imshow.

Related

Cannot display latex in Sympy

enter code hereI am a beginner in jupyter and am trying to do symbolic computations using sympy.
after running the following code
%matplotlib inline
import sympy as s
s.init_printing()
from IPython.display import display_latex
theta=s.symbols('theta')
print(theta)
instead of getting the symbol for theta the output is "theta"
I can get latex display in markdown cell so I don't thins that this is a mathjax issue
I am using jupyterlab 3.0.14
I know this is a duplicate but implementing fixes other discussions didn't resolve my issue

Why does Matplotlib saved figure look weird? [duplicate]

This question already has answers here:
Matplotlib savefig background always transparent
(2 answers)
How to set opacity of background colour of graph with Matplotlib
(2 answers)
Closed 1 year ago.
I am using the plotting pandas data frame and, saved the resulting figure using the following code. The output file looks weird when opened in image viewer as shown here.I don't understand why the background is not fully white.
I am using Linux OS called Zorin, which is a derivative of Ubuntu if that makes a difference.
fig, ax = plt.subplots(figsize=(15, 10))
account_profit_df.plot(
style="*-",
figsize=(15, 10),
title="test",
ax=ax,
)
plt.grid()
fig.savefig(
image_path_backtest,
bbox_inches="tight",
)
This is the default behaviour, you can set the background color using: fig.patch.set_facecolor('white')

How to get the value of a pixel from the screen (GTK 3, Shell, Linux) [duplicate]

This question already has answers here:
How can I grab the color of a pixel on my desktop? (Linux)
(4 answers)
Closed 2 years ago.
I am trying to do some automation on Linux, and I can't find a good way to get a pixel value from the screen, given 2 coordinates.
I have this python code:
#!/usr/bin/env python3
import pyautogui
import sys
image = pyautogui.screenshot()
print(str(image.getpixel((int(sys.argv[1]), int(sys.argv[2])))))
How can I do this without taking a screenshot and instead read from the pixel buffer?
If there is a program that someone knows about that can do this (I've heard AutoHotkey on windows can), that would also be helpful, as I'm using shell script (and lots of xdotool) to do the automation.
The following code, when called like this: ./getColor.py [X coordinate] [Y coordinate], will print the decimal RGB color value of the specified pixel on the screen in the form (R, G, B)
#!/usr/bin/python
import gi, sys
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk
pixbuf = Gdk.pixbuf_get_from_window(Gdk.get_default_root_window(), int(sys.argv[1]), int(sys.argv[2]), 1, 1)
print(tuple(pixbuf.get_pixels()))

Suppress plot window when creating figure

For years I have created figures using some rendition of the following code:
import pylab as pl
fig = pl.figure(figsize=(3.5, 2.5))
ax0 = fig.add_subplot(111)
Earlier this week I had to reinstall Python using the most-recent Anaconda Python 3.7 release (previous version was also 3.7). The problem is when I create my figure the figure window appears immediately (normally the figure window would never appear until I called fig.show()). I checked the matplotlib backend to see if it was different, but it is set to qt5agg. I don't think the backend is the problem. Does anyone know of a recent change in matplotlib that would cause the figures to pop up...anyone know how to prevent them from popping up without setting the backent to agg?
Current matplotlib version: 3.1.1

getting the color of pixels on the screen in Python3.x

I want to get the color of pixels on the screen in Python3.x. (example x,y)
I work on windows. and using tkinter.
But, It can't use PIL in Python 3.x.
How can i do this.
Thank you.
You can use PIL on Python3.x; there is a binary installer for Windows. The code might not work as is both on Python2.x and Python3.x:
try: import Image # Python 2.x
except ImportError:
from PIL import Image # Python 3.x
You could capture an area of the screen using an analog of grab() method.

Resources