Skip to content

Commit

Permalink
add to initTracker colorSpace option to let use other colors channels
Browse files Browse the repository at this point in the history
  • Loading branch information
kalwalt committed Nov 10, 2023
1 parent ce4fe4d commit fe46f86
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions WebARKit/WebARKitManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ bool WebARKitManager::initialiseBase(webarkit::TRACKER_TYPE trackerType, int fra
return true;
}

bool WebARKitManager::initTracker(uchar* refData, size_t refCols, size_t refRows) {
bool WebARKitManager::initTracker(uchar* refData, size_t refCols, size_t refRows, ColorSpace colorSpace) {
WEBARKIT_LOGd("WebARKitManager::initTracker(...)\n");
if (!refData || refCols <= 0 || refRows <= 0) {
WEBARKIT_LOGe("Error initialising tracker.\n");
return false;
}
m_tracker->initTracker(refData, refCols, refRows);
m_tracker->initTracker(refData, refCols, refRows, colorSpace);
state = WAITING_FOR_VIDEO;
WEBARKIT_LOGd("WebARKitManager::initTracker() done.\n");
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,19 @@ class WebARKitTracker::WebARKitTrackerImpl {
webarkit::cameraProjectionMatrix(camData, 0.1, 1000.0, frameWidth, frameHeight, m_cameraProjectionMatrix);
}

void initTracker(uchar* refData, size_t refCols, size_t refRows) {
void initTracker(uchar* refData, size_t refCols, size_t refRows, ColorSpace colorSpace) {
WEBARKIT_LOGi("Init Tracker!\n");

cv::Mat refGray(refRows, refCols, CV_8UC1, refData);
cv::Mat refGray;
if (colorSpace == ColorSpace::RGBA) {
cv::Mat colorFrame(refRows, refCols, CV_8UC4, refData);
refGray.create(refRows, refCols, CV_8UC1);
cv::cvtColor(colorFrame, refGray, cv::COLOR_RGBA2GRAY);
} else if (colorSpace == ColorSpace::GRAY) {
refGray = cv::Mat(refRows, refCols, CV_8UC1, refData);
}

//cv::Mat refGray(refRows, refCols, CV_8UC1, refData);

cv::Mat trackerFeatureMask = createTrackerFeatureMask(refGray);

Expand Down Expand Up @@ -420,8 +429,8 @@ void WebARKitTracker::initialize(webarkit::TRACKER_TYPE trackerType, int frameWi
_trackerImpl->initialize(trackerType, frameWidth, frameHeight);
}

void WebARKitTracker::initTracker(uchar* refData, size_t refCols, size_t refRows) {
_trackerImpl->initTracker(refData, refCols, refRows);
void WebARKitTracker::initTracker(uchar* refData, size_t refCols, size_t refRows, ColorSpace colorSpace) {
_trackerImpl->initTracker(refData, refCols, refRows, colorSpace);
}

void WebARKitTracker::processFrameData(uchar* frameData, size_t frameCols, size_t frameRows, ColorSpace colorSpace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class WebARKitTracker {

void initialize(webarkit::TRACKER_TYPE trackerType, int frameWidth, int frameHeight);

void initTracker(uchar* refData, size_t refCols, size_t refRows);
void initTracker(uchar* refData, size_t refCols, size_t refRows, ColorSpace colorSpace);

void processFrameData(uchar* frameData, size_t frameCols, size_t frameRows, ColorSpace colorSpace);

Expand Down
2 changes: 1 addition & 1 deletion WebARKit/include/WebARKitManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class WebARKitManager {
*/
std::shared_ptr<webarkit::WebARKitTracker> getTracker() { return m_tracker; };

bool initTracker(uchar* refData, size_t refCols, size_t refRows);
bool initTracker(uchar* refData, size_t refCols, size_t refRows, ColorSpace colorSpace);

bool update();

Expand Down
2 changes: 1 addition & 1 deletion tests/webarkit_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ TEST(WebARKitTest, InitTrackerTest) {
EXPECT_EQ(image.cols, 1637);
EXPECT_EQ(image.rows, 2048);
// Check if initTracker returns sucessfully
EXPECT_TRUE(manager.initTracker(data, width, height));
EXPECT_TRUE(manager.initTracker(data, width, height, webarkit::ColorSpace::RGBA));
}

// Check WebARKit version
Expand Down

0 comments on commit fe46f86

Please sign in to comment.