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

  • SEARCH
  • Home
  • 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 8967021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:09:12+00:00 2026-06-15T17:09:12+00:00

I am trying to extract a bitmask from a QPixmap and pass it to

  • 0

I am trying to extract a bitmask from a QPixmap and pass it to OpenCV. My bitmask is created by “painting” operations.

My process so far has been:

  1. Create a QPixmap, QPixmap::fill(QColor(0,0,0,0)) and use a QPainter with QPainter::setPen(QColor(255,0,0,255)) to QPainter::drawPoint(mouse_event->pos()

  2. When ready to extract the bitmask QPixmap::toImage() then QImage::createAlphaMask(), which is documented to return QImage::Format_MonoLSB

I am now officially stuck though. I’m having trouble deciphering the documentation:

Each pixel stored in a QImage is represented by an integer. The size of the integer varies depending on the format. QImage supports several image formats described by the Format enum.

Monochrome images are stored using 1-bit indexes into a color table with at most two colors. There are two different types of monochrome images: big endian (MSB first) or little endian (LSB first) bit order.

…

The createAlphaMask() function builds and returns a 1-bpp mask from the alpha buffer in this image…

Also:

QImage::Format_MonoLSB — 2 —The image is stored using 1-bit per pixel. Bytes are packed with the less significant bit (LSB) first.

Could anyone help me clarify how to transfer this into a cv::Mat.

Also, am I supposed to read this that each pixel will be an unsigned char or will we be storing 8 pixels in a bit.

  • 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-06-15T17:09:13+00:00Added an answer on June 15, 2026 at 5:09 pm

    I’ve successfully managed to transfer a monochrome QImage to a cv::Mat. I hope the following code is helpful to others:

    IMPORTANT EDIT: There was a major bug with this code. bytesPerLine is byte aligned as well as word aligned on some machines. Thus the width() should be used with cur_byte

    QImage mask; //Input from wherever
    cv::Mat workspace;
    if(!mask.isNull() && mask.depth() == 1)
    {
        if(mask.width() != workspace.cols || mask.height() != workspace.rows)
            workspace.create(mask.height(), mask.width(), CV_8UC1);
    
        for(int i = 0; i < mask.height(); ++i)
        {
            unsigned char * cur_row = mask.scanLine(i);
            //for(int cur_byte = 0, j = 0; cur_byte < mask.bytesPerLine(); ++cur_byte) wrong
            for(int cur_byte = 0, j = 0; j < mask.width(); ++cur_byte)
            {
                unsigned char pixels = cur_row[cur_byte];
                for(int cur_bit = 0; cur_bit < 8; ++cur_bit, ++j)
                {
                    if(pixels & 0x01) //Least Significant Bit
                        workspace.at<unsigned char>(i, j) = 0xff;
                    else
                        workspace.at<unsigned char>(i, j) = 0x00;
                     pixels = pixels >> 1; //Least Significant Bit
                }
            }
         }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to extract hours, seconds and minutes from an input text
I am trying to extract from a webpage which has the following markup <div
i am trying to extract outline path from given bitmap, i create a fast
im trying to extract some files from a jar-file downloaded using java-webstart. below code
I am trying to extract the facebook id from an iframe in order to
I am trying to extract the video id from a youtube url using the
I am trying to extract the page name from a complex url. This post
I'm trying to extract all of the links to image files from a text
I'm trying to extract all the unique characters from my utf-8 French dictionary file
I am trying to extract the below query: select '<tr><td>'||column1||'</td>', '<td>'||column2||'</td>', '<td>'||column3||'</td></tr>' from table

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.