I am trying to produce shadows in a captured image in the Pybullet simulator. The shadows show up in the debugGUI mode but are not visible when calling p.getCameraImage even with shadow=True.
Something else I noticed is when shadow=True in p.getCameraImage there is a large shadow as if there is a tall object blocking the light rather than a small shadow corresponding to the object.
The issue persists whether connected to direct (p.connect(p.DIRECT)) or to GUI (p.connect(p.GUI)) as suggested here: https://github.com/bulletphysics/bullet3/issues/2610 and I have attached a minimum code sample below needed to reproduce the issue.
import pybullet as p
import pybullet_data
from PIL import Image
import math
physicsClient = p.connect(p.DIRECT)
p.setAdditionalSearchPath(pybullet_data.getDataPath())
p.configureDebugVisualizer(p.COV_ENABLE_SHADOWS, 1) # Shadows on/off
planeId = p.loadURDF("plane.urdf")
p.loadURDF("sphere_small.urdf",[0,0,0.2])
projectionMatrix = p.computeProjectionMatrixFOV(
fov=90.0,
aspect=16. / 9.,
nearVal=0.1,
farVal=30)
for i in range(360):
viewMatrix = p.computeViewMatrix(
cameraEyePosition=[2*math.cos(math.radians(i)), 2*math.sin(math.radians(i)),2],
cameraTargetPosition=[0.0, 0, 0],
cameraUpVector=[0, 0, 1])
width, height, rgbImg, depthImg, segImg = p.getCameraImage(
width=int(1280),
height=int(720),
viewMatrix=viewMatrix,
projectionMatrix=projectionMatrix,
shadow=True
)
im = Image.fromarray(rgbImg)
im.save('imgs/test/' + str(i) + ".png")
Related
With pyautogui I'm trying to locate a object in a screenshot that is being taken but I can't find a way
from pyautogui import *
import pyautogui
import time
import keyboard
import random
import win32api, win32con
time.sleep(2)
ims = pica = pyautogui.screenshot(region=(569,381,800,450))
iml = pyautogui.screenshot(region=(1040,295,100,30))
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)
#Color of center: (255, 219, 195)
while keyboard.is_pressed('q') == False:
flag = 0
pyautogui.screenshot(region=(1040,295,100,30))
ims.save(r"C:\Users\Billy Bong\Desktop\python\saveimage.png")
pica = pyautogui.screenshot(region=(569,381,800,450))
ims.save(r"C:\Users\Billy Bong\Desktop\python\saveimage2.png")
time.sleep (2)
pyautogui.locateAllOnScreen("saveimage.png", confidence=0.6)
print (cords)
pyautogui.click (cords)
time.sleep (10)
break
Here is the minimal code for locating an object on the screen, you should have the image of the object.
import pyautogui as py
import keyboard
while True:
img = py.locateOnScreen("object.png", confidence=0.9) # add path to your object image here
print(img)
if keyboard.is_pressed('q'):
break
there is something i found out about pyautogui if u gonna use locateonscreen or locateallonscreen the image u asking him to locate must be in same folder u running the script from (according to my experience from using VS-code) and idk if there is a way to tell it to set a path for the image u wanna search to (something) so for the current time make sure u include all images u search for in same folder that the script is running from for me it is (E:\coding\game) cuz i make auto bots for games i like
btw locateallonscreenn prints out a list, the "cords" but idk if "pyautogui.click (cords)
" understand that and if it is going to click all the x,y in cords or not
I have the following code which gives me a scatter plot on a dbc.Card element within Dash. I'm trying to figure out what I need to do in order to make the corners of the card rounded.
Here's the code I have currently:
import dash
from dash import dcc
from dash import html
from dash import Input, Output
import dash_bootstrap_components as dbc
import plotly.express as px
import pandas as pd
# import the Caffeine dataset
caffeine = pd.read_csv('caffeine.csv')
# create scatter plot
scatter = px.scatter(caffeine,
x='Volume (ml)',
y='Caffeine (mg)',
color='type',
title='Volume x Caffeine',
height = 800,
hover_data=['drink'],
template='plotly_dark'
)
# layout of Dash app
pp.layout = dbc.Container([
dbc.Row(
dbc.Col(html.H1("Analysis of Caffeinated Drinks",
className='text-center mb-4',),
width=12
)
),
dbc.Row(
dbc.Col(
dbc.Card(
dbc.CardBody(
dcc.Graph(
figure=scatter
)
)
),
width={'size':10, 'offset':1}
)
)
I've tried using the answer on this stackoverflow question (How to round the corners of a card (body and image) in Bootstrap 4?) and as such I tried inserting a style={border-radius: '20px'} in a couple of different places but haven't had any luck producing a change.
Is there another method I could/should use, or else could someone please show me exactly what to do? I'm pretty new to Dash as well as html and css.
Many, many thanks in advance!
If you set the style in a CSS file, you need to use border-radius: 20px;, but if you set the style directly on the dbc.Card component, you have to set borderRadius=20.
I would suggest you add in your style.css a class called something like card-style and there, you will add all the CSS stuff
So, in your code, you will add the class in the className of the dbc.Card
app.layout = dbc.Container([
dbc.Row(
dbc.Col(html.H1("Analysis of Caffeinated Drinks",
className='text-center mb-4',),
width=12
)
),
dbc.Row(
[(dbc.Col(
dbc.Card(
dbc.CardBody(
html.Div(f"card {n}")
),
className="card-style"
),
width={'size':3, 'offset':1}
)) for n in range(8)]
)])
And in your assets/style.css you will add something like:
.card-style {
border: solid black 1px;
border-radius: 8px;
height: 120px;
}
It will help you to not repeat yourself by simply creating this kind of class for your elements.
You can check and test the HTML elements by pressing F12 and selecting what you're interested in;
The output of the code above is the above
I am trying to display both an image and a box with an Entry widget. I can do that, but the window is so large that the widget at the bottom is mostly out of view. I have tried several calls to set the window's size or unmaximize it, but they seem to have no effect. I determined that the problem only occurs when the image is large, but still wonder how to display a large image in a resizable window or, for that matter, to make any changes to the window's geometry from code. All the function call I tried seem to have no effect.
Here is my code:
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from gi.repository import GdkPixbuf
from urllib.request import urlopen
class Display(object):
def __init__(self):
self.window = Gtk.Window()
self.window.connect('destroy', self.destroy)
self.window.set_border_width(10)
# a box underneath would be added every time you do
# vbox.pack_start(new_widget)
vbox = Gtk.VBox()
self.image = Gtk.Image()
response = urlopen('http://1.bp.blogspot.com/-e-rzcjuCpk8/T3H-mSry7PI/AAAAAAAAOrc/Z3XrqSQNrSA/s1600/rubberDuck.jpg').read()
pbuf = GdkPixbuf.PixbufLoader()
pbuf.write(response)
pbuf.close()
self.image.set_from_pixbuf(pbuf.get_pixbuf())
self.window.add(vbox)
vbox.pack_start(self.image, False, False, 0)
self.entry = Gtk.Entry()
vbox.pack_start(self.entry, True,True, 0)
self.image.show()
self.window.show_all()
def main(self):
Gtk.main()
def destroy(self, widget, data=None):
Gtk.main_quit()
a=Display()
a.main()
Most of the posted information seems to pertain to Gtk2 rather than Gtk3, but there is a solution: to use a pix buf loader and set the size:
from gi.repository import Gtk, Gdk, GdkPixbuf
#more stuff
path = config['DEFAULT']['datasets']+'working.png'
with open(path,'rb') as f:
pixels = f.read()
loader = GdkPixbuf.PixbufLoader()
loader.set_size(400,400)
loader.write(pixels)
pb = GdkPixbuf.Pixbuf.new_from_file(path)
self.main_image.set_from_pixbuf(loader.get_pixbuf())
loader.close()
I have multiple categorical heatmap plots that are in a single display that have identical shapes and x,y coordinates. When hovering on any of the subplots I would like the inspection on one plot to trigger a new inspection on all other plots in the grid and display multiple tooltips simultaneously.
I have researched this topic and found similar posts such as:
Bokeh: Synchronizing hover tooltips in linked plots
Takeaway from link above: There are 2 suggested answers to this question, which attempt to mimic hover tooltips with text glyphs, however these implementations are not successful when I copy and run the code on my own computer (the graphs display correctly but the hover text glyphs don't appear). I assume this could be because of Bokeh API updates, but I am unsure. My reputation doesn't allow comments or I'd address this issue there.
Coordinate tooltips across multiple plots #1547
Takeaway from link above: There is no reproducible data so I am not able to recreate the plot listed here, however bryevdv summarizes what I am trying to do quite efficiently which I'll quote below:
Link on geometry. You might want the geometry of the inspection on one plot to trigger a completely new inspection (using that same geometry) on another plot. So if the cursor is at (10.5, 7) on one plot, then the additional plots do a hit test at (10.5, 7) and if there are glyphs that have any hovers a that point, then a hover gets drawn there.
I have created some generalized data to illustrate my problem:
from bokeh.io import show, output_notebook
from bokeh.layouts import gridplot
from bokeh.models import LinearColorMapper, HoverTool
from bokeh.plotting import figure, show, output_file
from bokeh.transform import transform
import numpy as np
import pandas as pd
data1 = [['A','A',100], ['A','B',175], ['B','A',75], ['B','B',200]]
data2 = [['A','A',25], ['A','B',100], ['B','A',50], ['B','B',75]]
data3 = [['A','A',150], ['A','B',75], ['B','A',25], ['B','B',125]]
df1 = pd.DataFrame(data1, columns = ['Left','Right','Value'])
df2 = pd.DataFrame(data2, columns = ['Left','Right','Value'])
df3 = pd.DataFrame(data3, columns = ['Left','Right','Value'])
def heatmap(df, title):
letters = ['A','B']
mapper = LinearColorMapper(palette=['#225ea8', '#41b6c4', '#a1dab4', '#ffffcc'], low=0, high=200)
TOOLS = 'reset'
p = figure(plot_width=255, plot_height=250, title=title,
x_range=letters,
y_range=list(reversed(letters)), x_axis_location='above',
tools=TOOLS, toolbar_location='below')
p.grid.grid_line_color = None
p.grid.grid_line_width = 0.5
p.axis.axis_line_color = None
p.axis.major_tick_line_color = None
p.axis.major_label_text_font_size = '9pt'
p.axis.major_label_standoff = 0
p.xaxis.major_label_orientation = 0
hover = HoverTool()
p.rect(x='Right', y='Left', width=1, height=1, line_color=None, source=df,
fill_color={'field': 'Value', 'transform': mapper})
hover.tooltips = [('Group','#Left #Right'), ('Value','#Value')]
p.tools.append(hover)
return p
output_notebook()
p1 = heatmap(df1, 'Plot 1')
p2 = heatmap(df2, 'Plot 2')
p3 = heatmap(df3, 'Plot 3')
grid = gridplot([[p1,p2,p3]])
show(grid)
Output:
My goal is to be able to observe the values across multiple plots at one time without having to be directed to another page or source, so I am open to alternative ways of doing this that doesn't involve hover tooltips. Thanks!
IMAGE WITH ERROR IN MY PYTHON GAME:
I want to run my application, but see this error, how to fix it?
Image with a correctly format is not a possible to open, this is a simple game make in a Python
import random
from livewires import games
games.init(screen_width=640,screen_height=480,fps=50)
class Ship(games.Sprite):
def update(self):
if games.keyboard.is_pressed(games.K_RIGHT):
self.angle+=1
if games.keyboard.is_pressed(games.K_LEFT):
self.angle-=1
if games.keyboard.is_pressed(games.K_1):
self.angle=0
if games.keyboard.is_pressed(games.K_2):
self.angle=90
if games.keyboard.is_pressed(games.K_3):
self.angle=180
if games.keyboard.is_pressed(games.K_4):
self.angle=270
class Asteroid(games.Sprite):
SMALL = 1
MEDIUM = 2
LARGE = 3
images={SMALL : games.load_image("asteroida_s.bmp"),
MEDIUM : games.load_image('asteroida_m.bmp'),
LARGE : games.load_image('asteroida_l.bmp') }
SPEED=2
def main():
nebula_image=games.load_image("mglawica.jpg")
games.screen.background=nebula_image
for i in range(8):
x=random.randrange(games.screen.width)
y=random.randrange(games.screen.height)
size-random.choice([Asteroid.SMALL,Asteroid.MEDIUM,Asteroid.LARGE,])
new_asteroid=Asteroid(x=x,y=y,size=size)
game.screen.add(new_asteroid)
games.screen.mainloop()
def main():
nebula_image=games.load_image("mglawica.jpg",transparent=false)
games.screen.background=nebula_image
ship_image=games.load_image("statek.bmp")
the_ship=Ship(image=ship_image,
x=games.scren.width/2,
y=games.scren.height/2)
games.scren.add(the_ship)
games.screen.mainloop()
def play(self):
nebula_image=games.load_image("mglawica.jpg")
games.screen.background=nebula_image
self.advance()
games.screen.mainloop()
def advanced(self):
self.level+=1
BUFFER=150
for i in range(self.level):
x_min=random.randrage(BUFFER)
y_min=BUFFER-x_min
x=self.ship.x+x_distance
y=self.ship.y+y_distance
x%=games.screen.width
y%=games.screen.height
new_asteroid=Asteroid(game=self,x=x,y=y,size=Asteroid.LARGE)
game.screen.add(new_asteroid)
def end():
end_message=games.Message(value="Koniec gry",
size=90,
color=color.red,
x=games.screen.width/2,
y=games.screen.height/2,
lifetime=10*games.scren.fps,after_death=games.screen.quit,
is_sollideable=False)
games.scren.add(end_message)
def die(self):
if self.size !=Asteroid.SMALL:
for i in range(Asteroid.SMALL):
new_asteroid=Asteroid(x=self.x,
y=self.y,
size=self.size-1)
game.screen.add(new_asteroid)
self.destroy()
While your code is very messy (no indentation), I think I have a way to fix it. First, I question your need to import livewire, and also wonder why you marked this question as pygame. You never imported pygame. So my solution will be written in pygame.
First, you have to load the images (and if you want assign it to a variable):
image = pygame.image.load(filename)
Then, you have to convert the Surface, or basically just the image.
image = pygame.image.load(filename).convert()