<?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[Hilfe bei Bildübertragung per Netzwerk]]></title><description><![CDATA[<p>Hi leute,<br />
ich habe die letzten tage versucht ein bild über einen Socket zu senden, doch leider funktioniert das zusammensetzen auf Client-Seite nicht;<br />
Hier ist das zu sendende Bild:<br />
<a href="http://img535.imageshack.us/img535/742/testxr.jpg" rel="nofollow">http://img535.imageshack.us/img535/742/testxr.jpg</a><br />
und hier das, was auf Client-Seite rauskommt:<br />
<a href="http://img85.imageshack.us/img85/4955/recvx.jpg" rel="nofollow">http://img85.imageshack.us/img85/4955/recvx.jpg</a></p>
<p>Ich bin mir sicher das der fehler auf client-seite ist, da das bild auf dem server richtig zerlegt wird.<br />
Es wird vor der Dateiübertragung ein header gesendet der mit &quot;&lt;&quot; und &quot;&gt;&quot; gekennzeichnet ist; in diesem stehen die relevanten informationen (größe,kanäle)</p>
<p>Der Epmfangscode sieht folgendermaßen aus:</p>
<pre><code class="language-cpp">IplImage *img;
int temp_count = 0;
bool data_transfer = false;

void readHandler(string c, int readBytes) // !!!not thread-safe!!!
{	
	if(!data_transfer)
	{
		int header_start = c.find(&quot;&lt;&quot;);
		int header_end = c.find(&quot;&gt;&quot;);
		if(header_start==header_end) // normaler text
		{
			cout &lt;&lt; c; 
		}
		if(header_start &lt; header_end)
		{

			data_transfer = true;

			int start = c.find(&quot;length=&quot;);
			int len = c.find(&quot;;&quot;,start) - start - 7; // length of number
			int tcp_out_count = atoi(c.substr(start + 7,len).c_str()); //size

			start = c.find(&quot;width=&quot;);
			len = c.find(&quot;;&quot;,start) - start - 6;
			int width = atoi(c.substr(start + 6,len).c_str()); //width

			start = c.find(&quot;height=&quot;);
			len = c.find(&quot;;&quot;,start) - start - 7;
			int height = atoi(c.substr(start + 7,len).c_str()); //height

			start = c.find(&quot;depth=&quot;);
			len = c.find(&quot;;&quot;,start) - start - 6;
			int depth = atoi(c.substr(start + 6,len).c_str()); //depth

			start = c.find(&quot;channels=&quot;);
			len = c.find(&quot;;&quot;,start) - start - 9;
			int channels = atoi(c.substr(start + 9,len).c_str()); //channels

			img = cvCreateImage(cvSize(width,height), IPL_DEPTH_8U, channels); //TODO: coversion from int depth to valid input

		}
	}
	else
	{
		for (int j=0; j&lt;readBytes &amp;&amp; j&lt;1024; j++)
		{
			img-&gt;imageData[temp_count*1024+j] = c[j];
		}
		if(temp_count &gt;= img-&gt;imageSize/1024-1)
		{
			cout &lt;&lt; &quot;&lt;finished&gt;&quot; &lt;&lt; endl;
			cout.flush();
			cvSaveImage(&quot;recv.jpg&quot;,img);

			temp_count = 0;
			data_transfer = false;
		}
		temp_count++;
	}
}
</code></pre>
<p>ich hoffe es hat jemand zeit sich das anzusehen;</p>
<p>LG</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/261179/hilfe-bei-bildübertragung-per-netzwerk</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 15:17:58 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/261179.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 14 Feb 2010 23:19:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Hilfe bei Bildübertragung per Netzwerk on Sun, 14 Feb 2010 23:19:18 GMT]]></title><description><![CDATA[<p>Hi leute,<br />
ich habe die letzten tage versucht ein bild über einen Socket zu senden, doch leider funktioniert das zusammensetzen auf Client-Seite nicht;<br />
Hier ist das zu sendende Bild:<br />
<a href="http://img535.imageshack.us/img535/742/testxr.jpg" rel="nofollow">http://img535.imageshack.us/img535/742/testxr.jpg</a><br />
und hier das, was auf Client-Seite rauskommt:<br />
<a href="http://img85.imageshack.us/img85/4955/recvx.jpg" rel="nofollow">http://img85.imageshack.us/img85/4955/recvx.jpg</a></p>
<p>Ich bin mir sicher das der fehler auf client-seite ist, da das bild auf dem server richtig zerlegt wird.<br />
Es wird vor der Dateiübertragung ein header gesendet der mit &quot;&lt;&quot; und &quot;&gt;&quot; gekennzeichnet ist; in diesem stehen die relevanten informationen (größe,kanäle)</p>
<p>Der Epmfangscode sieht folgendermaßen aus:</p>
<pre><code class="language-cpp">IplImage *img;
int temp_count = 0;
bool data_transfer = false;

void readHandler(string c, int readBytes) // !!!not thread-safe!!!
{	
	if(!data_transfer)
	{
		int header_start = c.find(&quot;&lt;&quot;);
		int header_end = c.find(&quot;&gt;&quot;);
		if(header_start==header_end) // normaler text
		{
			cout &lt;&lt; c; 
		}
		if(header_start &lt; header_end)
		{

			data_transfer = true;

			int start = c.find(&quot;length=&quot;);
			int len = c.find(&quot;;&quot;,start) - start - 7; // length of number
			int tcp_out_count = atoi(c.substr(start + 7,len).c_str()); //size

			start = c.find(&quot;width=&quot;);
			len = c.find(&quot;;&quot;,start) - start - 6;
			int width = atoi(c.substr(start + 6,len).c_str()); //width

			start = c.find(&quot;height=&quot;);
			len = c.find(&quot;;&quot;,start) - start - 7;
			int height = atoi(c.substr(start + 7,len).c_str()); //height

			start = c.find(&quot;depth=&quot;);
			len = c.find(&quot;;&quot;,start) - start - 6;
			int depth = atoi(c.substr(start + 6,len).c_str()); //depth

			start = c.find(&quot;channels=&quot;);
			len = c.find(&quot;;&quot;,start) - start - 9;
			int channels = atoi(c.substr(start + 9,len).c_str()); //channels

			img = cvCreateImage(cvSize(width,height), IPL_DEPTH_8U, channels); //TODO: coversion from int depth to valid input

		}
	}
	else
	{
		for (int j=0; j&lt;readBytes &amp;&amp; j&lt;1024; j++)
		{
			img-&gt;imageData[temp_count*1024+j] = c[j];
		}
		if(temp_count &gt;= img-&gt;imageSize/1024-1)
		{
			cout &lt;&lt; &quot;&lt;finished&gt;&quot; &lt;&lt; endl;
			cout.flush();
			cvSaveImage(&quot;recv.jpg&quot;,img);

			temp_count = 0;
			data_transfer = false;
		}
		temp_count++;
	}
}
</code></pre>
<p>ich hoffe es hat jemand zeit sich das anzusehen;</p>
<p>LG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1855695</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1855695</guid><dc:creator><![CDATA[kp]]></dc:creator><pubDate>Sun, 14 Feb 2010 23:19:18 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe bei Bildübertragung per Netzwerk on Sun, 14 Feb 2010 23:43:18 GMT]]></title><description><![CDATA[<p>Da die erste Unregelmäßigkeit rechts unten bei einem dunklen Pixel anfängt, gehe ich davon aus, dass es etwas mit der Nullterminierung von string zu tun hat. Du solltest stattdessen vector&lt;unsigned char&gt; verwenden.<br />
Und wenn du so ein Monstrum als Parameter übergibst, solltest du das unbedingt per Referenz machen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1855699</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1855699</guid><dc:creator><![CDATA[Athar]]></dc:creator><pubDate>Sun, 14 Feb 2010 23:43:18 GMT</pubDate></item><item><title><![CDATA[Reply to Hilfe bei Bildübertragung per Netzwerk on Mon, 15 Feb 2010 11:39:45 GMT]]></title><description><![CDATA[<p>Tatsächlich du hattest Recht... es lag wirklich an der null-terminierung von strings (bzw daran das im Bild auch der Wert 0 vorkommt);</p>
<p>Jetzt wird das Bild beim ersten Mal richtig übertragen, beim 2ten mal ist es wieder falsch (<a href="http://img534.imageshack.us/img534/8940/recv.jpg" rel="nofollow">http://img534.imageshack.us/img534/8940/recv.jpg</a>) und beim 3ten versuch bekomme ich folgende Antwort:</p>
<pre><code>Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7fd3b70 (LWP 16935)]
0x0804b512 in readHandler (
    c=0xbfffef18 &quot;\&quot;\n\024-\026\024*\027\020:)&amp;?12)\037%\&quot;\032$\036\030#\t\005\021#\037+%\037*\032\022\031\037\024\027\063! $\020\v\027&quot;, readBytes=1024)
    at client.cpp:226
226				img-&gt;imageData[temp_count*1024+j] = c[j];
</code></pre>
<p>Das sieht so aus als obe c nicht die 1024 Bytes sind die es sein sollten, aber ich weiß nicht warum...</p>
<p>Hier nochmal der angepasste code (is nicht schön, aber es muss vorerst tun):</p>
<pre><code class="language-cpp">IplImage *img;
int temp_count = 0;
bool data_transfer = false;

void readHandler(char *c, int readBytes) // !!!not thread-safe!!!
{	
	//cout &lt;&lt; c-&gt;length() &lt;&lt; endl;
	if(!data_transfer)
	{
		string s(c);
		int header_start = s.find(&quot;&lt;&quot;);
		int header_end = s.find(&quot;&gt;&quot;);
		if(header_start==header_end)
		{
			cout &lt;&lt; s;
		}
		if(header_start &lt; header_end)
		{

			data_transfer = true;

			int start =  s.find(&quot;length=&quot;,start);
			int len = s.find(&quot;;&quot;,start) - start - 7; // length of number
			int tcp_out_count = atoi(s.substr(start + 7,len).c_str()); //size

			start = s.find(&quot;width=&quot;);
			len = s.find(&quot;;&quot;,start) - start - 6;
			int width = atoi(s.substr(start + 6,len).c_str()); //width

			start = s.find(&quot;height=&quot;);
			len = s.find(&quot;;&quot;,start) - start - 7;
			int height = atoi(s.substr(start + 7,len).c_str()); //height

			start = s.find(&quot;depth=&quot;);
			len = s.find(&quot;;&quot;,start) - start - 6;
			int depth = atoi(s.substr(start + 6,len).c_str()); //depth

			start = s.find(&quot;channels=&quot;);
			len = s.find(&quot;;&quot;,start) - start - 9;
			int channels = atoi(s.substr(start + 9,len).c_str()); //channels

			img = cvCreateImage(cvSize(width,height), IPL_DEPTH_8U, channels); //TODO: coversion from int depth to valid input

		}
	}
	else
	{
		for (int j=0; j&lt;readBytes &amp;&amp; j&lt;1024; j++)
		{
			img-&gt;imageData[temp_count*1024+j] = c[j];
		}
		if(temp_count &gt;= img-&gt;imageSize/1024-1)
		{
			cout &lt;&lt; &quot;&lt;finished&gt;&quot; &lt;&lt; endl;
			cout.flush();
			cvSaveImage(&quot;recv.jpg&quot;,img);

			//tcp_out_count = -1;
			temp_count = 0;
			data_transfer = false;
		}
		temp_count++;
	}
}
</code></pre>
<p>und hier die empfangenden funktionen:</p>
<pre><code class="language-cpp">void read_start(void) 
        { // Start an asynchronous read and call read_complete when it completes or fails 

                socket_.async_read_some(boost::asio::buffer(buffer, 1024), 
                        boost::bind(&amp;tcp_client::read_complete, 
                                this, 
                                boost::asio::placeholders::error, 
                                boost::asio::placeholders::bytes_transferred)); 
        } 

        void read_complete(const boost::system::error_code&amp; error, size_t bytes_transferred) 
        { // the asynchronous read operation has now completed or failed and returned an error 
                if (!error) 
                { // read completed, so process the data 

                	//buffer[bytes_transferred] = '\0';

                	//cout &lt;&lt; buffer;

                	myPtr(&amp;buffer[0], bytes_transferred);

                        //cout.write(buffer, bytes_transferred); // echo to standard output 
                        //cout &lt;&lt; &quot;\n&quot;; 
                        read_start(); // start waiting for another asynchronous read again 
                } 
                else 
                        do_close(); 
        }
</code></pre>
<p>wobei buffer so definiert ist:</p>
<pre><code>char buffer[1024];
</code></pre>
<p>LG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1855852</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1855852</guid><dc:creator><![CDATA[kp]]></dc:creator><pubDate>Mon, 15 Feb 2010 11:39:45 GMT</pubDate></item></channel></rss>