Skip to content
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

Update vibe-background-sequential.cpp #206

Merged
merged 1 commit into from
Sep 14, 2021

Conversation

vc-zju
Copy link
Contributor

@vc-zju vc-zju commented Sep 14, 2021

solve the logical error between initialization and segmentation in vibe
Describe the bug
When we init the historybuffer[], the elements in it are like BBBBBBBBBBBBBBBBBBGGG…RRR…(suppose that the image imported by cv is a RGB image not a BGR). But when we use historybuffer[], we see it as RGBRGBRGB…… which confuses me much.

To Reproduce
Just see the code : ), I will offer it.
when we init it

for (int index = (3 * width) * height - 1; index >= 0; --index) {
          uint8_t value = image_data[index];
          for (int x = 0; x < model->numberOfSamples - NUMBER_OF_HISTORY_IMAGES; ++x) {
            int value_plus_noise = value + rand() % 20 - 10;
            if (value_plus_noise < 0) { value_plus_noise = 0; }
            if (value_plus_noise > 255) { value_plus_noise = 255; }
            model->historyBuffer[index * (model->numberOfSamples - NUMBER_OF_HISTORY_IMAGES) + x] = value_plus_noise;
          }
}

when we use it

for (int i = numberOfTests; i > 0; --i, indexHistoryBuffer += 3) {
              if (
                distance_is_close_8u_C3R(
                  image_data[(3 * index)], image_data[(3 * index) + 1], image_data[(3 * index) + 2],
                  historyBuffer[indexHistoryBuffer], historyBuffer[indexHistoryBuffer + 1], historyBuffer[indexHistoryBuffer + 2],
                  matchingThreshold
                )
                )
                --segmentation_map[index];

Expected behavior
Consistency should be maintained in logic.
Init it just like this(may have some errors)

    auto plus_noise = [](uint8_t value) -> int {int value_plus_noise = value + rand() % 20 - 10;
            if (value_plus_noise < 0) { value_plus_noise = 0; }
            if (value_plus_noise > 255) { value_plus_noise = 255; }
            return value_plus_noise;};
    for (int index = (3 * width) * height - 1; index >= 0; index -= 3) {
          uint8_t value_1 = image_data[index];
          uint8_t value_2 = image_data[index - 1];
          uint8_t value_3 = image_data[index - 2];
          for (int x = 0; x < model->numberOfSamples - NUMBER_OF_HISTORY_IMAGES; ++x) {
            int value_plus_noise1 = plus_noise(value_1);
            int value_plus_noise2 = plus_noise(value_2);
            int value_plus_noise3 = plus_noise(value_3);
            model->historyBuffer[(index - 2) * (model->numberOfSamples - NUMBER_OF_HISTORY_IMAGES) + x * 3 + 2] = value_plus_noise1;
            model->historyBuffer[(index - 2) * (model->numberOfSamples - NUMBER_OF_HISTORY_IMAGES) + x * 3 + 1] = value_plus_noise2;
            model->historyBuffer[(index - 2) * (model->numberOfSamples - NUMBER_OF_HISTORY_IMAGES) + x * 3] = value_plus_noise3;
          }
     }

Additional context
However, it nearly doesn't cause any mistake when we just see the result, which confuses me more.

solve the logical error between initialization and segmentation in vibe
@andrewssobral
Copy link
Owner

Thank you very much @vc-zju for this fix! Let's merge it

@andrewssobral andrewssobral merged commit 4e47342 into andrewssobral:master Sep 14, 2021
KhanMechAI pushed a commit to KhanMechAI/bgslibrary that referenced this pull request Mar 1, 2023
solve the logical error between initialization and segmentation in vibe
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.

2 participants