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 9192071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:50:15+00:00 2026-06-17T20:50:15+00:00

I made a simple graphical user interface with Qt and I use OpenCV for

  • 0

I made a simple graphical user interface with Qt and I use OpenCV for making processing on webcam streaming, i.e canny edge detection.

I try to implement a switch between two displays of the webcam :

1*) “normal Mode” : a grayscale display where webcam gives a border detection video with grayscale color

2*) “greenMode” : a green and black display where webcam gives the same “border detected” but with green and black colors.

The first one works (with grayscale) works. Here’s the result :

enter image description here

Now I have problems with the second one. Here’s the part of the code where I can’t find a solution :

  // Init capture
  capture = cvCaptureFromCAM(0);
  first_image = cvQueryFrame( capture );
  // Init current qimage
  current_qimage = QImage(QSize(first_image->width,first_image->height),QImage::Format_RGB32);

  IplImage* frame = cvQueryFrame(capture);
  int w = frame->width;
  int h = frame->height;

  if (greenMode) // greenMode : black and green result
  {
    current_image = cvCreateImage(cvGetSize(frame),8,3); 
    cvCvtColor(frame,current_image,CV_BGR2RGB);

    for(int j = 0; j < h; j++)
    {  
      for(int i = 0; i < w; i++)
      {
        current_qimage.setPixel(i,j,qRgb(current_image->imageData[i+j*w+1],current_image->imageData[i+j*w+1],current_image->imageData[i+j*w+1]));
      }
    }
  }
  else // normal Mode : grayscale result WHICH WORKS
  {
    current_image = cvCreateImage(cvGetSize(frame),8,1); 
    cvCvtColor(frame,current_image,CV_BGR2GRAY);

    for(int j = 0; j < h; j++)
    {  
      for(int i = 0; i < w; i++)
      {
        current_qimage.setPixel(i,j,qRgb(current_image->imageData[i+j*w+1],current_image->imageData[i+j*w+1],current_image->imageData[i+j*w+1]));

      }
    }
  }
  gaussianfilter(webcam_off);
  border_detect(webcam_off);
  cvReleaseImage(&current_image);
  repaint();

The “greenMode” doesn’t seem to put good pixels with this “setPixel” (I take the middle rgb value : current_image->imageData[i+j*w+1]) :

current_image = cvCreateImage(cvGetSize(frame),8,3); 
    cvCvtColor(frame,current_image,CV_BGR2RGB);

    for(int j = 0; j < h; j++)
    {  
      for(int i = 0; i < w; i++)
      {
        current_qimage.setPixel(i,j,qRgb(current_image->imageData[i+j*w+1],current_image->imageData[i+j*w+1],current_image->imageData[i+j*w+1]));
      }
    }

Here’s what I get :

enter image description here

Firstly, the output is not green and black and secondly, it’s zoomed compared to the grayscale image.

Could you have any clues to get the greenMode ?

  • 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-17T20:50:16+00:00Added an answer on June 17, 2026 at 8:50 pm
    qRgb(current_image->imageData[i+j*w+1],current_image->imageData[i+j*w+1],current_image->imageData[i+j*w+1])
    

    You’re using an identical value for all three RGB color components. R == G == B will always result in grey.

    To convert an RGB value to green/black, you could for example convert to greyscale (using the luminosity method) and then tint it green:

    const int v = qRound(  0.21 * pixel.red() + 0.71 * pixel.green() + 0.07 * pixel.blue() );
    setPixel( i, j, qRgb( v, 0, 0 ) );
    

    (There are probably more sophisticated methods for the tinting).

    For the scaling, I assume the error occurs when calculating the index for current_image. You’re using the same (i+j*w+1) for both images, but the grey has 1 channel and the second 3 (third cvCreateImage argument). So the latter will have two more values per pixel.

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

Sidebar

Related Questions

so I'm making some basic programming language (just for exercise). I've made simple grammar
I have made a very simple game in titanium mobile. I only use 90k
I am making a simple game using a JFrame . I have made a
I made simple email in wordpress but it would only send email to the
I have made simple encryption/decryption method in php that I'm trying to move to
hi i've got question i've made simple form with attachment input and i want
Visual Studio 2008 (vb.net) I made simple anivirus but when I make Full scan
OK, I have made simple rectangular using OpenGL, and it looks pretty simple glNormal3f(0.0f,
On Windows, testing different OSes is made simple using VMs. Is there a simple
I made a simple module for Lighttpd to experiment with it. If I just

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.