CCS+C6678LE开发记录10:(图像)数据处理与传输框架
2019-07-15 14:57发布
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
CCS+C6678LE开发记录10:(图像)数据处理与传输框架
探索了这么久也该上一点料,本文关注PC<-->DSP数据处理与传输的简单框架。这个框架其实也很简单,具体描述如下:1.PC端通过ETH0发送(图像)数据到DSP2.DSP收到完整数据后进行处理(Image Processing...)3.DSP端数据处理完毕后将数据发回给PC4.PC端收到发回的处理结果,然后保存
下面是一段代码,数据处理执行的操作很简单:对图像像素值取补newValue=255-oldValue- int udpTransferTask( SOCKET s, UINT32 unused )
- {
- printf("TASK execution %d
",++task_counter);
-
- struct timeval tv;
- tv.tv_sec = 1;
- tv.tv_usec = 0;
- setsockopt(s,SOL_SOCKET,SO_SNDTIMEO,&tv,sizeof(tv));
- setsockopt(s,SOL_SOCKET,SO_RCVTIMEO,&tv,sizeof(tv));
-
- struct sockaddr_in sin1;
- int sz=sizeof(sin1);
- int hlen=strlen(reply);
- int nr,total=0;
- HANDLE hBuffer=NULL;
- unsigned char* pBuf=NULL;
-
- int width,height,size;
- int i,n=sizeof(int);
- unsigned char* ptr=NULL;
-
- // Image width
- recvncfrom( s, (void**)&pBuf, 0, (PSA)&sin1, &sz, &hBuffer );
- recvncfree( hBuffer );
- ptr=(unsigned char*)&width;
- for(i=0;i<n;++i) ptr=pBuf;
-
- // Image height
- recvncfrom( s, (void**)&pBuf, 0, (PSA)&sin1, &sz, &hBuffer );
- recvncfree( hBuffer );
- ptr=(unsigned char*)&height;
- for(i=0;i<n;++i) ptr=pBuf;
-
- // Image data size
- size=width*height;
-
- printf("Image Size: %d * %d
",width,height);
-
- // Data buffer
- unsigned char* data=(unsigned char*)malloc(size);
- if(data==NULL)
- {
- printf("Failed to allocate memory!
");
- return 2;
- }
-
- ptr=data;
- while(1)
- {
- nr=recvncfrom( s, (void**)&pBuf, 0, (PSA)&sin1, &sz, &hBuffer );
- if(nr<=0) break;
- total+=nr;
- for(i=0;i<nr;++i)
- {
- ptr=pBuf;
- }
- ptr+=nr;
- sendto( s, reply, hlen, 0, (PSA)&sin1, sz );
- recvncfree( hBuffer );
- }
-
- if(total!=size)
- {
- free(data);
- size=0;
- printf("Data transfer is imcomplete!
");
- return 1;
- }
-
- processDataFrame(data,width,height);
-
- total=0;
- int unit=64;
- int loop=size/unit;
- int residue=size-loop*unit;
- pBuf=data;
- for(i=1;i<=loop;++i)
- {
- nr=sendto(s,pBuf,unit,0,(PSA)&sin1, sz);
- pBuf+=unit;
- total+=nr;
- }
- if(residue>0)
- {
- nr=sendto(s,pBuf,residue,0,(PSA)&sin1, sz);
- total+=nr;
- }
- printf("Finished sending back %dB.
",total);
-
- free(data);
- return 1;
- }
-
- void processDataFrame(unsigned char* data,int width,int height)
- {
- printf("Processing data...");
- int i, size=width*height;
- unsigned char tmp;
- for(i=0;i<size;++i)
- {
- tmp=data;
- data=255-tmp;
- }
- printf("Finished.
");
- }
[color=rgb(51, 102, 153) !important]复制代码
发回数据时建议设置更小的分片大小,这里设置为64字节,实测效果尚可。
一周热门 更多>