<?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[Mittelwert einer Bildmatrix bilden und abspeichern]]></title><description><![CDATA[<p>Guten Tag liebe Community,<br />
ich bin ziemlich neu in diesem Gebiet und suche nun nach Vorschlägen. Ich schildere kurz mein Anliegen:</p>
<p>Ich schreibe ein C++ Programm auf meinem Beaglebone Black mit dem Betriebssystem Ubuntu 14.04.<br />
In dem Programm lese ich ein Bild im PNG Format ein und würde nun gerne die Summe aller Elemente dieser Bildmatrix erhalten um daraus den Mittelwert zu bilden. Das Bild ist in ein Graustufenbild umgewandelt worden. Über die Helligkeitsinformationen (Mittelwert) möchte ich einen Rückschluss auf die Bewegungen in dem Bild schließen.</p>
<p>Nun folgt der Programmcode:</p>
<pre><code>#include &lt;stdio.h&gt;
#include &quot;opencv2/core/core.hpp&quot;
#include &quot;opencv2/features2d/features2d.hpp&quot;
#include &quot;opencv2/highgui/highgui.hpp&quot;
#include &quot;opencv2/nonfree/nonfree.hpp&quot;
#include &lt;string&gt;
#include &lt;sstream&gt;

using namespace cv;

static void help()
{
    printf(&quot;\nThis program demonstrates using features2d detector, descriptor extractor and simple matcher\n&quot;
            &quot;Using the SURF desriptor:\n&quot;
            &quot;\n&quot;
            &quot;Usage:\n matcher_simple &lt;image1&gt; &lt;image2&gt;\n&quot;);
}

int main(int argc, char** argv)
{
    if(argc != 3)
    {
        help();
        return -1;
    }

    Mat img1 = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
    Mat img2 = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE);
    if(img1.empty() || img2.empty())
    {
        printf(&quot;Can't read one of the images\n&quot;);
        return -1;
    }

    Mat img_matches;

	img_matches = img1 - img2;

	img_matches = imwrite( &quot;./differenz.png&quot;, img_matches);

    waitKey(0);	

	long summe = 0;

	for(int i=0;i &lt; 100;i++)
	{
		summe += img_matches[i];
	}

    IplImage *img = cvLoadImage(&quot;differenz.png&quot;);
    CvMat *mat = cvCreateMat(img-&gt;height,img-&gt;width,CV_32FC3 );
    cvConvert( img, mat );
	cvSave( &quot;./combined2307.txt&quot;, mat );

    FILE *datei;

    datei = fopen (&quot;datei.txt&quot;, &quot;w&quot;);

    if (datei == NULL)

      {

        printf(&quot;Fehler beim oeffnen der Datei.&quot;);

        return 1;

      }
	std::string s = std::to_string(summe);

    fprintf (datei, &quot;%s&quot;, s.c_str());

    fclose (datei);

    return 0;
}
</code></pre>
<p>Der Fehler der beim compilieren nun ensteht ist der, dass img_Matches vom Typ cv::mat ist und somit nicht in einen Typ int gebracht werden kann...</p>
<p>no match for ‘operator[]’ (operand types are ‘cv::M at’ and ‘int’)<br />
summe += img_matches[i];</p>
<p>Ich hoffe mir kann da jemand weiter helfen.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/327191/mittelwert-einer-bildmatrix-bilden-und-abspeichern</link><generator>RSS for Node</generator><lastBuildDate>Thu, 09 Jul 2026 20:22:01 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/327191.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 28 Jul 2014 08:51:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Mittelwert einer Bildmatrix bilden und abspeichern on Mon, 28 Jul 2014 08:51:17 GMT]]></title><description><![CDATA[<p>Guten Tag liebe Community,<br />
ich bin ziemlich neu in diesem Gebiet und suche nun nach Vorschlägen. Ich schildere kurz mein Anliegen:</p>
<p>Ich schreibe ein C++ Programm auf meinem Beaglebone Black mit dem Betriebssystem Ubuntu 14.04.<br />
In dem Programm lese ich ein Bild im PNG Format ein und würde nun gerne die Summe aller Elemente dieser Bildmatrix erhalten um daraus den Mittelwert zu bilden. Das Bild ist in ein Graustufenbild umgewandelt worden. Über die Helligkeitsinformationen (Mittelwert) möchte ich einen Rückschluss auf die Bewegungen in dem Bild schließen.</p>
<p>Nun folgt der Programmcode:</p>
<pre><code>#include &lt;stdio.h&gt;
#include &quot;opencv2/core/core.hpp&quot;
#include &quot;opencv2/features2d/features2d.hpp&quot;
#include &quot;opencv2/highgui/highgui.hpp&quot;
#include &quot;opencv2/nonfree/nonfree.hpp&quot;
#include &lt;string&gt;
#include &lt;sstream&gt;

using namespace cv;

static void help()
{
    printf(&quot;\nThis program demonstrates using features2d detector, descriptor extractor and simple matcher\n&quot;
            &quot;Using the SURF desriptor:\n&quot;
            &quot;\n&quot;
            &quot;Usage:\n matcher_simple &lt;image1&gt; &lt;image2&gt;\n&quot;);
}

int main(int argc, char** argv)
{
    if(argc != 3)
    {
        help();
        return -1;
    }

    Mat img1 = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
    Mat img2 = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE);
    if(img1.empty() || img2.empty())
    {
        printf(&quot;Can't read one of the images\n&quot;);
        return -1;
    }

    Mat img_matches;

	img_matches = img1 - img2;

	img_matches = imwrite( &quot;./differenz.png&quot;, img_matches);

    waitKey(0);	

	long summe = 0;

	for(int i=0;i &lt; 100;i++)
	{
		summe += img_matches[i];
	}

    IplImage *img = cvLoadImage(&quot;differenz.png&quot;);
    CvMat *mat = cvCreateMat(img-&gt;height,img-&gt;width,CV_32FC3 );
    cvConvert( img, mat );
	cvSave( &quot;./combined2307.txt&quot;, mat );

    FILE *datei;

    datei = fopen (&quot;datei.txt&quot;, &quot;w&quot;);

    if (datei == NULL)

      {

        printf(&quot;Fehler beim oeffnen der Datei.&quot;);

        return 1;

      }
	std::string s = std::to_string(summe);

    fprintf (datei, &quot;%s&quot;, s.c_str());

    fclose (datei);

    return 0;
}
</code></pre>
<p>Der Fehler der beim compilieren nun ensteht ist der, dass img_Matches vom Typ cv::mat ist und somit nicht in einen Typ int gebracht werden kann...</p>
<p>no match for ‘operator[]’ (operand types are ‘cv::M at’ and ‘int’)<br />
summe += img_matches[i];</p>
<p>Ich hoffe mir kann da jemand weiter helfen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2410785</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2410785</guid><dc:creator><![CDATA[Taazok]]></dc:creator><pubDate>Mon, 28 Jul 2014 08:51:17 GMT</pubDate></item><item><title><![CDATA[Reply to Mittelwert einer Bildmatrix bilden und abspeichern on Mon, 28 Jul 2014 10:07:39 GMT]]></title><description><![CDATA[<p>Wo ist deine C++ Frage?<br />
Hast du die OpenCV Doku gelesen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2410799</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2410799</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Mon, 28 Jul 2014 10:07:39 GMT</pubDate></item><item><title><![CDATA[Reply to Mittelwert einer Bildmatrix bilden und abspeichern on Mon, 28 Jul 2014 11:16:03 GMT]]></title><description><![CDATA[<p>manni66 schrieb:</p>
<blockquote>
<p>Wo ist deine C++ Frage?<br />
Hast du die OpenCV Doku gelesen?</p>
</blockquote>
<p>Ich habe gehofft dass es Funktionen in C++ gibt, die mir ein Scalar aus der Matrix bilden. OpenCV funktioniert nicht einwandfrei auf dem Beaglebone. Viele Funktionen zeigen einen Treiberkonflikt an. Deswegen wollte ich es über C++ Bibliotheken und Funktionen realisieren.</p>
<p>Ich bin aber über jeden Tipp dankbar. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2410812</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2410812</guid><dc:creator><![CDATA[Taazok]]></dc:creator><pubDate>Mon, 28 Jul 2014 11:16:03 GMT</pubDate></item></channel></rss>