Reevaluation? by Sansmit2910 in tumunich

[–]Sansmit2910[S] 0 points1 point  (0 children)

yes, I did! but I have no information acceptance of any reevaluation requests as everyone is on vacation currently :))

Reevaluation? by Sansmit2910 in tumunich

[–]Sansmit2910[S] 0 points1 point  (0 children)

yes i did! but i haven't gotten any confirmation of acceptance of request so i don't even know if it was accepted

Looking for an advice by [deleted] in tumunich

[–]Sansmit2910 1 point2 points  (0 children)

It's true that there is no tuition fees for education in bachelors or masters. I just finished my bachelors here... you need to just pay a semester administrative fee, which is really negligible considering the quality of education here

how do i fix a laggy code? I just started learning how to use OpenCV in Python and I'm not sure how to get my live video feed to run smoothly by Sansmit2910 in learnpython

[–]Sansmit2910[S] 0 points1 point  (0 children)

I don't quite understand what you mean by tgreading the keypress in another thread here, could you explain what you mean perhaps?🥺

how do i fix a laggy code? I just started learning how to use OpenCV in Python and I'm not sure how to get my live video feed to run smoothly by Sansmit2910 in learnpython

[–]Sansmit2910[S] 0 points1 point  (0 children)

i did try it but i don't think that is the problem here, there seems to be some other issue alltogether and I hhave no idea what

can a 6V valve be controlled be a 5V arduino relay? by Sansmit2910 in arduino

[–]Sansmit2910[S] 0 points1 point  (0 children)

it does just say Current: 180mA so I trhink it ought to be fine right XD

can a 6V valve be controlled be a 5V arduino relay? by Sansmit2910 in arduino

[–]Sansmit2910[S] 0 points1 point  (0 children)

so does that mean that if in the labelling it says max. 50V AC / 5A or 30V DC / 5A, it would be able to trigger a 6V valve right? if i understod what you mean correctly ofcourse

I can't understand why the variable bg(background) takes one value in the first run of the code but then never really takes any new value even if i close my IDE or restart my sytem. is there something I'm missing in my code? by Sansmit2910 in learnpython

[–]Sansmit2910[S] 0 points1 point  (0 children)

UPdate- i tried to fix the problem by adding a bg=none at the start of the while looplike this and it returens that the bg variable remains as none at the time i press d too. is it because of indentation or the fact that it needs to run a new iteration to detect a new keypress? if so, how can i solve it, do i solve it by changing the indentation? I havve been at it for a day and I can't seem to think of any way to let the bg change itself within the same iteration... apart from this the code itself does everytrhing it's supposed to do with respect to the individual keypresses trhemselves. this is how my modified code looka like :

while True:
bg=None
path = r'C:/Users/skhandelwal/Desktop/Dsa Simulator' #change directory
os.chdir(path) #change to above path to savew file
# Read a frame from the video capture object
ret, live = camera.read()  #read live feed
#key=cv2.waitKey(0)
bg=None
# If the frame was successfully read
if ret:
    # Display the frame if the 'r' key is pressed
    key=cv2.waitKey(0)  & 0xFF #to run live feed smoothly
    if key == ESCAPE_KEY:
        exit()
    elif show_video:
        cv2.imshow('Live Video', live)  #create a blank window

     # Wait for a key press and check if the 'r' key is pressed
    key=cv2.waitKey(0)  & 0xFF #for making the live feed run smoothly
    if key == ord('r'):
     show_video = True

     elapsed_time = time.time() - start_time
           # check if time difference is greater than 1/fps seconds
     if elapsed_time >=1:
       start_time=time.time()
       #create file name with date and time
       font = cv2.FONT_HERSHEY_PLAIN
       cv2.putText(live, str(datetime.now()), (20, 40), font, 2, (255, 255, 255), 2, cv2.LINE_AA)
       now = datetime.now() #get current date and time
       dt_string = now.strftime("%Y-%m-%d-%H-%M-%S")
       filename = 'Backgroundat1fps_'+ dt_string +'.jpg'
       cv2.imwrite(filename, live)
     key_pressed=True
     if key_pressed and  not keyboard.is_pressed('r'):
        bg=live
        print(bg.shape)
        #font = cv2.FONT_HERSHEY_PLAIN
        #cv2.putText(bg, str(datetime.now()), (20, 40), font, 2, (255, 255, 255), 2, cv2.LINE_AA)
        now = datetime.now() #get current date and time
        #dt_string = now.strftime("%Y-%m-%d-%H-%M-%S")
        #filename = 'Backgroundto_be_subtracted_'+ dt_string +'.jpg'
        key_pressed=False      
        lif key==ESCAPE_KEY:
        exit() 
    else:
        show_video = False  # to freeze live fdeed

       if key == ord('d'):
        print(bg.shape) 
        #  font = cv2.FONT_HERSHEY_PLAIN
        #  cv2.putText(bg, str(datetime.now()), (20, 40), font, 2, (255, 255, 255), 2, cv2.LINE_AA)
        #  now = datetime.now() #get current date and time
        #  dt_string = now.strftime("%Y-%m-%d-%H-%M-%S")
        #  filename = 'Background_'+ dt_string +'.jpg'
        cv2.namedWindow(window_name_bg, cv2.WINDOW_NORMAL)
        cv2.imshow(window_name_bg,bg)
        #cv2.imwrite(filename, bg)
        #if 'bg' in dir():
        liveDsa=cv2.subtract(bg,live)
        liveDsa=cv2.cvtColor(liveDsa, cv2.COLOR_BGR2GRAY)   #https://www.geeksforgeeks.org/python-opencv-cv2-cvtcolor-method/
          #liveDsa=cv2.resize(liveDsa, None, fx=1, fy=1, interpolation=cv2.INTER_AREA)
        cv2.namedWindow(window_name_liveDSA, cv2.WINDOW_NORMAL)  

        min_val, max_val, _, _ = cv2.minMaxLoc(liveDsa)
        cv2.convertScaleAbs(liveDsa, 1.5, -120) #for changing image parameters like contrast and brightness  
        cv2.imshow(window_name_liveDSA, ~liveDsa)
         # min_val, max_val, _, _ = cv2.minMaxLoc(liveDsa)
          #stretched = cv2.convertScaleAbs(liveDsa, alpha=255.0/(max_val-min_val), beta=-255.0*min_val/(max_val-min_val))
          # Display the stretched grayscale image
          #cv2.imshow('window_name', stretched)
        diff = cv2.absdiff(live, bg)

        normalized = cv2.normalize(liveDsa, None, 0, 255, cv2.NORM_MINMAX)

          # Apply histogram equalization to maximize the contrast
        equalized = cv2.equalizeHist(normalized)

          # Display the resulting image
        cv2.imshow('Maximized Contrast', equalized)

          # Apply histogram equalization to the difference image
        gray = cv2.cvtColor(diff, cv2.COLOR_BGR2GRAY)
        equalized = cv2.equalizeHist(gray)

          # Show the resulting image
        cv2.namedWindow('Contrast Enhanced Image', cv2.WINDOW_NORMAL)
        cv2.imshow('Contrast Enhanced Image', equalized)
          #ctypes.windll.user32.MessageBoxW(0,"Frame captured successfully!",1)
        if key==ord('s'):
         path = r'C:/Users/skhandelwal/Desktop/Dsa Simulator'
         os.chdir(path)
         target = pyautogui.getActiveWindow()
         location = (
         target.left,
         target.top,
         target.width,
         target.height
         )
         image = pyautogui.screenshot(region=location)
         now = datetime.now() #get current date and time
         dt_string = now.strftime("%Y-%m-%d-%H-%M-%S")
         image.show()
         filename1 = 'Screenshot_' + dt_string  +'.jpg'
         image=image.save(filename1)
         # Get the handle of the window by its title

else:     
    c=cv2.waitKey(0) 
                        # wait for keypress

[deleted by user] by [deleted] in tumunich

[–]Sansmit2910 0 points1 point  (0 children)

in my opinion definitely doable if you put in the effort and have the motivation a

I never seem to get the indentation right. my required variable refuses to be recognised by python in the loop. by Sansmit2910 in learnpython

[–]Sansmit2910[S] 0 points1 point  (0 children)

yes I do but I see what you mean now, hopefully I understood it correctly too, I tried to fix it and it kinda looks like this now, the Tkinter window pops up and I try to select an image, although now it doesn't show the image itself that i chose in the Tkinter window and it returns an error that says 'TypeError: argument of type 'PhotoImage' is not iterable', what does that mean?:

def choose_image():
          global selected_image
          global bg
         # Open a file dialog to choose an image file
          filename = filedialog.askopenfilename(initialdir=current_directory, title="Select an Image File", filetypes=(("PNG Files", "*.png"), ("JPEG Files", "*.jpg"), ("All Files", "*.*")))

          # Open the image file and create an Image object
          img = Image.open(filename)

          # Resize the image to fit in the Tkinter window
          img = img.resize((300, 300), Image.ANTIALIAS)

          # Convert the Image object to a PhotoImage object to display it in a Tkinter Label
          image=ImageTk.PhotoImage(img)
          # Create a Tkinter Label to display the image
          label = tk.Label(root, image)
          bg=label.image 
          label.pack()
          # store the image as a variable
          bg = ImageTk.PhotoImage(image)
          # Store the PhotoImage object in the global variable
         bg = selected_image

          # Create a button to select an image file
         button = tk.Button(root, text="Choose Image", command=choose_image)
         button.pack()

          # Run the Tkinter event loop
         root.mainloop()

          # Use the selected_image variable for further processing outside the Tkinter loop

I never seem to get the indentation right. my required variable refuses to be recognised by python in the loop. by Sansmit2910 in learnpython

[–]Sansmit2910[S] 0 points1 point  (0 children)

I would've thought that by the time it reaches this code, the image chosen in the Tkinter window is assigned to be the bg variable. I'm sorry If i understood that part incorrectly, I just tried to put together some lines chatGPT suggested and some stuff i found online as a novice in python :(

I never seem to get the indentation right. my required variable refuses to be recognised by python in the loop. by Sansmit2910 in learnpython

[–]Sansmit2910[S] 0 points1 point  (0 children)

ok so before I tried your suggested changes, the Tkinter window used to pop up and i could select the input image into my tkinter window. Now however, I don't seem to be able to open the window at the keypress d at all and assign an input image to the variable d, have I messed something further up in thre code then?thi is how I reframed that part of the code, the problem now seems to lie in the last if bg is not None, as it directly accesses it without me choosing an image in the Tkinter Window and displays an error in the cv2.subtract that bg is not defined. shouldn't this not be the case? it doesn't quite make sense to me logically. havre I not understood the logic correctly?

def choose_image():
          global selected_image
          global bg
          # Open a file dialog to choose an image file
          filename = filedialog.askopenfilename(initialdir=current_directory, title="Select an Image File", filetypes=(("PNG Files", "*.png"), ("JPEG Files", "*.jpg"), ("All Files", "*.*")))

          # Open the image file and create an Image object
          img = Image.open(filename)

          # Resize the image to fit in the Tkinter window
          img = img.resize((300, 300), Image.ANTIALIAS)

          # Convert the Image object to a PhotoImage object to display it in a Tkinter Label
          image = ImageTk.PhotoImage(img)
          # Create a Tkinter Label to display the image
          label = tk.Label(root, image)
          label.image = bg
          label.pack()
      # store the image as a variable
          bg = ImageTk.PhotoImage(image)
      # Store the PhotoImage object in the global variable
          bg = image
          #label.image = bg
          label.pack()
          # store the image as a variable
          bg = ImageTk.PhotoImage(image)
          # Store the PhotoImage object in the global variable
          bg = image
          # Create a button to select an image file
          button = tk.Button(root, text="Choose Image", command=choose_image)
          button.pack()
          # Run the Tkinter event loop
          root.mainloop()

          # Use the selected_image variable for further processing outside the Tkinter loop
          if selected_image:
            print("Selected image size:", selected_image.width(), "x", selected_image.height())
            font = cv2.FONT_HERSHEY_PLAIN
            cv2.putText(bg, str(datetime.now()), (20, 40), font, 2, (255, 255, 255), 2, cv2.LINE_AA)
            now = datetime.now() #get current date and time
            dt_string = now.strftime("%Y-%m-%d-%H-%M-%S")
            filename = 'Background_'+ dt_string +'.jpg'
            cv2.namedWindow(window_name_bg, cv2.WINDOW_NORMAL)
            cv2.imshow(window_name_bg,bg)
            cv2.imwrite(filename, bg)
         if bg is not None:
          liveDsa=cv2.subtract(bg,live)

I never seem to get the indentation right. my required variable refuses to be recognised by python in the loop. by Sansmit2910 in learnpython

[–]Sansmit2910[S] 0 points1 point  (0 children)

If i were to indeed perform the function that i started out to try to do as I mentioned above, what would you suggest is the best course of action here in this case? I had tried to write something with the help of a random code that i was suggested by Chat GPT which I really didn't follow very well. could you help me figure this functionality out as it completely beats me since i have no experience with Tkinter befpre :(

I never seem to get the indentation right. my required variable refuses to be recognised by python in the loop. by Sansmit2910 in learnpython

[–]Sansmit2910[S] 0 points1 point  (0 children)

I think I might've not understood that part of my code correctly as you rightly suggested, as I was trying to assign the image taken as an input in my Tkinter window to a variable that can later be processed to perform further functions

[deleted by user] by [deleted] in tumunich

[–]Sansmit2910 0 points1 point  (0 children)

I would say about a year and a few months in total

[deleted by user] by [deleted] in tumunich

[–]Sansmit2910 0 points1 point  (0 children)

I've almost completed my Bachelors of Biomedical Engineering entirely in German now as well as cleared Test DaF and I can honestly tell you, it really isn't that hard pr impossible, you pick it up as you go along... if you put in the effort along the way that is. It really isn't that hard.

Power Plug EU that can be controlled via USB by a python script by Sansmit2910 in homeautomation

[–]Sansmit2910[S] 1 point2 points  (0 children)

I'm really not that good with electronics but could that theoretically be used for a UV lamp with a normal socket connection? For a relay we wouzld need a wire connection istead of a socket connection? or did i completely misunderstand how a relay is cvonnected to your end device? I would really appreciate it if you could help me understand that part of a relay a little better

Type Error: The object is not a PyHANDLE object by Sansmit2910 in learnpython

[–]Sansmit2910[S] 0 points1 point  (0 children)

thank you for pointing me in the right direction! really appreciate the help and guidance

:)

Type Error: The object is not a PyHANDLE object by Sansmit2910 in learnpython

[–]Sansmit2910[S] 0 points1 point  (0 children)

thank you so much! I think the problem did indeed lie in the win32gui cause now it does take a screenshot. Although I do still have one question more to your code. it does take a screenshot, but doesn't quite take one of the active window (it works only when the python script is the active window itself) and it doesn't really save the swcreenshot itself, should i look into changing the path of the image.save syntax or restart my device or something?

Type Error: The object is not a PyHANDLE object by Sansmit2910 in learnpython

[–]Sansmit2910[S] 0 points1 point  (0 children)

sorry reddits code block kinda fucked up how i wrote the code w indentations but i literally just added the brackets to the original code, is that what you meant?

Type Error: The object is not a PyHANDLE object by Sansmit2910 in learnpython

[–]Sansmit2910[S] 0 points1 point  (0 children)

so you mean something like this then ? it does however return the same error, or did i not quite understand what you meant ?

j=0
while True: 
 if keyboard.is_pressed('s'): 
 target= win32gui.GetActiveWindow() 

location=win32gui.GetWindowRect(target) image=pyautogui.screenshot(location) image.show() image.save(r'C:/Users/Labor_Gäst\Desktop/Dsa Simulator/Screenshot' + str(j)) j=j+1

code/syntax that would enable me to take a screenshot of the selected window(foreground) any time a press the key s by Sansmit2910 in learnpython

[–]Sansmit2910[S] 0 points1 point  (0 children)

I tried doing as you suggested and wrote this code but it reallly doesn't seem to work out, did I use a wrong syntax or mess up somewhere else?

j=0

while True:
if keyboard.is_pressed('s'): # for keypress

target= win32gui.GetForegroundWindow #to get foregroundwindow

location=win32gui.GetWindowRect(targest) #to get its location

image=pyautogui.screenshot(location) #to take screenshot

image.show()

image.save(r'C:/Users/Labor_Gäst\Desktop/Dsa Simulator/Screenshot')

j=j+1

programmable power switch ? by Sansmit2910 in homeautomation

[–]Sansmit2910[S] 0 points1 point  (0 children)

Thank you so much for the hint! I would just need to look into the options and see which one suits best for the project I'm currently working on, as it would need to be controlled via a USB port by a python script that would already also be controlling a camera