<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[opencv]]></title><description><![CDATA[<p>Hallo,</p>
<p>Ich habe ein schwarz-weiß Bild.<br />
Ich habe die Aufgabe, die Mitte eines schwarzen Blocks herauszufinden.</p>
<p>Zu Anfang habe ich mir gedacht, dass ich den Block mit Linien umschließe, damit ich herausfinde, ob die Koordinaten richtig sind.</p>
<p>Allerdings klappt es nicht und ich finde den Fehler nicht.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
//#include &lt;math.h&gt;
#include &lt;cv.h&gt;
#include &lt;highgui.h&gt;

using namespace std;
using namespace cv;

int main(int argc, char *argv[])
{
  IplImage* img = 0;
  int height,width,step,channels, row;
  uchar *data;
  int i=0,j,k;

  if(argc&lt;2){
    cerr&lt;&lt;&quot;Usage: &quot; &lt;&lt; argv[0] &lt;&lt; &quot; &lt;image-file-name&gt; &quot; &lt;&lt; endl;
    exit(1);
  }

  // load an image  
  img=cvLoadImage(argv[1]);
  if(!img){
    cerr &lt;&lt; &quot;Could not load image from file: &quot; &lt;&lt; argv[1]&lt;&lt;endl;
    exit(2);
  }

cout &lt;&lt; &quot; Simple variable value i=&quot; &lt;&lt; i &lt;&lt; endl;

  // get the image data
  height    = img-&gt;height;
  width     = img-&gt;width;
  step      = img-&gt;widthStep;
  channels  = img-&gt;nChannels;
  data      = (uchar *)img-&gt;imageData;
  cout &lt;&lt; &quot;Processing a &quot; &lt;&lt; height &lt;&lt; &quot;x&quot; &lt;&lt; width &lt;&lt; &quot; image with &quot; &lt;&lt; channels &lt;&lt; &quot; colour channels&quot; &lt;&lt; endl;
  //cout &lt;&lt; &quot;Step is &quot; &lt;&lt; step &lt;&lt; endl;

  // create a window
  cvNamedWindow(&quot;mainWin&quot;, CV_WINDOW_AUTOSIZE);
  cvMoveWindow(&quot;mainWin&quot;, 100, 100);

  // NB Your code
 for(i=0;i&lt;height;i++)
 {
    for(j=0;j&lt;width;j++)
    {
       for(k=0;k&lt;channels;k++)
       {
         if(data[i*step+j*channels+k] &lt; 60)
         {
            data[i*step+j*channels+k] = 0;
         }
         else
            data[i*step+j*channels+k] = 255;
       }
    }
 }
 int row_begin = 0, row_end = 0;
 int column_begin = 0, column_end = 0;

 for(i=0;i&lt;(height);i++)
 {
    for(j=0;j&lt;(width);j++)
    {
       for(k=0;k&lt;channels;k++)
       {
        if((data[i*step+j*channels+k] == 255) &amp;&amp; ((data[(++i)*step+j*channels+k] == 0) || (data[i*step+(++j)*channels+k] == 0) || (data[(++i)*step+ (++j)*channels+k] == 0)))
        {
         row_begin = i;
         column_begin = j;
        }

        if((data[i*step+j*channels+k] == 0) &amp;&amp; ((data[(++i)*step+j*channels+k] == 255) || (data[i*step+(++j)*channels+k] == 255) || (data[(++i)*step+(++j)*channels+k == 255] )))
        {
         row_end = i;
         column_end = j;
        }
       }
    }
 }

cvLine(img, cvPoint(column_begin,0), cvPoint(column_begin,width), cvScalar(255,0,0), 1);
cvLine(img, cvPoint(0,row_begin), cvPoint(height,row_begin), cvScalar(255,0,0), 1);

cvLine(img, cvPoint(column_end,0), cvPoint(column_end,width), cvScalar(255,255,0), 1);
cvLine(img, cvPoint(0,row_end), cvPoint(height,row_end), cvScalar(255,255,0), 1);

cout&lt;&lt;&quot;r_b = &quot;&lt;&lt;row_begin&lt;&lt;endl;
cout&lt;&lt;&quot;c_b = &quot;&lt;&lt;column_begin&lt;&lt;endl;
cout&lt;&lt;&quot;r_e = &quot;&lt;&lt;row_end&lt;&lt;endl;
cout&lt;&lt;&quot;c_e = &quot;&lt;&lt;column_end&lt;&lt;endl;

  //End Your code

  // show the image
  cvShowImage(&quot;mainWin&quot;, img );

  // wait for a key
  cvWaitKey(0);

  // release the image
  cvReleaseImage(&amp;img );
  return 0;
}
</code></pre>
<p>Vielleicht könnt ihr mir weiterhelfen</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/310060/opencv</link><generator>RSS for Node</generator><lastBuildDate>Tue, 04 Aug 2026 23:26:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/310060.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 02 Nov 2012 13:24:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to opencv on Fri, 02 Nov 2012 13:24:50 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Ich habe ein schwarz-weiß Bild.<br />
Ich habe die Aufgabe, die Mitte eines schwarzen Blocks herauszufinden.</p>
<p>Zu Anfang habe ich mir gedacht, dass ich den Block mit Linien umschließe, damit ich herausfinde, ob die Koordinaten richtig sind.</p>
<p>Allerdings klappt es nicht und ich finde den Fehler nicht.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
//#include &lt;math.h&gt;
#include &lt;cv.h&gt;
#include &lt;highgui.h&gt;

using namespace std;
using namespace cv;

int main(int argc, char *argv[])
{
  IplImage* img = 0;
  int height,width,step,channels, row;
  uchar *data;
  int i=0,j,k;

  if(argc&lt;2){
    cerr&lt;&lt;&quot;Usage: &quot; &lt;&lt; argv[0] &lt;&lt; &quot; &lt;image-file-name&gt; &quot; &lt;&lt; endl;
    exit(1);
  }

  // load an image  
  img=cvLoadImage(argv[1]);
  if(!img){
    cerr &lt;&lt; &quot;Could not load image from file: &quot; &lt;&lt; argv[1]&lt;&lt;endl;
    exit(2);
  }

cout &lt;&lt; &quot; Simple variable value i=&quot; &lt;&lt; i &lt;&lt; endl;

  // get the image data
  height    = img-&gt;height;
  width     = img-&gt;width;
  step      = img-&gt;widthStep;
  channels  = img-&gt;nChannels;
  data      = (uchar *)img-&gt;imageData;
  cout &lt;&lt; &quot;Processing a &quot; &lt;&lt; height &lt;&lt; &quot;x&quot; &lt;&lt; width &lt;&lt; &quot; image with &quot; &lt;&lt; channels &lt;&lt; &quot; colour channels&quot; &lt;&lt; endl;
  //cout &lt;&lt; &quot;Step is &quot; &lt;&lt; step &lt;&lt; endl;

  // create a window
  cvNamedWindow(&quot;mainWin&quot;, CV_WINDOW_AUTOSIZE);
  cvMoveWindow(&quot;mainWin&quot;, 100, 100);

  // NB Your code
 for(i=0;i&lt;height;i++)
 {
    for(j=0;j&lt;width;j++)
    {
       for(k=0;k&lt;channels;k++)
       {
         if(data[i*step+j*channels+k] &lt; 60)
         {
            data[i*step+j*channels+k] = 0;
         }
         else
            data[i*step+j*channels+k] = 255;
       }
    }
 }
 int row_begin = 0, row_end = 0;
 int column_begin = 0, column_end = 0;

 for(i=0;i&lt;(height);i++)
 {
    for(j=0;j&lt;(width);j++)
    {
       for(k=0;k&lt;channels;k++)
       {
        if((data[i*step+j*channels+k] == 255) &amp;&amp; ((data[(++i)*step+j*channels+k] == 0) || (data[i*step+(++j)*channels+k] == 0) || (data[(++i)*step+ (++j)*channels+k] == 0)))
        {
         row_begin = i;
         column_begin = j;
        }

        if((data[i*step+j*channels+k] == 0) &amp;&amp; ((data[(++i)*step+j*channels+k] == 255) || (data[i*step+(++j)*channels+k] == 255) || (data[(++i)*step+(++j)*channels+k == 255] )))
        {
         row_end = i;
         column_end = j;
        }
       }
    }
 }

cvLine(img, cvPoint(column_begin,0), cvPoint(column_begin,width), cvScalar(255,0,0), 1);
cvLine(img, cvPoint(0,row_begin), cvPoint(height,row_begin), cvScalar(255,0,0), 1);

cvLine(img, cvPoint(column_end,0), cvPoint(column_end,width), cvScalar(255,255,0), 1);
cvLine(img, cvPoint(0,row_end), cvPoint(height,row_end), cvScalar(255,255,0), 1);

cout&lt;&lt;&quot;r_b = &quot;&lt;&lt;row_begin&lt;&lt;endl;
cout&lt;&lt;&quot;c_b = &quot;&lt;&lt;column_begin&lt;&lt;endl;
cout&lt;&lt;&quot;r_e = &quot;&lt;&lt;row_end&lt;&lt;endl;
cout&lt;&lt;&quot;c_e = &quot;&lt;&lt;column_end&lt;&lt;endl;

  //End Your code

  // show the image
  cvShowImage(&quot;mainWin&quot;, img );

  // wait for a key
  cvWaitKey(0);

  // release the image
  cvReleaseImage(&amp;img );
  return 0;
}
</code></pre>
<p>Vielleicht könnt ihr mir weiterhelfen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266589</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266589</guid><dc:creator><![CDATA[chris2728]]></dc:creator><pubDate>Fri, 02 Nov 2012 13:24:50 GMT</pubDate></item><item><title><![CDATA[Reply to opencv on Fri, 02 Nov 2012 13:30:09 GMT]]></title><description><![CDATA[<p>chris2728 schrieb:</p>
<blockquote>
<p>Allerdings klappt es nicht und ich finde den Fehler nicht.</p>
<p>...</p>
<p>Vielleicht könnt ihr mir weiterhelfen</p>
</blockquote>
<p>Bei der Problembeschreibung sicher nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266591</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266591</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Fri, 02 Nov 2012 13:30:09 GMT</pubDate></item><item><title><![CDATA[Reply to opencv on Fri, 02 Nov 2012 13:36:56 GMT]]></title><description><![CDATA[<p>Ich habe folgendes Bild:<br />
<a href="http://img213.imageshack.us/img213/17/purgid.jpg" rel="nofollow">http://img213.imageshack.us/img213/17/purgid.jpg</a></p>
<p>Diese Bild habe ich in ein schwarz-weißes Bild umgewandelt, so dass nur noch die 2 schwarzen Blöcke zu sehen sind.</p>
<p>Jetzt brauche ich die Mitte des Blockes der oben links ist.<br />
Der Plan ist Ende_Koord. - Anfangs_Koord. der Zeilen und Spalten.</p>
<p>Ich habe versucht diesen Block mittels Linien zu umschließen, um zu sehen ob diese Koordinaten stimmen, aber die sind entweder ganz am Anfang (zeile = 0, spalte = 0) oder irgendwo im nirgendwo.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266596</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266596</guid><dc:creator><![CDATA[chris2728]]></dc:creator><pubDate>Fri, 02 Nov 2012 13:36:56 GMT</pubDate></item><item><title><![CDATA[Reply to opencv on Fri, 02 Nov 2012 14:18:42 GMT]]></title><description><![CDATA[<p>Das hier</p>
<pre><code class="language-cpp">if((data[i*step+j*channels+k] == 255) &amp;&amp; ((data[(++i)*step+j*channels+k] == 0) || (data[i*step+(++j)*channels+k] == 0) || (data[(++i)*step+ (++j)*channels+k] == 0)))
</code></pre>
<p>ist mit Sicherheit undefiniertes Verhalten. Du willst prüfen, ob Pixel 255 und Nachbar-Pixel 0 sind? Dann prüfe Pixel i und Pixel i+1 (nicht ++i, damit inkrementierst du i vor Auswertung des Terms, und das mehrmals in einem Ausdruck ist irgendwie ziemlich böse <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> ).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266609</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266609</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Fri, 02 Nov 2012 14:18:42 GMT</pubDate></item><item><title><![CDATA[Reply to opencv on Fri, 02 Nov 2012 14:18:43 GMT]]></title><description><![CDATA[<p>Was ich damit machen will ist:</p>
<p>Wenn der jetzige Pixel weiß ist und der Pixel in der nächsten Zeile bzw. Spalte schwarz ist, ist das der Anfang des Blockes</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266611</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266611</guid><dc:creator><![CDATA[chris2728]]></dc:creator><pubDate>Fri, 02 Nov 2012 14:18:43 GMT</pubDate></item><item><title><![CDATA[Reply to opencv on Fri, 02 Nov 2012 14:21:33 GMT]]></title><description><![CDATA[<p>chris2728 schrieb:</p>
<blockquote>
<p>Was ich damit machen will ist:</p>
<p>Wenn der jetzige Pixel weiß ist und der Pixel in der nächsten Zeile bzw. Spalte schwarz ist, ist das der Anfang des Blockes</p>
</blockquote>
<p>Der Ansatz ist ja auch ok. Aber notiere dann für den Nachbarpixel i+1 (bzw. j+1), nicht ++i.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266612</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266612</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Fri, 02 Nov 2012 14:21:33 GMT</pubDate></item><item><title><![CDATA[Reply to opencv on Sat, 03 Nov 2012 13:11:15 GMT]]></title><description><![CDATA[<p>Ich habe mal die zwei IF-Anweisungen in vier aufgeteilt</p>
<pre><code class="language-cpp">if((data[i*step+j*channels+k] == 255) &amp;&amp; (data[(i++)*step+j*channels+k] == 0))
         row_begin = i;

        if((data[i*step+j*channels+k] == 255) &amp;&amp; (data[i*step+(j++)*channels+k] == 0))
         column_begin = j;

        if((data[i*step+j*channels+k] == 0) &amp;&amp; (data[(i++)*step+j*channels+k] == 255))
         row_end = i;

        if((data[i*step+j*channels+k] == 0) &amp;&amp; (data[i*step+(j++)*channels+k] == 255))
         column_end = j;
</code></pre>
<p>Als Ergebnis kommt bei allen 4 Variablen immer 0</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2266886</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2266886</guid><dc:creator><![CDATA[chris2728]]></dc:creator><pubDate>Sat, 03 Nov 2012 13:11:15 GMT</pubDate></item><item><title><![CDATA[Reply to opencv on Sun, 04 Nov 2012 18:04:58 GMT]]></title><description><![CDATA[<p>*push*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2267321</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2267321</guid><dc:creator><![CDATA[chris2728]]></dc:creator><pubDate>Sun, 04 Nov 2012 18:04:58 GMT</pubDate></item><item><title><![CDATA[Reply to opencv on Mon, 05 Nov 2012 09:04:17 GMT]]></title><description><![CDATA[<p>chris2728 schrieb:</p>
<blockquote>
<pre><code class="language-cpp">if((data[i*step+j*channels+k] == 255) &amp;&amp; (data[(i++)*step+j*channels+k] == 0))
         row_begin = i;
</code></pre>
</blockquote>
<p>Du musst dir wirklich mal ansehen, wie das mit den Pre-/Postincrement-Operatoren funktioniert. Das sind Grundlagen, die du beherrschen solltest, bevor du dich an die Bildverarbeitung herantraust. Deine Bedingung kann hier niemals erfüllt werden, da du i erst <strong>nach</strong> Auswerten des Ausdrucks inkrementierst. Du fragst also ab: &quot;ist Pixel i,j == 255 und ist Pixel i,j == 0&quot;. Erst danach erhöhst du i. Logisch, dass der Pixel nicht beide Werte halten kann, oder? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2267559</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2267559</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Mon, 05 Nov 2012 09:04:17 GMT</pubDate></item><item><title><![CDATA[Reply to opencv on Mon, 05 Nov 2012 13:24:32 GMT]]></title><description><![CDATA[<p>Und überhaupt...<strong>i</strong> ist doch eine Laufvariable einer deiner For-Schleifen...diese überhaupt zu verändern halte ich für fragwürdig ... jede ausgeführte If-Abfrage ändert den Index...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2267646</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2267646</guid><dc:creator><![CDATA[_Sascha_]]></dc:creator><pubDate>Mon, 05 Nov 2012 13:24:32 GMT</pubDate></item><item><title><![CDATA[Reply to opencv on Mon, 05 Nov 2012 16:33:30 GMT]]></title><description><![CDATA[<p>So, wie Du Dir das vorstellst wird das mit Deinem Code aber nichts.</p>
<p>In Zeile 46-60 versuchst Du, das Bild zu binarisieren. Das geht aber nur, wenn alle Kanäle den selben Wert haben. So wie Du das machst, kommen nicht unbedingt Schwarz-Weiss-Werte raus. Beispiel: Dreikanalbild, rgb mit [49, 61, 49]. Da macht Dein Verfahren dann ein komplett grünes Pixel draus. Du musst erst die Kanäle in einen graukanal wandeln - wenn Du noch kein Graustufenbild hast - und dann denn Schwellenwertoperator anwenden.</p>
<p>Das Ganze würde ich dann in eine separate FUnktion &quot;binarize&quot; auslagern. Eigentlich sollte OpenCV aber so was schon mitbringen.</p>
<p>Dass die Verwendung des Preinkrement-Operators in den Zeilen 70 und 76 falsch ist haben diverser Vorposter ja schon gesagt.</p>
<p>Dein Ansatz, so wie er in den Zeilen 61-84 formuliert ist, würde, selbst wenn die Codierungsfehler nicht drin wären, nur das am weitesten rechts unten liegende Rechteck erkennen.</p>
<p>Statt dessen solltest Du drei Funktionen schreiben. Eine, die die linke obere Ecke eines Rechtecks im Bild sucht, und eine weitere, die, ausgehend von der vorher gefundenen die korrespondierende rechte, untere Ecke sucht. Und die dritte Funktion ruft zuerst die Erste, und dann die zweite Funktion auf. Um alle Rechtecke zu finden, muss Du dann durch das ganze Bild gehen, wobei Du die Suche n+1 an der rechten oberen (!) Ecke, des zuvor gefundenen Rechtecks starten kannst.</p>
<p>Und: Lass Dich nicht entmutigen! Aller Anfang ist schwer und Du hast Dir ein Problem ausgesucht, bei dem Du viel über Programmierung und Bildverarbeitung lernen kannst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2267753</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2267753</guid><dc:creator><![CDATA[cvcv]]></dc:creator><pubDate>Mon, 05 Nov 2012 16:33:30 GMT</pubDate></item><item><title><![CDATA[Reply to opencv on Mon, 05 Nov 2012 17:33:17 GMT]]></title><description><![CDATA[<p>Übrigens ist es bei solchen Geschichten oft hilfreich, sich die Zwischenschritte auch mal selbst anzusehen. Wenn du dein Bild nicht in einem Control anzeigen kannst, weil du gar kein GUI hast, kannst du es ja als Datei abspeichern. Dann wäre dir z.B. aufgefallen, dass dein Binärbild gar keines ist (habe ich gar nicht gesehen, guter Einwand). Ich zeichne auch manchmal gerne mit verschiedenen Farben ins Bild hinein, was der Algorithmus so macht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2267786</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2267786</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Mon, 05 Nov 2012 17:33:17 GMT</pubDate></item></channel></rss>