Detection😆
This class provide the function for obtaining the detected images.
Link to the class
Attributes😆
Attributes | Type | Description |
---|---|---|
categories |
dict | Count all the detected objects. |
img |
numpy.array | Origin image get from the camera. |
size |
tuple | Size of image. |
frame |
numpy.array | Image with bounding boxes and categories. |
Constructor😆
__init__(self, google_kit_json_path: str, categories: list, size: tuple = (640, 480), max_results: int = 10, camera=0)
😆
Create an instance from Detection class.
- Args
google_kit_json_path
: Path for the Google API JSON file. To get the API file, please refer to this page .categories
: Categories to be detected. All supported types can be found in here.size
: Size of the images and frames.max_results
: Maximum results for the response. It won't absolutely contain the wanted objects listed incategories
. The categories being selected is controlled by the Google Server.camera
: Camera to be used. The backend function was usingcv2.VideoCapture
in OpenCV. Please refer to this link for all the valid input.
Method😆
start(self)
😆
Start the object detection and open the camera.
end(self)
😆
End the detection and release the camera.
Logic😆
Below is a flow chart that shows the logic behind the class.
Example😆
import gcdetection
import cv2
# Create detected class and start the detection
detection_class = gcdetection.Detection(google_kit_json_path="/path/to/json/file",
categories=["Person", "Book"],
size=(640, 480),
max_results=10,
camera=0)
detection_class.start()
# Show the original images and detected images
while True:
# Obtain images
ori_img = detection_class.img
detected_img = detection_class.frame
# Wait for key
key = cv2.waitKey(30) & 0xff
if key == 27: # ESC
break
# Show the images
if ori_img is not None:
cv2.imshow("Original image", ori_img)
if detected_img is not None:
cv2.imshow("Detected image", detected_img)
# Release the resources
detection_class.end()
cv2.destroyAllWindows()
For more example, please visit the example repository.