Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your program has a couple of issues.</p> <p>First of all <code>imgColor</code> is not declared, you'll need:</p> <pre><code>IplImage* imgColor = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 3); </code></pre> <p>Also, on:</p> <pre><code>void changeColor(int pos) { cvSet(imgColor, CV_RGB(red, green, blue), NULL); } </code></pre> <p>you can't access neither <code>red</code>, nor <code>green</code>, nor <code>blue</code> here, for they are local to main. I take it this is just a concept proof example, let's declare these global.</p> <p>Now onto why no windows is displayed. There are two reasons:</p> <ol> <li><p>That may sound obvious, but well, main is returning, your program is simply exiting. As sgar91 already pointed out, you'll need <code>cvWaitKey(0);</code> at the end of main so you program can hold there processing gui events.</p></li> <li><p>That also might sound obvious, but you haven't actually instructed OpenCV to show anything. You'll need <code>cvShowImage("ColorSelector", imgColor);</code>, this will trigger events for window painting inside OpenCV;</p></li> </ol> <p>The following quick and dirty example works fine and I'm able to select the color which is displayed on the window.</p> <pre><code>#include &lt;cstdio&gt; #include "cv.h" #include "highgui.h" int red, blue, green; IplImage* imgColor = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 3); void changeColor(int pos) { cvSet(imgColor, CV_RGB(red, green, blue), NULL); cvShowImage("ColorSelector", imgColor); } int main() { // cvNamedWindow("DrawArea", 0); //area for inputting digits cvNamedWindow("ColorSelector", 0); //area for selecting colour of input cvShowImage("ColorSelector", imgColor); cvCreateTrackbar("Red", "ColorSelector", &amp;red, 255, &amp;changeColor); cvCreateTrackbar("Green", "ColorSelector", &amp;green, 255, &amp;changeColor); cvCreateTrackbar("Blue", "ColorSelector", &amp;blue, 255, &amp;changeColor); // cvSetMouseCallback("Demo", &amp;on_mouse, 0); cvWaitKey(0); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload