Background details
I have a model that classifies a hand gesture into one of the 26 classes. The accuracy of my model is 99%.
Now I want to take image from a web cam and make real time predctions. for this purpose, I want to create a region on web cam where I can place my hand gesture and consider only that region as input image, this way I can eliminate the background noise that affects my model real time accuracy.
current source code :
import cv2
videoCaptureObject = cv2.VideoCapture(0)
result = True
while(result):
ret,frame = videoCaptureObject.read()
#here I want to display a square region on web cam and capture only that
#sqaure regin
cv2.imshow("test", frame)
k = cv2.waitKey(1)
if k%256 == 27:
print("Escape hit, closing...")
break
elif k%256 == 32:
cv2.imwrite("input_image.jpg",frame)
img = cv2.imread("input_image.jpg")
gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray_img = cv2.resize(gray_image, (28, 28)).reshape(1,28,28,1)
#ax[2,1].imshow(gray_img.reshape(28, 28) , cmap = "gray")
cv2.imshow("image", gray_img.reshape(28, 28))
y_pred = model.predict_classes(gray_img)
print("predicted alphabet = ", y_pred)
#text_to_audio(myDict.get(y_pred[0]))
result = False
videoCaptureObject.release()
cv2.destroyAllWindows()
Question : Using OpenCv how can I create a region on web cam and capture image of only that region instead of the entire frame.