Detecting Clicks on Image [7] | OpenCV Python Tutorials for Beginners

preview_player
Показать описание
In this video, we will learn how to detect clicks on an image. Using these x and y coordinates detected we will warp an image.

🚀🚀 My Urdu/Hindi AI YouTube Channel 🚀🚀

Code & Complete Course:

Premium Courses:
✔️ Computer Vision Game Development Course:
✔️ Computer Vision with Arduino Course:
✔️ Advanced Drone Programming Course:
✔️ Learn to Build Computer Vision Mobile Apps:
✔️ Jetson Nano Premium Course:

⚙️⚙️⚙️—-My Gear — ⚙️⚙️⚙️

Follow Me:

#ComputerVision
#OpenCV
#CVZone
Рекомендации по теме
Комментарии
Автор

This works great! However, I am having trouble identifying where "break" needs to go in the loop so I can call cv2.destroyAllWindows at the end. Right now I have to manually end the code.

ZachFerris-nx
Автор

sir is there a workaroundt that instead of refrencing the location of image. when we launch the appliation it give a cross hair and we can do this (set cordinates) in the live (current screen)

usmankhawar
Автор

Hey can you show how to crop object from image if object's shape(like book) is not square and the object is diamond .So how can we crop diamond from image using more circles(6 circles).

yuvrajsinhchauhan
Автор

Mr. Murtaza, what is it used for flags/param when defining events?

pravuchaudhary
Автор

cv2.circle(img, ([pts1[x][0], pts1[x][1]]), 15, (0, 255, 0), cv2.FILLED)



cv2.error: OpenCV(4.5.2) :-1: error: (-5:Bad argument) in function 'circle'
> Overload resolution failed:
> - Can't parse 'center'. Sequence item with index 0 has a wrong type
> - Can't parse 'center'. Sequence item with index 0 has a wrong type


i am getting this error

samarthas
Автор

hello sir why you changed the delay from cv2.waitKey(0) to cv2.waitKey(1)

i_am_slayer_
Автор

you forget to tell about "global counter". error occurred... but now i fixed it

yashabhgoyal
Автор

How just can i return x, y of one clicked position to compare of points from

modykhalil
Автор

Code(import cv2
import numpy as np

# Initialize variables
circles = np.zeros((4, 2), int)
counter = 0

# Define the mouse callback function
def mousePointer(event, x, y, flags, param):
global counter
if event == cv2.EVENT_LBUTTONDOWN:
print(x, y)
circles[counter] = x, y
counter += 1
print(circles)

# Read the image
img = cv2.imread("image/me.jpg")
width, height = 250, 350

# Check if the image is loaded successfully
if img is None:
print("nothing as a image")
else:
cv2.imshow("original img", img)
img", mousePointer)

while True:
for x in range(0, 4):
cv2.circle(img, (int(circles[x][0]), int(circles[x][1])), 5, (0, 0, 255), cv2.FILLED)

if counter == 4:
pts1 = np.float32(circles)
pts2 = np.float32([[0, 0], [width, 0], [0, height], [width, height]])
matrix = cv2.getPerspectiveTransform(pts1, pts2)
imgOutput = cv2.warpPerspective(img, matrix, (width, height))
cv2.imshow("imgOutput", imgOutput)

cv2.imshow("original img", img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

cv2.destroyAllWindows()

)

mdmokshedurrahman
Автор

Hello, I am getting the following error: Traceback (most recent call last):
File "C:/Users/DOS/PycharmProjects/myproject1/WarpPerspective.py", line 8, in <module>
matrix = cv2.getPerspectiveTransform(pts1, pts2)
cv2.error: OpenCV(4.6.0) error: (-215:Assertion failed) src.checkVector(2, CV_32F) == 4 && dst.checkVector(2, CV_32F) == 4 in function 'cv::getPerspectiveTransform'

bulletforcekurdish
Автор

You can even crop the image with 3 points

aneesjaveed
Автор

I keep having errors with cv2 and sometimes it works sometimes it doesn't, I don't get it why

evagok
Автор

how to remove 1 point?, specifically the last point

nachetons
Автор

suddenly the basic code also is not working...it is giving the error....cv2.error: OpenCV(4.5.3) error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
PLEASE TELL ME HOW DO I FIX THIS

ishankrajpal
Автор

I tried to fix it but it is actually working but its weird

evagok
Автор

bro change ur screen in to bright if u can

dawitworkenh
Автор

How to remove points from the output image? The green points are cropped...

cezaryczarkowsky
Автор

can anyone share the code? I am not getting it, how with waitkey(1) I will be able to hold the picture for that long, and my if count is also not working.

rajshekharghosh
Автор

v2.circle(img, (pts1[x][0], pts1[x][1]), 15, (0, 255, 0), cv2.FİLLED)
AttributeError: module 'cv2.cv2' has no attribute 'FİLLED'
ı got this error what should ı do?

mertolojis
Автор

How to click on an image automatically?

redhwanalgabri