1

I want to drag and drop an image file to cv2.imshow() window and fetch the filename path.

There is no event named drag and drop and I need some help.

In my project I remove the background image and I want to change the background with any image.

I did the hard part (removing the background) but I don't know how to handle drag/drop files event in OpenCV python.

def mouse_events(event, x,y, flags,param):
    if event == cv2.EVENT_??: # ?? drag/drop a file event
        # return the filename

while True:
   ...
   cv2.setMouseCallback(windowName, mouse_events)
   ...

handle drag/drop event

Thanks in advance

AcK
  • 2,063
  • 2
  • 20
  • 27
Peyman Majidi
  • 1,777
  • 2
  • 18
  • 31
  • 3
    you **can't**. OpenCV is a library for computer vision, with some convenience for displaying images. you want a **library for GUI programming**. – Christoph Rackwitz Sep 20 '21 at 11:33
  • 2
    as you found out, there is no such event built into the imshow() code. there is also no clipboard handling of any kind , so it simply wont work. maye you can fire up the stdio input() function on the console , and drop your file there, not on the gui window – berak Sep 20 '21 at 11:35

1 Answers1

1

As @Christoph Rackwitz pointed out, you cannot do this using OpenCV alone. You have to use some GUI programming interface such as PyQt5 or pyside.

This question demonstrates drag and drop functionality with file explorer.

Have a look at this tutorial for integrating with OpenCV

Abhi25t
  • 3,703
  • 3
  • 19
  • 32