Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to capture Mini Program visually by processing

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "processing how to achieve visual capture Mini Program". In daily operation, I believe many people have doubts about how to achieve visual capture of Mini Program by processing. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to achieve visual capture of Mini Program by processing". Next, please follow the editor to study!

Write a simple visual grab Mini Program with processing: identify the red, blue and green blocks and grab them sequentially.

Import processing.serial.*;import processing.video.*;Serial Port;Capture cam;float [] [] kernel = {{0.111, 0.111, 0.111, 0.111}, 0.111, 0.111, 0.111} / / convolution kernel / / the gray value of the middle pixel is equal to the red component of the surrounding pixel minus the average value of the blue-green component / / so that the gray value of the pixel without red feature becomes zero / / equivalent to the effect of the filter. Modify the parameters of the convolution kernel to achieve a different effect int sub_x=0,sub_y=0;// the pixel coordinates of the center of the object float pre_x=0,pre_y=0 / / the pixel coordinates of the center of the object in the previous frame float tar_x=80,tar_y=80;// target coordinates, the coordinates of the manipulator boolean event=false;// to calculate the event int / initialization {String portName = Serial.list () [0]; Port = new Serial (this, portName, 115200); / / connect serial port size (640480); / / screen size String [] cameras = Capture.list (); printArray (cameras) / / print usable camera cam = new Capture (this, cameras [0]); cam.start (); / start camera frameRate (30); / / frame rate Port.write ("G5B90\ r\ n"); Port.write ("G28\ r\ n"); Port.write ("G1 X80 Y80 Z40\ r\ n"); Port.write ("G5B50\ r\ n"); / / move to initial position delay (6000) / / delay to avoid fluctuations when the camera is first turned on} void draw () / / cycle {if (cam.available () = = true) {cam.read (); image (cam, 0,0, width, height); cam.loadPixels (); int sum_x=0,sum_y=0;// all red pixel coordinates and the number of int pixels / for (number of red pixels / number of red pixels for) & 0xFF Int B = cam.pixels [pos] & 0xFF; float val=0; switch (c) / / Sequential grabbing of red, blue and green blocks {case 0: val= Rmur1.5; break; case 1: val= Bmur1.5; break Case 2: val = Gmi 0.5; BMI 1R; break;} / / 1.5 is the proportion factor, which can be changed to make the red more prominent sum + = Kernel [Ky + 1] [kx+1] * val. / / calculate the grayscale value} if (sum > 0) / / the new grayscale value is non-zero {sum_x=sum_x+x; sum_y=sum_y+y;// accumulative coordinates sub_x=sum_x/m of the object center of the previous frame of pre_x=sub_x; pre_y=sub_y;// Sub_y=sum_y/m;// takes the average and calculates the pixel coordinates of the center of the object cam.updatePixels (); fill (# FF0000);} line (sub_x,0,sub_x,480); line. / / make two intersecting lines if (abs (sub_x-pre_x) 5) in the center of the object / / determine whether the object is moving (the fluctuation is less than 5 pixels is still) and whether there is an object (default is 0 when there is no object, set here to 5 to avoid fluctuation) {if (event==true) / / if the object exists, the manipulator is at rest and the event is triggered Then calculate {tar_x=tar_x- (0.0625*sub_x-20) Tar_y=tar_y- (15-0.0625*sub_y); / / convert pixel coordinates to absolute coordinates, and close the calculation event according to the actual scale of event=false;//, that is, calculate Port.write only once ("G1 X" + tar_x+ "Y" + tar_y+ "\ r\ n"); / / move to the target location delay (100) / / delay, reduce fluctuation} else / / if the manipulator is moving, the calculation event is triggered, but the calculation is not performed to prepare for the calculation when the manipulator is at rest event=true; / * due to the delay in the communication and movement of the manipulator, the speed is far less than that of the image recognition by the camera, so let the manipulator calculate only once when it is at rest * / if (sub_x

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report