问题描述
初学者一个,请问下下面的程序怎样修改可以提高视频的帧数,现在连接摄像头读图像帧数太低,一卡一卡的,谢谢![code=csharp]/***************************************************************************************summary:字节数组生成图片**************************************************************************************/privateImagebyteArrayToImage(byte[]Bytes,intcount){using(MemoryStreamms=newMemoryStream(Bytes,0,count)){ImageoutputImg=Image.FromStream(ms);returnoutputImg;}}/***************************************************************************************summary:获取视频流**************************************************************************************/privatevoidGetStream(stringUriString){HttpWebRequestrequest=null;HttpWebResponseresponse=null;Streamstream=null;System.DateTimetime;intfps=0;constintbufSize=512*1024;//视频图片缓冲byte[]jpg_buf=newbyte[bufSize];//buffertoreadjpgconstintreadSize=10;//每次最大获取的流byte[]buffer=newbyte[readSize];//buffertoreadstreamwhile(true){try{time=System.DateTime.Now;fps=0;request=(HttpWebRequest)System.Net.WebRequest.Create(UriString);response=(HttpWebResponse)request.GetResponse();intread;intstatus=0;intjpg_count=0;//jpg数据下标while(true){stream=response.GetResponseStream();if((read=stream.Read(buffer,0,readSize))>0){for(inti=0;i<read;i++){switch(status){//Content-Length:case0:if(buffer[i]==(byte)'C')status++;elsestatus=0;break;case1:if(buffer[i]==(byte)'o')status++;elsestatus=0;break;case2:if(buffer[i]==(byte)'n')status++;elsestatus=0;break;case3:if(buffer[i]==(byte)'t')status++;elsestatus=0;break;case4:if(buffer[i]==(byte)'e')status++;elsestatus=0;break;case5:if(buffer[i]==(byte)'n')status++;elsestatus=0;break;case6:if(buffer[i]==(byte)'t')status++;elsestatus=0;break;case7:if(buffer[i]==(byte)'-')status++;elsestatus=0;break;case8:if(buffer[i]==(byte)'L')status++;elsestatus=0;break;case9:if(buffer[i]==(byte)'e')status++;elsestatus=0;break;case10:if(buffer[i]==(byte)'n')status++;elsestatus=0;break;case11:if(buffer[i]==(byte)'g')status++;elsestatus=0;break;case12:if(buffer[i]==(byte)'t')status++;elsestatus=0;break;case13:if(buffer[i]==(byte)'h')status++;elsestatus=0;break;case14:if(buffer[i]==(byte)':')status++;elsestatus=0;break;case15:if(buffer[i]==0xFF)status++;jpg_count=0;jpg_buf[jpg_count++]=buffer[i];break;case16:if(buffer[i]==0xD8){status++;jpg_buf[jpg_count++]=buffer[i];}else{if(buffer[i]!=0xFF)status=15;}break;case17:jpg_buf[jpg_count++]=buffer[i];if(buffer[i]==0xFF)status++;if(jpg_count>=bufSize)status=0;break;case18:jpg_buf[jpg_count++]=buffer[i];if(buffer[i]==0xD9){status=0;//jpg接收完成this.Invoke((EventHandler)delegate{fps++;image=byteArrayToImage(jpg_buf,jpg_count);map=newBitmap(image);Image<Bgr,byte>img=newImage<Bgr,byte>(map);map=img.ToBitmap();img_src=newImage<Bgr,Byte>(map);img_show=screen(img_src);img_show=imageMatch(img_show,img_tem);if(System.DateTime.Now>=time.AddSeconds(1)){label2.Text=fps.ToString()+"fps";fps=0;time=System.DateTime.Now;}});}else{if(buffer[i]!=0xFF)status=17;}break;default:status=0;break;}}}}}catch(Exception){//textBox2.Text=ex.Message;if(request!=null){request.Abort();request=null;}//closeresponsestreamif(response!=null){response.Close();response=null;}//closeresponseif(stream!=null){stream.Close();stream=null;}}}}/code]
解决方案
解决方案二:
我靠,头一次看见这样读ContentLength的,response里就有啊。。。
解决方案三:
引用1楼shingoscar的回复:
我靠,头一次看见这样读ContentLength的,response里就有啊。。。
能给个大致思路吗?因为这个程序是X宝卖家给的,不是很明白