Skip to content

G-API: Refine Semantic Segmentation Demo#23766

Merged
asmorkalov merged 13 commits intoopencv:4.xfrom
TolyaTalamanov:at/segmentation-demo-desync
Jun 13, 2023
Merged

G-API: Refine Semantic Segmentation Demo#23766
asmorkalov merged 13 commits intoopencv:4.xfrom
TolyaTalamanov:at/segmentation-demo-desync

Conversation

@TolyaTalamanov
Copy link
Copy Markdown
Contributor

Overview

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

explicit GCaptureSource(int id) : cap(id) { prep(); }
explicit GCaptureSource(const std::string &path) : cap(path) { prep(); }
using Properties = std::unordered_map<int, double>;
explicit GCaptureSource(int id, const Properties &properties = {})
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I wish it was separate method set but properties must be set before the first frame is read (prep())

}

static void drawResults(cv::Mat &img, const cv::Mat &color_mask) {
img = img / 2 + color_mask / 2;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not so efficient due reallocations but it doesn't impact performance

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should thing how we can make stuff like this in graph -- where a desynchronized path meets the synchronized one, and results are accumulated inside as we do now manually..

Good idea for future versions

cv::Mat mask_img;
classesToColors(classes, mask_img);
cv::resize(mask_img, out, in.size());
cv::resize(mask_img, out, in.size(), 0, 0, cv::INTER_NEAREST);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INTER_NEAREST is better when it comes to resize color mask

source = std::make_shared<cv::gapi::wip::GCaptureSource>(
std::stoi(input),
cv::gapi::wip::GCaptureSource::Properties {
{cv::CAP_PROP_FRAME_WIDTH, 1280},
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded so far, not sure if it should be cmd option

@TolyaTalamanov TolyaTalamanov force-pushed the at/segmentation-demo-desync branch from a19aa1c to cf2505c Compare June 9, 2023 07:36
@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@dmatveev Could you have a look, please?

explicit GCaptureSource(int id) : cap(id) { prep(); }
explicit GCaptureSource(const std::string &path) : cap(path) { prep(); }
using Properties = std::unordered_map<int, double>;
explicit GCaptureSource(int id, const Properties &properties = {})
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exposed to python so far...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exposed now

{0, 0, 0}, {0, 0, 128}, {0, 128, 0}, {0, 128, 128}, {128, 0, 0}, {128, 0, 128}, {128, 128, 0},
{128, 128, 128}, {0, 0, 64}, {0, 0, 192}, {0, 128, 64}, {0, 128, 192}, {128, 0, 64}, {128, 0, 192},
{128, 128, 64}, {128, 128, 192}, {0, 64, 0}, {0, 64, 128}, {0, 192, 0}, {0, 192, 128}, {128, 64, 0}
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this change? Previously it was just one line per class, easy to edit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, I'll keep old alignment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}

static void drawResults(cv::Mat &img, const cv::Mat &color_mask) {
img = img / 2 + color_mask / 2;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should thing how we can make stuff like this in graph -- where a desynchronized path meets the synchronized one, and results are accumulated inside as we do now manually..

Good idea for future versions

@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@dmatveev @asmorkalov Hi folks, can we merge this?

{cv::CAP_PROP_FRAME_HEIGHT, 720},
{cv::CAP_PROP_BUFFERSIZE, 1},
{cv::CAP_PROP_AUTOFOCUS, true},
{cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('M', 'J', 'P', 'G')}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works not with all cameras. I propose to add note on required camera parameters to help message and the source file header.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'd rather remove it then

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@asmorkalov asmorkalov added this to the 4.8.0 milestone Jun 13, 2023
@asmorkalov asmorkalov merged commit a371bda into opencv:4.x Jun 13, 2023
@asmorkalov asmorkalov mentioned this pull request Jul 12, 2023
thewoz pushed a commit to thewoz/opencv that referenced this pull request Jan 4, 2024
…emo-desync

G-API: Refine Semantic Segmentation Demo opencv#23766

### Overview
* Supported demo working with camera id (e.g `--input=0`)
* Supported 3d output segmentation models (e.g `deeplabv3`)
* Supported `desync` execution
* Supported higher camera resolution
* Changed the color map to pascal voc (https://cloud.githubusercontent.com/assets/4503207/17803328/1006ca80-65f6-11e6-9ff6-36b7ef5b9ac6.png)

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [ ] I agree to contribute to the project under Apache 2 License.
- [ ] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
thewoz pushed a commit to thewoz/opencv that referenced this pull request May 29, 2024
…emo-desync

G-API: Refine Semantic Segmentation Demo opencv#23766

### Overview
* Supported demo working with camera id (e.g `--input=0`)
* Supported 3d output segmentation models (e.g `deeplabv3`)
* Supported `desync` execution
* Supported higher camera resolution
* Changed the color map to pascal voc (https://cloud.githubusercontent.com/assets/4503207/17803328/1006ca80-65f6-11e6-9ff6-36b7ef5b9ac6.png)

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [ ] I agree to contribute to the project under Apache 2 License.
- [ ] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants