How can we calculate length/width of an object in image?
Basically , i am trying to calculate length/width of an object in image ,with cartesian graph paper in background.I have found bounding box of object.But how can i read cartesian coordinate (x,y) in background?
import cv2 as cv
import numpy as np
img = cv.imread('E:\PY_CV\graph1.jpg')
img=cv.resize(img,(400,400))
edges = cv.Canny(img,100,200)
####################################
# Convert BGR to HSV https://www.lifewire.com/what-is-hsv-in-design-1078068
hsv_g = cv.cvtColor(img, cv.COLOR_BGR2HSV)
# define range of green color in HSV
lower_green = np.array([30,60,60])
upper_green = np.array([100,255,255])
# Threshold the HSV image to get only yellow colors
mask_g = cv.inRange(hsv_g, lower_green, upper_green)
non_zero_green=cv.countNonZero(mask_g)
points=cv.findNonZero(mask_g)
x,y,w,h=cv.boundingRect(points)
cv.rectangle(img,(x,y),(x+w,y+h),(255,255,255),2)
cropped_green=img[y:y+h,x:x+w]
print(x)
print(y)
print(w)
print(h)
cv.imshow('mask-green',mask_g)
cv.imshow('cropped_green',cropped_green)
cv.imshow('bounding_box',img)
cv.waitKey(0)
cv.destroyAllWindows()
I cannot see any image in your post
Updated image link
please put your image here, not on dropbox.
My image is 2.7 MB
there is a password. Reduce image size : resize or compress image and insert in your post (limit is 1MB). and post your code
image uploaded
please give the code you tried so far
code added
Calibrate your camera and use a camera with a fixed distance and orientation relative to object (leaf)
You should use a scanner it would be easyer
If you just want to calculate real world dimensions of leaf. You can you use this approach similar to @LBerger