We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I have a graduation project that should be done in 4 weeks and it includes motion tracking so I made a code that was not bad but still has problems..
I just knew recently about "blobscanner library" from Mr.adiarduino I have searched about it and it was much better than my code but the problem was that I could not find any code so I can learn it and make some tests on it so I understand it
So what I want is if you have a simple code any code that tracks moving objects using blobscanner library please give me it and I will understand it. or please check my current code and advice me on how to make the blue circle more stable and only following the center of the whole moving object.
here is my code:
import processing.video.*;
Capture video;
PImage prevFrame;
float threshold = 150;
int Mx = 0;
int My = 0;
int ave = 0;
int ballX = width/8;
int ballY = height/8;
int rsp = 5;
void setup() {
size(320, 240);
video = new Capture(this, width, height, 30);
video.start();
prevFrame = createImage(video.width, video.height, RGB);
}
void draw() {
if (video.available()) {
prevFrame.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
prevFrame.updatePixels();
video.read();
}
loadPixels();
video.loadPixels();
prevFrame.loadPixels();
Mx = 0;
My = 0;
ave = 0;
for (int x = 0; x < video.width; x ++ ) {
for (int y = 0; y < video.height; y ++ ) {
int loc = x + y*video.width;
color current = video.pixels[loc];
color previous = prevFrame.pixels[loc];
float r1 = red(current);
float g1 = green(current);
float b1 = blue(current);
float r2 = red(previous);
float g2 = green(previous);
float b2 = blue(previous);
float diff = dist(r1, g1, b1, r2, g2, b2);
if (diff > threshold) {
pixels[loc] = video.pixels[loc];
Mx += x;
My += y;
ave++;
}
else {
pixels[loc] = video.pixels[loc];
}
}
}
fill(255);
rect(0, 0, width, height);
if (ave != 0) {
Mx = Mx/ave;
My = My/ave;
}
if (Mx > ballX + rsp/2 && Mx > 50) {
ballX+= rsp;
}
else if (Mx < ballX - rsp/2 && Mx > 50) {
ballX-= rsp;
}
if (My > ballY + rsp/2 && My > 50) {
ballY+= rsp;
}
else if (My < ballY - rsp/2 && My > 50) {
ballY-= rsp;
}
updatePixels();
noStroke();
fill(0, 0, 255);
ellipse(ballX, ballY, 20, 20);
}
Answers
bump
really need this! got 2 weeks to finish my graduation project
Here is some links you might be interested
Somve other tutorials if you are interested but check above link first.
http://www.openprocessing.org/browse/?viewBy=tags&tag=motion detection
Some codes
http://www.openprocessing.org/sketch/34973
.............. :-B :-B :-B
this was so much help full and I found what I was looking for, thank you so so so so much for helping me this saved my project
(PS: i am now using processing openCV) Thank You again
Once I had the same situation and nobody responded me when I posted my code here so I understand how it feels.
And Your welcome :) :)
Dear Mimansoob,
I am from Indonesia, and I have seen the project of yours and try it on my computer. I have a project as well. I need a kind of visual sensors for my program. I have been looking for from so many sources on the internet and I do not get what I need..
When I saw your program I get what I need. Dear mimansoob, I want to ask you. Could I use the program you've made for my project? :) I would be very happy if you're willing, I'm waiting for your answer soon.
Thank you very much..
waw that is very helpful guys. I am not good enough in processing but i can understand how this is fascinated works and they help me learn many things. Thanks Mimansoob & Blyk
Dear Adnan_As yes you are free to use my code :),
Mr.Dnon I am glad that my code helped you ^_^
Dear Mimansoob please give me the code or paste the code here after you solve this problem