New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable GAPI VASOT in Python #24576
Enable GAPI VASOT in Python #24576
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,28 +24,28 @@ namespace ot { | |
* | ||
* Tracking status twin for vas::ot::TrackingStatus | ||
*/ | ||
enum class TrackingStatus: int32_t | ||
enum TrackingStatus | ||
{ | ||
NEW = 0, /**< The object is newly added. */ | ||
TRACKED, /**< The object is being tracked. */ | ||
LOST /**< The object gets lost now. The object can be tracked again | ||
by specifying detected object manually. */ | ||
}; | ||
|
||
struct ObjectTrackerParams | ||
struct GAPI_EXPORTS_W_SIMPLE ObjectTrackerParams | ||
{ | ||
/** | ||
* Maximum number of trackable objects in a frame. | ||
* Valid range: 1 <= max_num_objects. Or it can be -1 if there is no limitation | ||
* of maximum number in X86. KMB/TBH has limitation up to 1024. | ||
* Default value is -1 which means there is no limitation in X86. KMB/TBH is -1 means 200. | ||
*/ | ||
int32_t max_num_objects = -1; | ||
GAPI_PROP_RW int32_t max_num_objects = -1; | ||
|
||
/** | ||
* Input color format. Supports 0(BGR), 1(NV12), 2(BGRX) and 4(I420) | ||
*/ | ||
int32_t input_image_format = 0; | ||
GAPI_PROP_RW int32_t input_image_format = 0; | ||
|
||
/** | ||
* Specifies whether tracker to use detection class for keeping id of an object. | ||
|
@@ -60,7 +60,7 @@ struct ObjectTrackerParams | |
* @n | ||
* Default value is true. | ||
*/ | ||
bool tracking_per_class = true; | ||
GAPI_PROP_RW bool tracking_per_class = true; | ||
|
||
bool operator==(const ObjectTrackerParams& other) const | ||
{ | ||
|
@@ -70,7 +70,7 @@ struct ObjectTrackerParams | |
} | ||
}; | ||
|
||
using GTrackedInfo = std::tuple<cv::GArray<cv::Rect>, cv::GArray<int32_t>, cv::GArray<uint64_t>, cv::GArray<TrackingStatus>>; | ||
using GTrackedInfo = std::tuple<cv::GArray<cv::Rect>, cv::GArray<int32_t>, cv::GArray<uint64_t>, cv::GArray<int>>; | ||
|
||
G_API_OP(GTrackFromMat, <GTrackedInfo(cv::GMat, cv::GArray<cv::Rect>, cv::GArray<int32_t>, float)>, "com.intel.track_from_mat") | ||
{ | ||
|
@@ -107,23 +107,26 @@ G_API_OP(GTrackFromFrame, <GTrackedInfo(cv::GFrame, cv::GArray<cv::Rect>, cv::GA | |
* @param delta Frame_delta_t Delta time between two consecutive tracking in seconds. | ||
* The valid range is [0.005 ~ 0.5]. | ||
* @return Tracking results of target objects. | ||
* cv::GArray<cv::Rect> Array of rectangles for tracked objects. | ||
* cv::GArray<int32_t> Array of detected objects labels. | ||
* cv::GArray<uint64_t> Array of tracking IDs for objects. | ||
* Numbering sequence starts from 1. | ||
* The value 0 means the tracking ID of this object has | ||
* not been assigned. | ||
* cv::GArray<TrackingStatus> Array of tracking statuses for objects. | ||
* cv::GArray<cv::Rect> Array of rectangles for tracked objects. | ||
* cv::GArray<int32_t> Array of detected objects labels. | ||
* cv::GArray<uint64_t> Array of tracking IDs for objects. | ||
* Numbering sequence starts from 1. | ||
* The value 0 means the tracking ID of this object has | ||
* not been assigned. | ||
* cv::GArray<int> Array of tracking statuses for objects. | ||
*/ | ||
GAPI_EXPORTS std::tuple<cv::GArray<cv::Rect>, | ||
cv::GArray<int32_t>, | ||
cv::GArray<uint64_t>, | ||
cv::GArray<TrackingStatus>> track(const cv::GMat& mat, | ||
const cv::GArray<cv::Rect>& detected_rects, | ||
const cv::GArray<int>& detected_class_labels, | ||
float delta); | ||
GAPI_EXPORTS_W std::tuple<cv::GArray<cv::Rect>, | ||
cv::GArray<int>, | ||
cv::GArray<uint64_t>, | ||
cv::GArray<int>> | ||
track(const cv::GMat& mat, | ||
const cv::GArray<cv::Rect>& detected_rects, | ||
const cv::GArray<int>& detected_class_labels, | ||
float delta); | ||
|
||
|
||
/** | ||
@overload | ||
* @brief Tracks objects with video frames. Overload of track(...) for frame as GFrame. | ||
* | ||
* @param frame Input frame. | ||
|
@@ -139,15 +142,16 @@ GAPI_EXPORTS std::tuple<cv::GArray<cv::Rect>, | |
* Numbering sequence starts from 1. | ||
* The value 0 means the tracking ID of this object has | ||
* not been assigned. | ||
* cv::GArray<TrackingStatus> Array of tracking statuses for objects. | ||
* cv::GArray<int> Array of tracking statuses for objects. | ||
*/ | ||
GAPI_EXPORTS std::tuple<cv::GArray<cv::Rect>, | ||
cv::GArray<int32_t>, | ||
cv::GArray<uint64_t>, | ||
cv::GArray<TrackingStatus>> track(const cv::GFrame& frame, | ||
const cv::GArray<cv::Rect>& detected_rects, | ||
const cv::GArray<int>& detected_class_labels, | ||
float delta); | ||
GAPI_EXPORTS_W std::tuple<cv::GArray<cv::Rect>, | ||
cv::GArray<int>, | ||
cv::GArray<uint64_t>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually doubt if we even need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what inner VAS function operates with. I don't think that |
||
cv::GArray<int>> | ||
track(const cv::GFrame& frame, | ||
const cv::GArray<cv::Rect>& detected_rects, | ||
const cv::GArray<int>& detected_class_labels, | ||
float delta); | ||
} // namespace ot | ||
} // namespace gapi | ||
} // namespace cv | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,14 @@ class Int(): | |
def __new__(self): | ||
return cv.GOpaqueT(cv.gapi.CV_INT) | ||
|
||
class Int64(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see any usage of both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of the return types of OT I guess. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
def __new__(self): | ||
return cv.GOpaqueT(cv.gapi.CV_INT64) | ||
|
||
class UInt64(): | ||
def __new__(self): | ||
return cv.GOpaqueT(cv.gapi.CV_UINT64) | ||
|
||
class Double(): | ||
def __new__(self): | ||
return cv.GOpaqueT(cv.gapi.CV_DOUBLE) | ||
|
@@ -111,6 +119,14 @@ class Int(): | |
def __new__(self): | ||
return cv.GArrayT(cv.gapi.CV_INT) | ||
|
||
class Int64(): | ||
def __new__(self): | ||
return cv.GArrayT(cv.gapi.CV_INT64) | ||
|
||
class UInt64(): | ||
def __new__(self): | ||
return cv.GArrayT(cv.gapi.CV_UINT64) | ||
|
||
class Double(): | ||
def __new__(self): | ||
return cv.GArrayT(cv.gapi.CV_DOUBLE) | ||
|
@@ -170,6 +186,8 @@ def op(op_id, in_types, out_types): | |
garray_types= { | ||
cv.GArray.Bool: cv.gapi.CV_BOOL, | ||
cv.GArray.Int: cv.gapi.CV_INT, | ||
cv.GArray.Int64: cv.gapi.CV_INT64, | ||
cv.GArray.UInt64: cv.gapi.CV_UINT64, | ||
cv.GArray.Double: cv.gapi.CV_DOUBLE, | ||
cv.GArray.Float: cv.gapi.CV_FLOAT, | ||
cv.GArray.String: cv.gapi.CV_STRING, | ||
|
@@ -190,6 +208,8 @@ def op(op_id, in_types, out_types): | |
cv.GOpaque.Rect: cv.gapi.CV_RECT, | ||
cv.GOpaque.Bool: cv.gapi.CV_BOOL, | ||
cv.GOpaque.Int: cv.gapi.CV_INT, | ||
cv.GOpaque.Int64: cv.gapi.CV_INT64, | ||
cv.GOpaque.UInt64: cv.gapi.CV_UINT64, | ||
cv.GOpaque.Double: cv.gapi.CV_DOUBLE, | ||
cv.GOpaque.Float: cv.gapi.CV_FLOAT, | ||
cv.GOpaque.String: cv.gapi.CV_STRING, | ||
|
@@ -205,6 +225,8 @@ def op(op_id, in_types, out_types): | |
type2str = { | ||
cv.gapi.CV_BOOL: 'cv.gapi.CV_BOOL' , | ||
cv.gapi.CV_INT: 'cv.gapi.CV_INT' , | ||
cv.gapi.CV_INT64: 'cv.gapi.CV_INT64' , | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where do we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was exposed in the bindings already. I decided to just add it here also. |
||
cv.gapi.CV_UINT64: 'cv.gapi.CV_UINT64' , | ||
cv.gapi.CV_DOUBLE: 'cv.gapi.CV_DOUBLE' , | ||
cv.gapi.CV_FLOAT: 'cv.gapi.CV_FLOAT' , | ||
cv.gapi.CV_STRING: 'cv.gapi.CV_STRING' , | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python | ||
|
||
import numpy as np | ||
import cv2 as cv | ||
import os | ||
import sys | ||
import unittest | ||
|
||
from tests_common import NewOpenCVTests | ||
|
||
|
||
try: | ||
|
||
if sys.version_info[:2] < (3, 0): | ||
raise unittest.SkipTest('Python 2.x is not supported') | ||
|
||
class gapi_ot_test(NewOpenCVTests): | ||
|
||
def test_ot_smoke(self): | ||
# Input | ||
img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')]) | ||
in_image = cv.cvtColor(cv.imread(img_path), cv.COLOR_RGB2BGR) | ||
in_rects = [ (138, 89, 71, 64) ] | ||
in_rects_cls = [ 0 ] | ||
|
||
# G-API | ||
g_in = cv.GMat() | ||
g_in_rects = cv.GArray.Rect() | ||
g_in_rects_cls = cv.GArray.Int() | ||
delta = 0.5 | ||
|
||
g_out_rects, g_out_rects_cls, g_track_ids, g_track_sts = \ | ||
cv.gapi.ot.track(g_in, g_in_rects, g_in_rects_cls, delta) | ||
|
||
|
||
comp = cv.GComputation(cv.GIn(g_in, g_in_rects, g_in_rects_cls), | ||
cv.GOut(g_out_rects, g_out_rects_cls, | ||
g_track_ids, g_track_sts)) | ||
|
||
__, __, __, sts = comp.apply(cv.gin(in_image, in_rects, in_rects_cls), | ||
args=cv.gapi.compile_args(cv.gapi.ot.cpu.kernels())) | ||
|
||
self.assertEqual(cv.gapi.ot.NEW, sts[0]) | ||
|
||
except unittest.SkipTest as e: | ||
|
||
message = str(e) | ||
|
||
class TestSkip(unittest.TestCase): | ||
def setUp(self): | ||
self.skipTest('Skip tests: ' + message) | ||
|
||
def test_skip(): | ||
pass | ||
|
||
|
||
if __name__ == '__main__': | ||
NewOpenCVTests.bootstrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looked fine, why we decided to change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be automatically convertable to int