moving detection without clik, for set point opencv

diez's picture

HI,

I'm new user of quartz composer, It's magic software for me. I don't know a lot of things in programming, but with a lot of logic, it's possible.

I discover open cv (it's difficult !) , is it possible to make an automatic setting of tracker point , without defining tracker point?

how to retrieve and use the attribute of the tracker? as the x, y ... I am looking for a kind of blob decoder like isadora

in brief : I want tracking a move, et retrieve the center of this moving, without clik

I think to be clear, sorry if my english it's not good...

diez's picture
probleme with "structure count patch"

I explore some composition, and I start to understand...

Just I have a probleme with "structure count patch"

Hi, I want to use the value given by "structure count patch", with a conditional patch, It doesn't work ? why ? How can I make this... ?

I think this value is not a numeric value ?? how can I transpose it ?

thx. diez

cwright's picture
Re: probleme with "structure count patch"

By "doesn't work", what do you mean?

The noodles attach (but are orange -- structure count is an Index (Integer), while Conditional expects a Number (Floting-point, or non-integer).

Are you testing for a specific value ("Equals")? That's a bad idea with floating point numbers unless you've got tolerance set a bit higher.

I'd write more, but I'm just going to expect you to post a composition before I go more in depth.

diez's picture
Re: probleme with "structure count patch"

OK , I upload my composition.

It's Kris harris composition, modified by S.Rozsa , and now by me...

I want keep the same point during the tracking, for make this:

If strucutre count is different to 0 , I stop the period

If strucutre count is 0, I enable the period ...

Now It's work but, how you say the noodle is orange...

And I have an other question, If I want calculate an average of x value of strucutre, how can I make this?

(x1+x2+x3+ .... + xn)/n

(make a snapshot of your cam in substract patch , witout moving or person)

PreviewAttachmentSize
motion_detection_diez.qtz49.52 KB

cwright's picture
Re: probleme with "structure count patch"

diez wrote:
Now It's work but, how you say the noodle is orange...

Orange noodles are ok.

diez wrote:
And I have an other question, If I want calculate an average of x value of strucutre, how can I make this?

(x1+x2+x3+ .... + xn)/n

To do this, you need to use javascript. Math Expression cannot loop or access structure members individually.

diez's picture
Re: probleme with "structure count patch"

ok,thanks

New problem for me, I don't know java...

You've some example or source for study this?

I re-upload my file, I have change difference with snapshot, with difference with n last frame ...

It's work nice ...

PreviewAttachmentSize
motion_detection_diez2.qtz25.89 KB

gtoledo3's picture
Re: moving detection without clik, for set point opencv

I'm thinking what you mean is that, you have to click with the mouse to set a point. You want motion to set the point, arbitrarily. Correct? No click. Just walk in front of cam and point generates. No walk in front of cam, no point?

Sorry if the conversation has progressed past this, haven't looked at the examples.

cwright's picture
Re: probleme with "structure count patch"

diez wrote:
New problem for me, I don't know java...

You've some example or source for study this?

Sing it with me:

"Java isn't JavaScript!" ;)

(I'm half-seriously considering adding code to KinemeCore that changes the JavaScript patch to be called "JAVASCRIPT, NOT FREAKING JAVA! HOLY CRAP!", but that'll make the patch really big... :)

Lucky for you, 26,746,521 people have asked about javascript in QC, so we've prepared this: https://kineme.net/wiki/JavaScriptInQuartzComposer

Additionally, http://www.quartzcompositions.com/phpBB2/mediawiki/index.php/JavaScript_... has some more information on JS in QC.

(I'm not trying to single you out, but this question comes up a lot, I'm not even joking)

diez's picture
Re: moving detection without clik, for set point opencv

yes It's that ;)

Now I put a java script in my composition,

I set input in : __structure I set outupt in : __number

How I can say to my patch , to use x, y value of One "point track" in java

Conversation have progress, and I don't seen your answer chris.. I see now

gtoledo3's picture
Re: probleme with "structure count patch"

Lol... MOST asked QC question Hall Of Fame.

Now that I've been messing with QC app based screen grab and Processing 135 and 146... totally underwhelmed :o/ It isn't nearly as cool as I "thought" it would be.

gtoledo3's picture
Re: moving detection without clik, for set point opencv

I remember looking at that about 6 or 7 months ago when kristopf posted the thing to clear points, and then I did something that used the clicks to add parts of a multi structure 3D object that would stick to your face...

I tried to use optical flow/ openCV/ other ideas to return a "true" if movement was detected, enabling a point. My problem was that I found that "numbers" get generated even when nothing is moving in front of a camera.

That said, I have different thoughts on this now. Thinking aloud, I'm wondering if I could have set something up with some math/tolerances/rounding, etc.... that would have reliably delivered the "true", or triggered iterations, or "something".

This has been in the back of my mind for quite awhile, so I'm likely to mess with it. If I get anything productive, I will post, but it is a mega hectic week for me. If anyone else does, even MORE awesome :o)

diez's picture
Re: moving detection without clik, for set point opencv

yes gtoledo, I use the same idea, and I take the information of structure count,

member = 0 automatik set point

member ≠ 0 stop automatik set point

Chris I have seen link that you give to me .. ok I start to understand this...It's ok for me for create a structure but how to use an already existing structure

My probleme now: how can exctract argument of structure? What's the syntax?

for x argument ? for y argument ?

how can I say : x of member1 , x of member2 ....

I know I'm newbies.....

cybero's picture
Re: moving detection without clik, for set point opencv

I've only just picked up on this now having just got back home.

If you want to study up regarding JavaScript in Quartz Composer then do please follow the links given above. Kineme Wiki

&

** QC3 JavaScript**

For a class by class reference [in English] you could go to Quartz Composer JavaScript Guide

If I get a spare moment this evening, I shall install the Open CV & Structure Maker & Official subpatches plugins that your composition requires to render and then take a peak inside your composition and see what might be needed so as to achieve what you want it to do.

diez's picture
Re: moving detection without clik, for set point opencv

Thx dude ;)

Auto set track point is ok, for this no probleme.

Now I want make an coordinate average of every tracker in composition, for these a lot of problem, I don't know javascript... but I work on it , the more big problème is the syntax...

this forum is very reactiv, thanks a lot ;)

diez's picture
decompose structure ok

Ok, I understand how to decompose a structure in QC, and use any value of this structure (with structure index member) .

Now I try the same in javascript...

diez's picture
make an average of value in javascript is OK, but...

Now , it's ok for make a loop in javascript.

But my probleme, is I don't retrieve the name of the object of outputPoint's structure (optical flow)

see attach image

For this how I must write for use X value of Members 0 ?

thx for your help...

PreviewAttachmentSize
Picture 3.png
Picture 3.png415.52 KB

Lango's picture
Re: make an average of value in javascript is OK, but...

Hi diez

I'm not sure if you have solved this yet. But if you are looking for the average then connect the output that has the structure into a javascript patch.

The javascript patch should have code similar to below. This is from my last QC I made, which i'm pluggin right now :)

var X_INDEX = 0;
var Y_INDEX = 1;
var oldX = 0;
var oldY = 0;
 
function (__number averageX, __number averageY, __boolean anyPoints) main (__structure points, __number numberOfPointsLimit) {
   myResult = new Object;
   myResult.anyPoints = false;
   myResult.numberOfPoints = points == null ? 0 : points.length;
   myResult.averageX = 0;
   myResult.averageY = 0;
 
   var count;
   for (count = 0; count < myResult.numberOfPoints; count++)
   {
      myResult.averageX += points[count][X_INDEX];
      myResult.averageY += points[count][Y_INDEX];
   }
 
   // find average
   numberOfPointsLimit = numberOfPointsLimit < 0 ? 0 : numberOfPointsLimit;
   if (count > numberOfPointsLimit)
   {
      myResult.averageX /= count;
      myResult.averageY /= count;
      myResult.anyPoints = true;
   }
   else
   {
      myResult.anyPoints = false;
      myResult.averageX = oldX; // use old points
      myResult.averageY = oldY;
   }
 
 
   oldX =  myResult.averageX;
   oldY = myResult.averageY;
 
   return myResult;
}

This code will accept the structure from the 'OpenCV Calc Optical Flow PyrLK' patch (which is what i think you are using) then find the average x and y of all the points as long as there are more points than what is set in the 'numberOfPointsLimit' input.

Its output will be averageX, averageY, and anyPoints. anyPoints will be true when there are points available and false when not. You could use this to turn on and off a billboard.

My recommendation would be to read the pages linked above and start to muck around with this code. It will be the best way to learn.

If you need any more help about this please just ask, i'll keep an eye on this post.

Regards

diez's picture
Re: moving detection without clik, for set point opencv

Hi, Sorry for this delay, I'm just back to my home, thanks lango, It's work fine now ;) . I was not far to hit. Javascript that I tried was on the same principle, without operating as long as ... I understand better how to use javascript, thank you.

PreviewAttachmentSize
motion_detection.zip27.76 KB