养生 装修 购物 美食 感冒 便秘 营销 加盟 小吃 火锅 管理 创业 搭配 减肥 培训 旅游

网络识图,delphi识别,百度图片

时间:2024-11-06 14:00:52

网络图片识别,根据网络图片链接识别图片,是使用百度图片识别

网络识图,delphi识别,百度图片

工具/原料

delphi

jpg网络图片链接

方法/步骤

1、放置2个button,2个edit,2个image

网络识图,delphi识别,百度图片

2、button1的过程varms:TMemoryStream;jpg:TJPEGImage;begintryjpg:=TJPEGImage.Create;ms:=TMemoryStream.Create;idhtp1.Get(edt1.Text,ms);ms.Position:=0;jpg.LoadFromStream(ms);img1.Picture.Assign(jpg);jpg.SaveToFile('c:\123.jpg');exceptms.Free;end;

3、but隋茚粟胫ton2的过程,即是识别图片过程,这个过程完全模拟百度上传图片识别vari:Integer;pd:tstringlist;s,霜杼厮贿sName,sUrljpg:string;ms,ms1:TStringStream;jpg:TJPEGImage;//Cookies:TIdCookieManager;mstrCookie:string;begintryjpg:=TJPEGImage.Create;ms:=TStringStream.Create('');ms1:=TStringStream.Create('');img1.Picture.Bitmap.SaveToStream(ms);idhtp1.Request.UserAgent:='Mozilla/5.0(WindowsNT6.3;WOW64;Trident/7.0;rv:11.0)likeGecko';idhtp1.Request.AcceptLanguage:='zh-Hans-CN,zh-Hans;q=0.8,en-US;q=0.7,en;q=0.5,es-DO;q=0.3,es;q=0.2';begins:=(idhtp1.Post('http://image.baidu.com/pictureup/uploadshitu?'+'fr=flash&fm=index&pos=upload',mps));s:=(idhtp1.Get('http://image.baidu.com'+s));sName:=GetStringBetween(s,'guessWord','.split');sName:=Trim(StringReplace(sName,'''','',[rfReplaceAll]));sName:=Trim(StringReplace(sName,':','',[rfReplaceAll]));sUrljpg:=GetStringBetween(s,'<imgclass="guess-newbaike-left-img"src="','<divclass="guess-newbaike-left-similarity">');sUrljpg:=Trim(StringReplace(sUrljpg,'amp;','',[rfReplaceAll]));sUrljpg:=Trim(StringReplace(sUrljpg,'</div>','',[rfReplaceAll]));sUrljpg:=Trim(StringReplace(sUrljpg,'">','',[rfReplaceAll]));//sUrljpg:=TIdURI.URLDecode(sUrljpg);idhtp1.Request.UserAgent:='';mstrCookie:='aaa=5555&bb=12345';idhtp1.Request.AcceptEncoding:='';ifmstrCookie<>''thenbeginidhtp1.Request.CustomHeaders.Add('Cookie:'+mstrCookie);end;idhtp1.Request.Referer:='https://www.baidu.com';idhtp1.Request.UserAgent:='Mozilla/5.0(WindowsNT6.3;WOW64;Trident/7.0;rv:11.0)likeGecko';idhtp1.Get(sUrljpg,ms1);ms1.Position:=0;jpg.LoadFromStream(ms1);img2.Picture.Assign(jpg);edt2.Text:='我猜您的图片是:'+Utf8ToAnsi(sName);//ShowMessage(sUrljpg);end;exceptMPS.Free;ms.Free;ms1.Free;end;

4、必要的过程,取字符串与字符串中间的字符functionGetStringB娣定撰钠etween(constFul造婷用痃lStr,StrLeft,StrRight:String):string;varidx_Start,idx_End,iStrCnt:Integer;beginResult:='';idx_Start:=Pos(StrLeft,FullStr)+Length(StrLeft);idx_End:=Pos(StrRight,FullStr);iStrCnt:=idx_End-idx_Start;Result:=Copy(FullStr,idx_Start,iStrCnt);end;

网络识图,delphi识别,百度图片

© 一点知识