Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4267762
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:56:37+00:00 2026-05-21T06:56:37+00:00

I am trying to parallelize some Image Matching code written in OpenCV using TBB.

  • 0

I am trying to parallelize some Image Matching code written in OpenCV using TBB. Problem is that according to me matching (creating a 5×5 window in left image and looking for match in right pixel by pixel) is essentially a read only operation and currently I am trying to parallelize the inner loop ( ie at a given height. I assign different pixels to different threads). To my surprise though the cvSetImageROI command breaks when done in parallel. Here is the code.

//Code below just carves out a window(5x5) at a current width which is to be matched
cvSetImageROI(leftImageROI, cvRect(curWidth - 2, 0, 5, 5));
IplImage* currentROI = cvCreateImage(cvSize(5, 5), leftImageROI->depth, leftImageROI->nChannels);
cvCopy(leftImageROI, currentROI);                   
cvResetImageROI(leftImageROI);

Now all this looks thread safe to me since they are only reading images.However code crashes. If I put a lock at the very beginning though it works. Can someone help ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T06:56:38+00:00Added an answer on May 21, 2026 at 6:56 am

    setImageROI() is not a read-only operation. Obviously, as it is changing the state of the image. Even if it would not crash, some of your copy operations would operate on the wrong ROI (as set by a different thread).

    The solution to your problem is to use the OpenCV C++ API!

    There you have a cv::Mat instead of IplImage. Then, you can use code like this:

    // given: cv::Mat image
    // returns: cv::Mat dest
    cv::Rect roi(curWidth - 2, 0, 5, 5);
    cv::Mat local(image, roi);
    cv::Mat dest(...);
    local.copyTo(dest);
    

    Now why is this thread-safe? Obviously, the state of the original image is not changed. Instead, the ROI is written to a new, thread-local matrix header.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to parallelise a code using scala actors. That is my first
I'm trying to use doSMP / foreach to parallelize some code in R. I
Here's the sample C code that I am trying to accelerate using SSE, the
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
I was considering trying PLINQ to parallelize some numerical methods which need to be
I'm trying to understand some of the basics of using POSIX pthreads. The kind
Trying to create an app that does some socket communication (Writing only). I can
I've written a python function that scours a filesystem using a provided directory pattern,
I'm trying to understand some quirks of the Parallelize[] behavior. If I do: CloseKernels[];
I'm trying to refactor some code to achieve more throughput through parallelism. I did

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.