Delphi: How to tag photos the way facebook does

混江龙づ霸主 提交于 2019-12-03 21:53:37

The key parameters of the API you cited are the picture ID, the coordinates, and the tag. The tag can be either the user ID of a Facebook user, or it can be free-form text (for the case when the tagged subject is not a Facebook user). Facebook uses just one coordinate because it uses fixed-size regions to denote a tagged area; the idea is that you click on the center of a person's face, and Facebook just stores that point.

If you display a picture in a TImage control (that's the obvious first choice, after all), you can detect mouse clicks with the OnMouseDown and OnMouseUp events. (The OnClick event is simpler, but doesn't tell you the coordinates.) Once you've acquired a point, prompt for a label to accompany that point. You can use predetermined labels, like Facebook's user IDs, or just use ordinary text, or use something of your own devising. The question of what you use to represent a tag value is orthogonal to whatever other questions you've asked so far.

The other half of Facebook's photo tagging is that moving the mouse over the image displays the tag text over the image, and moving the mouse over the labels below highlight the associated regions. Handle OnMouseMove events and write some code to display or hide labels and shapes as appropriate. If you use TLabel and TShape, you might not even have to modify the image, but showing those controls on top of the image might interfere with further OnMouseMove events for the image. It shouldn't take too long to try some experiments and see what works for you.

lkessler, I just read your reply to Marshall Fryman, so may have a couple options for you:

THotSpotImage - If you already have TMS components...

ImageEn - in case you already have them...

See w2m's answer #3 i think in further i need get all inner pixels of my selections, so how i can save my selections/objects ?

Save selection just saves the selection itself. It does not save the image inside of the selection:

procedure SaveSelectionToFile(const FileName:string); SaveSelectionToFile saves the current selection to the specified file. Example ImageEnView1.Select(10,10,100,100); ImageEnView1.SaveSelectionToFile('selection1'); .. sel1.Position:=0; ImageEnView1.LoadSelectionFromFile('selection1'); // this is like Select(10,10,100,100)

I'm a bit confused as to your question. Are you trying to interact with Facebook or just copy the functionality?

If you are trying to copy the functionality: You should be able to just display the image, let the user select the rectangle, possibly copy the image to a new copy to notify the other person with, and apply a tag in a DB. Some helpful links: here is a select image example and here is the copy image portion example. I'd actually think you could do the select image in a paintbox but haven't actually played with one of those in forever.

If you are trying to access the API: The .NET interface may work for you. From what I can tell, there is no COM interface so you'd have to write your own connector or use a .NET Delphi app. Note: all of this information is coming from Google so I won't swear up and down that it's really the current state of things. The only other Facebook API request I saw was from 2007.

If you want to do automatic face recognition, OpenCV from the referenced question looks like a decent way to do it (especially if you have access to C++ Builder).

In the Graphic32-library, you can have several layers upon each other in a image. One of the layers that is provided out of the box, is a TRubberbandLayer that allows the user to reposition/resize the layer at runtime.

The mousemove event for the TImage32-component, has a parameter that gives the layer currently under the cursor.

type TImgMouseMoveEvent = procedure(Sender: TObject; Shift: TShiftState; X, Y: Integer; Layer: TCustomLayer) of object;

A combination of rubberbandlayers and the mousemove-event should be good solution, I think.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!