Python Forum
drawing random over the image
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
drawing random over the image
#1
I am trying to draw randomly over the image. Image can be either .jpeg file or simple black background. Once the drawing is complete I need to save the drawing as a numpy array.
I have found a few solutions that might work but non of them work for me for some reason.
For example, one idea is to use tkinter
from tkinter import *
app = Tk()
app.mainloop
canvas = Canvas(app, bg='black')
canvas.pack(anchor='nw', fill='both', expand=1)
def get_x_and_y(event):
    global lasx, lasy
    lasx, lasy = event.x, event.y

def draw_smth(event):
    global lasx, lasy
    canvas.create_line((lasx, lasy, event.x, event.y), fill='red', width=2)
    lasx, lasy = event.x, event.y
(
)
However, when I run the codes above it just seems to "run" in the infinite loop in the first three lines. I am also note sure how to convert this drawing into numpy.

I have also tried this:
import cv2
import numpy as np 
im = cv2.imread("einstein.jpg")
cv2.namedWindow("Jenya Polyakova OpenCV")
cv2.setMouseCallback('Jenya Polyakova OpenCV',geology_draw)
while(1):
    cv2.imshow('Jenya Polyakova OpenCV',im)
    k=cv2.waitKey(1)&0xFF
    if k==27:
        break
cv2.destroyAllWindows()
Again, it just seems to go into infinite loop. I am using jypiter notebook to compile.
I also have seen some turtle solution but have not tried.
Any ideas/suggestions would be appreciated.
Thank you!
Larz60+ write Sep-02-2021, 01:56 AM:
Duplicate thread other removed
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020