⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ocvtr2.pde

📁 motion detection made in processing. it detects motion in stream taken from webcam using OpenCV spec
💻 PDE
字号:
import hypermedia.video.*; // Imports the OpenCV libraryOpenCV opencv; // Creates a new OpenCV ObjectPImage trailsImg; // Image to hold the trailsint hCycle; // A variable to hold the hue of the image tintvoid setup(){size( 320, 240 );opencv = new OpenCV( this ); // Initialises the OpenCV objectopencv.capture( 320, 240 ); // Opens a video capture streamtrailsImg = new PImage( 320, 240 ); // Initialises trailsImghCycle = 0; // Initialise hCycle}void draw(){opencv.read(); // Grabs a frame from the cameraPImage camImage; // Creates an image andcamImage = opencv.image(); // stores the unprocessed camera frame in itopencv.absDiff(); // Calculates the absolute differenceopencv.convert( OpenCV.GRAY ); // Converts the difference image to greyscaleopencv.blur( OpenCV.BLUR, 3 ); // I like to blur before taking the difference image to reduce camera noiseopencv.threshold( 20 );trailsImg.blend( opencv.image(), 0, 0, 320, 240, 0, 0, 320, 240, SCREEN ); // Blends the movement image with the trails imagecolorMode(HSB); // Changes the colour mode to HSB so that we can change the huetint(color(hCycle, 255, 255)); // Sets the tint so that the hue is equal to hcycle and the saturation and brightness are at 100%image( trailsImg, 0, 0 ); // Display the blended difference imagenoTint(); // Turns tint offcolorMode(RGB); // Changes the colour mode back to the defaultblend( camImage, 0, 0, 320, 240, 0, 0, 320, 240, SCREEN ); // Blends the original image with the trails imageopencv.copy( trailsImg ); // Copies trailsImg into OpenCV buffer so we can put some effects on itopencv.blur( OpenCV.BLUR, 4 ); // Blurs the trails imageopencv.brightness( -20 ); // Sets the brightness of the trails image to -20 so it will fade outtrailsImg = opencv.image(); // Puts the modified image from the buffer back into trailsImgopencv.remember(); // Remembers the current framehCycle++; // Increments the hCycle variable by 1 so that the hue changes each frameif (hCycle > 255) hCycle = 0; // If hCycle is greater than 255 (the maximum value for a hue) then make it equal to 0}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -