how to Load captured image in sikuli? - sikuli

How to load captured image from a location into sikuli script and make it clickable.
here is what I am doing:
open pp
capture desired image
save it to some location
Now I want to load that captured image and make it clickable in code, so that functions in that carpeted image can be used as needed.
please assist... Or any work around will be much appreciated.
My Code
openApp('Safari') App.focus("Safari")
wait(10)
import shutil
import os
dir = "imgpath" wait(5)
image = capture()
name = input("abc")
newimg = os.path.join(dir, name + ".png")
shutil.move(image, newimg)

Related

In python-tkinter export images name to csv file

I am trying to build a pygame editor with python and tkinter.
I have this situation: on a tkinter canvas I can place tiles neatly and without overlapping (see attached image, tiles are taken from Ghosts 'n Goblins).
Now I would like to export what is displayed on the canvas to a csv file:
for instance, if in a particular cell there's no image I would like to export "-1" to the csv file;
if in the cell nearby there's an image (let's say 1.png) I would like to export "1" to the csv;
if the image displayed is "2.png" I would like to export "2" and so on.
I am able to open a csv file and write on it but I cannot retrieve the information I need from Tkinter.
I think I could use some kind of a for loop but I do not know where to start.
I've tried:
img_on_grid = []
def export_csv():
for row in range(8):
test_1=canvas.itemcget("image_B", "image")
img_on_grid.append(test_1)
print(img_on_grid)de here
but it doesn't work: it repeats the id item.
Any help will be appreciated.

What file does a icon have to be for the pygame.display.set_icon() function? [duplicate]

Does anyone know how to change the pygame icon?
I found a thing on the pygame website that lets you do this, but when I try it, it just makes the pygame window very small.
First load the icon image as a surface, then use pygame.display.set_icon(surface) to change the icon.
EDIT: Since the asker doesn't know what a surface is
From the docs at http://www.pygame.org/docs/ref/surface.html
"A pygame Surface is used to represent any image. The Surface has a fixed resolution and pixel format. Call pygame.Surface() to create a new image object."
For example, if you used screen = pygame.display.set_mode, screen is a surface.
So when using pygame.display.set_icon(surface) you must first import an image as a pygame.Surface by using a = pygame.image.load('image') where a is the variable the surface will be stored and 'image' is the directory to that image. Then you can set a to the icon by using pygame.display.set_icon(surface). You can pass any surface, but it is desirable that it is 32x32.
More information here: http://www.pygame.org/docs/ref/display.html#pygame.display.set_icon
programIcon = pygame.image.load('icon.png')
pygame.display.set_icon(programIcon)
This will set the icon of the Pygame window.
If you are using pgzero you can simply set global variable ICON to path to desired PNG file, like:
ICON = 'images/icon.png'
and pgzero will automatically replace default icon.
For more information see: https://github.com/lordmauve/pgzero/pull/128/files
You simply have to make an object, say an icon, and in that variable you have to give the path of the image you want to set as icon.
icon = 'your image path'
(Make sure you put double backslashes when writing path because writing single might give you an error)
After that you have to write:
pygame.display.set_icon(icon)
Make sure you have imported and installed pygame on your system
installation of pygame:
(if you are on windows):
hit windows+r on your keyboard... This will open a dialogue box and then hit enter. your cmd will open.. after that simply run this command:
pip install pygame
Then in your folder import it
In order to import it simply write:
import pygame
If your pip command shows you an error check the installation of python and try uninstalling python and then reinstalling it
Just make sure the display has been set and the icon is set before the caption:
icon = pygame.image.load('icon.png')
pygame.display.set_icon(icon)
You must be careful when setting a window icon. See pygame.display.set_icon():
[...] Some systems do not allow the window icon to change after it has been shown. This function can be called before pygame.display.set_mode() to create the icon before the display mode is set.
Set the icon before initializing the window pygame.display.set_mode(). e.g.:
icon = pygame.image.load('my_icon.png')
pygame.display.set_icon(icon)
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption(‘my window’)
In addition, the size of the icon is limited:
[...] You can pass any surface, but most systems want a smaller image around 32x32.
If the icon is not displayed, try a smaller icon.
Make sure that the resource (image) path and the working directory is correct.
The image file path has to be relative to the current working directory. The working directory is possibly different to the directory of the python file.
The name and path of the file can be get by __file__. The current working directory can be get by os.getcwd() and can be changed by os.chdir(path).
import os
sourceFileDir = os.path.dirname(os.path.abspath(__file__))
os.chdir(sourceFileDir)
An alternative solution is to find the absolute path.
If the image is relative to the folder of the python file (or even in the same folder), then you can get the directory of the file and join (os.path.join()) the image filename. e.g.:
import pygame
import os
# get the directory of this file
sourceFileDir = os.path.dirname(os.path.abspath(__file__))
iconPath = os.path.join(sourceFileDir, 'my_icon.png')
icon = pygame.image.load(iconPath)
pygame.display.set_icon(icon)

Selenium finding class inside div

I am trying to access and click the 'X' button via selenium in python to be able to be redirected to the next page and load some information from it. However, I am having a hard time finding the element, do not know whether it is because of being inside a class or something else. Can you guys help me out to actually click on the button. Code below is what I currently have.
Thank you in advance:
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
import time
from selenium import webdriver
driver = webdriver.Firefox()
url = 'https://shop.axs.co.uk/Lw%2fYCwAAAAA6dpvSAAAAAABB%2fv%2f%2f%2fwD%2f%2f%2f%2f%2fBXRoZW8yAP%2f%2f%2f%2f%2f%2f%2f%2f%2f%2f'
opts = Options()
browser = Firefox(options=opts)
browser.get(url)
#wait for all elements to load
time.sleep(5)
#working lines are commented out
#search_form = browser.find_element_by_class_name("modal-open")
browser.find_element_by_class_name('btn-close-svg pull-right').click()
Remove this lines -
opts = Options()
browser = Firefox(options=opts)
use the xpath here-
driver.find_element_by_xpath(".//div[#class='btn-close-svg pull-right']").click()

HTML5 Save Video/Canvas Tag to File

I have a page that plays 4 videos from a local source, and I combine those all into a canvas so that all display through one element (I update the image on the canvas every X seconds). Is there any way I can save that into a video file?
First: I do not recommend the following method for big amounts of data!!
You can create an array with a size big enough to store the whole video:
//Size: Colour channels * width * height * noOfFrames
//THIS WILL GET BIG!!
var video = new Uint8Array(3*640*480*24);
Then store every frame of your video in the array
Now you could use this snippet as a start to convert it to a DataUrl:
var base64String = btoa(String.fromCharCode.apply(null, video));
(http://stackoverflow.com/a/11562550/1554114)
This would give you something like RAW-Video.
This is a link with a DataUrl, save it via right-click / save as.. / "Test.mp4"
(Let's see if SO can handle this :D -- No, it can't :( -- Press the 'edit' button to see what it looks like)
Implementing h264 in JavaScript is up to you then ;)

HTML5/Canvas - Save Base64 image to server (replacing current image)

I am currently experimenting with the HTML5 Canvas.
I currently made a simple little painting app where you can draw lines and what not.
I made it so I can save the image in base64. with
var dataUrl = document.getElementById('your-canvas').toDataURL();
I was wondering if it is possible to take that image, and save it to my server (or anywhere) replacing/overwriting an image that is already there.
The goal of this is to have the saved image as the background for the canvas. Then every time someone draws on the canvas and clicks save, it saves their drawing as the background image so the next person who goes on it can see what the last person drew.
Basically a public internet whiteboard.
Can someone tell me if this is possible, and point me in the right direction (code languages, tutorials, etc.)?
Thanks.
You can display or save image like this:
$imgData = $_POST['data'];
$imgData = str_replace(' ','+',$_POST['data']);
$imgData = preg_replace('/^data:image\/(png|jpg);base64,/','',$imgData);
header("Content-type: image/png");
echo base64_decode($imgData);