rollover between object; embedding event on object?

Hello everyone!

I’m not sure if anyone here already built this ‘facility’.

Actually I need to have an object, that could ‘detect’ if any other objects ‘inside’ it (just like ‘rollover’ event); Can we ‘embed’ an object with ability to trap ‘event’?

For example, as shown in the image below, we have the ‘circle cursor’; each object in the screen will give appropriate response when this cursor ‘touch’ them.

Thank you!

Dio

I don’t mean to be rude but you really need to explain this a little better for me to understand what your question is.

Oops, I’m sorry ding! (I have problem for explaining things)

For example, we have “time frame” like above picture (t=0 is the initial time, t=1,t=2 is the next two frames). And we have two objects, P and obj_1.

I’m interested to detect the event as shown in t=2 (or if only small part of P inside the obj_1)

I want to know if there any possibility to let the obj_1 ‘fire’ an event that object P is inside the obj_1 (as shown at t=1). Or, give the object P ability to ‘aware’ that it is inside a specific object.

(actually it is the same as the case of ‘rollover-event’ on mouse as in Flash actionscript, but in this case the ‘mouse’ is considered as an object).

*Oh no! I cannot explain it clearer. I really beg for apologize for this. I’m sorry*.

Thank you for your time reading this ‘unclear’ explanation. But I hope you can get the points.

Dio

hi,

I’ll give a short explanation for how I would do this, but then I think I can code a demo if I have a moment tomorrow. I thought I’d jump in just with an explanation first at least.

the easiest way to do this is to draw the two regions into two images, as white pixels on a black background (ie, binary image). this is easiest done with the opencv addon. then look at a third image which is the & operation of the two, which will show you only the pixel that are overlapped. you can then count the number of overlapped pixels and compare it to the number of hit region pixels, to get a percentage, like 90% of the hit region covered, etc. you can then decide what constitutes a hit.

on a technical level, the ofxCvGrayscaleImage has a great function called drawblobIntoMe(…). The trick to draw a hit region which is vertor (say, a set of points that define a circle), is to make a fake blob and add the points you want to test into that and draw it into an image. Alternatively, you can define your hit regions as images, and load them into grayscale images. Either method would work.

I’ve used this technique before, and it’s super reliable.

I hope that helps!

take care,
zach

That was a lot clearer. Don’t apologize. I am guilty of the same thing quite often. I was just trying to help you get some help. I like the images. I am also a visual learner. :smiley:

Thank you zach!

I’ll give it a try!!! And I’m looking forward to see your demo on this… :slight_smile:

cheers,

Dio

is the paul bourke solution a posibility for you:
http://www.openframeworks.cc/forum/view-…-ght=inside

here’s an implementation of the intersection approach, which looks at the intersection (ie, & / AND) between a background subtracted image and two “objects”, it calculates the % of overlap, which could be used as a basis for a trigger, etc.

this is a 0.05 mac fat example, (but you can add the src / data to any 0.05 package). it requires the opencv addon, so base it on that example if you are on CB, linux, etc.

http://www.openframeworks.cc/files/exam-…-xample.zip

hope that helps!!
zach[/img]

Thank you ding! (I had to search in the forum first before I ask this question);

zach! your example inspired me so much! Thank you!

cheers

Dio

here’s an implementation of the intersection approach, which looks at the intersection (ie, & / AND) between a background subtracted image and two “objects”, it calculates the % of overlap, which could be used as a basis for a trigger, etc.

this is a 0.05 mac fat example, (but you can add the src / data to any 0.05 package). it requires the opencv addon, so base it on that example if you are on CB, linux, etc.

http://www.openframeworks.cc/files/exam … xample.zip

hope that helps!!
zach[/img]

hey zach i run this code and in this part

  
	ofxCvBlob tempBlob;  
	tempBlob.pts.push_back(ofPoint(40,40));  
	tempBlob.pts.push_back(ofPoint(90,40));  
	tempBlob.pts.push_back(ofPoint(90,180));  
	tempBlob.pts.push_back(ofPoint(40,180));  
	tempBlob.nPts = tempBlob.pts.size();  
	objAImg.set(0);  
	objAImg.drawBlobIntoMe(tempBlob, 255);  
  
  
	// make a moving circle for B,  
  
	tempBlob.pts.clear();  
	for (int i = 0; i < 20; i++){  
  
		float radius = 20;  
		float centerx = 160 + 40 * sin(ofGetElapsedTimef());  
		float centery = 120;  
		float x = centerx + radius * cos((float)i/19.0f * (TWO_PI));  
		float y = centery + radius * sin((float)i/19.0f * (TWO_PI));  
		tempBlob.pts.push_back(ofPoint(x,y));  
	}  
	tempBlob.nPts = tempBlob.pts.size();  
	objBImg.set(0);  
    objBImg.drawBlobIntoMe(tempBlob, 255);  
  
    bool bNewFrame = false;  

appear error: ‘class ofxCvGrayscaleImage’ has no member named ‘drawBlobIntoMe’

do you now how can fix this problem

argh, looks like that got lost in changes to 0.06 … in the meantime, can you copy the code from FAT 0.05 ofxCvGrayscaleImage (both in the .h and .cpp) for drawBlobIntoMe() and paste it into your 0.06 ofxCvGrayscaleImage ? we will update it for 0.061…

take care,
zach

ok it works perfect…

yhx again zach