{"id":26716466,"url":"https://github.com/onlylemi/processing-android-capture","last_synced_at":"2025-04-14T01:25:51.802Z","repository":{"id":101122661,"uuid":"48174894","full_name":"onlylemi/processing-android-capture","owner":"onlylemi","description":"AndroidCapture For Processing","archived":false,"fork":false,"pushed_at":"2018-11-24T07:08:12.000Z","size":54621,"stargazers_count":145,"open_issues_count":5,"forks_count":30,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-27T15:31:39.365Z","etag":null,"topics":["android","creative-coding","processing","processing-library"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onlylemi.png","metadata":{"files":{"readme":"README-zh.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2015-12-17T13:06:34.000Z","updated_at":"2025-01-17T10:18:17.000Z","dependencies_parsed_at":"2023-05-24T12:00:22.355Z","dependency_job_id":null,"html_url":"https://github.com/onlylemi/processing-android-capture","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onlylemi%2Fprocessing-android-capture","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onlylemi%2Fprocessing-android-capture/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onlylemi%2Fprocessing-android-capture/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onlylemi%2Fprocessing-android-capture/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onlylemi","download_url":"https://codeload.github.com/onlylemi/processing-android-capture/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248805941,"owners_count":21164422,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","creative-coding","processing","processing-library"],"created_at":"2025-03-27T15:27:38.971Z","updated_at":"2025-04-14T01:25:51.774Z","avatar_url":"https://github.com/onlylemi.png","language":"Java","readme":"# AndroidCapture For Processing\n\n![Logo](https://raw.githubusercontent.com/onlylemi/res/master/processing-android-capture-logo.gif)\n\n\u003e * 已被 [processing.org](https://processing.org/reference/libraries/) 官方收录\n\u003e * 已被 [creativecoding.cn](http://creativecoding.cn/?p=587) 收录\n\u003e * 已被 [OF COURSE](http://mp.weixin.qq.com/s?__biz=MzA4NTc5MDU5OQ==\u0026mid=410954063\u0026idx=1\u0026sn=cd94026161ffc4862a4397571041d605\u00263rd=MzA3MDU4NTYzMw==\u0026scene=6#rd) 收录\n\n\n## Lib介绍\n\n这是一个有关 [processing](https://processing.org) 和 [android](https://android.com) 交互的`library`。通过`Android app`客户端获取手机的摄像头图像及各类传感器的数据通过局域网`WiFi`通信`socket`编程技术发送到`processing`服务端，服务端接受数据然后进行图像处理、数据应用。\n\n## WHY\n\n本是一只**程序猿**，由于开发 **android** 项目需求，无意中发现了 **processing** 这门语言，效果真是太赞了，本来打算用它来做 **ui/animation** 的，可是它的 android 的库不是很好，社区维护的又少之又少，也就放弃了使用。\n\n可是它的效果不得不佩服呀，简单的几句代码就可以勾勒出一幅优美的画面，做**可视化（我最喜欢做的）**又是如此方便，所以就拿 processing 玩起来了。前段时间做的一个**室内地磁导航 app**，在给大家讲地磁导航原理的时候讲了又讲，可是大家就是不明白，最后用做了一个简单地磁导航原理模拟动画，大家瞬间明白。在不断的尝试后，越来越喜欢这门语言，现在一有空就会拿出来玩玩。**手握程序，不仅可以写应用，还可以娱乐、画画，真是给程序猿枯燥的生活添加了一笔别样的色彩（“一只不务正业的程序猿”就这样来了）**。哈哈，程序猿也不是你想的那样无趣的，这样的多好啊！\n\n![室内导航原理模型](https://raw.githubusercontent.com/onlylemi/res/master/android-indoor-visual.gif)\n\n另外，大家都知道在 **processing** 里可以写程序直接采用 **android-mode** 执行，只要你的电脑中有 **android-sdk**，就可以在 android 手机上运行，但是大家觉得运行效果如何呢？我只想说还能不能再卡点呀，本来一幅优美的画面，硬生生的给你放成慢动作，还是超慢动作啊。另外，**[processing foundation](https://github.com/processing)** 对 **[processing-android](https://github.com/processing/processing-android)** 的维护的又很少，所以性能也就不是很令人满意。但是，作为一名android开发者，我认为android手机是个很好的东西啊，凭借它有丰富的**传感器**、**摄像头（本文的库就是干）**、**画板**以及它的可移动、灵活的特点，既然让它本身执行processing很卡，那为何不让它解放出来，只从它上获取数据，把数据交给processing pc端做处理呢？\n\n\u003e 12月13日下午1点-3点，来自财新数据可视化实验室的执行总监**[任远老师](http://yuanren.cc/)**在 **[OF COURSE](http://www.ofcourse.io/)** 给大家进行 [Live Coding+Music Visualization](http://e.vhall.com/686423389) 现场表演！期间，任远老师在做视频和音乐的互动时，即兴的将观众融入到了作品中，用手机将现场的观众录制下来，然后将录制的视频进行播放，通过摄像头和音乐进行了实时的互动，观众成为了 **live coding** 的一部分，同时观众也参与了作品的创作。live coding 并不是我一个人在写 code，而是大家和我一起完成code。 在这个环节中手机正好可以当做这个媒介，如果我可以拿着手机把手机拍摄到的画面可以实时传到processing中处理，而不是先在现场录制一段视屏然后再播放处理这样效果是不是更好呢?  \n**Live coding代码**：[https://github.com/onlylemi/MusicVisual](https://github.com/onlylemi/MusicVisual)\n\n正因为如此，我就决定开发一个 processing 和 android 交互的库，供大家来使用，同时，**作为一个只用p rocessing 从来就没给[foundation](https://github.com/processing) 捐赠过的人，写这样一个lib来为社区做点贡献，这样心里应该会好过点吧。。。**\n\n就这样这个库诞生了。我称它为 **AndroidCapture For Processing**。**capture** 包括**android** `camera`、`sensor`。\n\n废话不多说了，先看看 Android App 界面，然后给大家撸代码讲解。  \n\n## Android APP\n\n![androidcapture1](https://raw.githubusercontent.com/onlylemi/res/master/androidcapture1.jpg)  \nΔ  android 客户端 首页\n\n![androidcapture2](https://raw.githubusercontent.com/onlylemi/res/master/androidcapture2.jpg)  \nΔ  android 客户端 登录服务器界面（地址为 processing 服务端的本地ip地址，pc 端 cmd 进入命令行模式，输入 ipconfig 即可查看本地局域网 ip 地址）\n\n![androidcapture3](https://raw.githubusercontent.com/onlylemi/res/master/androidcapture3.jpg)  \nΔ  android 客户端 颜色识别界面\n\n![androidcapture4](https://raw.githubusercontent.com/onlylemi/res/master/androidcapture4.jpg)  \nΔ  android 客户端 传感器选择界面\n\n## 使用方法\n\n1. 首先你需要在 github 上去下载 AndroidCaptureForProcessing.jar 及 android 客户端 app  \n**android app 豌豆荚地址:** [http://wandoujia.com/apps/com.onlylemi.android.capture](http://wandoujia.com/apps/com.onlylemi.android.capture)\n2. 在手机上安装 app，processing 项目中导入 jar 包到 code 文件夹下\n3. pde 文件中调用。一下分为`camera`、`sensor`两种情况进行阐释\n\n\n### PAndroidCamera类\n\n* 获取图像 **getCameraImage()**\n* 获取颜色 **getColor()**\n\n#### 使用步骤\n\n1、导包\n\n```java\n// 导包\nimport com.onlylemi.processing.android.capture.*;\n```\n\n2、声明（**AndroidCamera类**）\n\n\n```java\n// 声明\nAndroidCamera ac;\nPImage img;\n```\n\n3、在 **setup** 函数中初始化，并且开启捕捉\n\n```java\nvoid setup() {\n    size(720, 480);\n    // 初始化对象\n    // 参数含义： width 图像的宽\n    //           height 图像的高\n    //           30 frame速率\n    ac = new AndroidCamera(width, height, 30);\n    ac.start();\n};\n```\n\n4、在 **draw** 函数中调用**getCameraImage()**函数获取图像\n\n```java\nvoid draw() {\n    // 获取图像\n    img = ac.getCameraImage();\n    image(img, 0, 0);\n}\n```\n```java\nvoid draw(){\n    translate(width / 2, height / 2);\n    // 获取颜色\n    int c = ac.getColor();\n    fill(c);\n    ellipse(0, 0, 300, 300);\n}\n```\n\n至此 **AndroidCamera** 类的功能就介绍完毕，具体效果在后面的实例中查看。\n\n### PAndroidSensor类\n\n* 提供Android手机的8大传感器  \n* 加速度传感器（SensorType.TYPE_ACCELEROMETER）  \n调用函数**getAccelerometerSensorValues()**  \n* 方向传感器（SensorType.TYPE_ACCELEROMETER）  \n调用函数**getOrientationSensorValues()**  \n* 地磁传感器（SensorType.TYPE_MAGNETIC_FIELD）   \n调用函数**getMagneticFieldSensorValues()**\n* 陀螺仪传感器（SensorType.TYPE_GYROSCOPE）  \n调用函数**getGyroscopeSensorValues()**\n* 光线传感器（SensorType.TYPE_LIGHT）  \n调用函数**getLightSensorValues()**  \n* 距离传感器（SensorType.TYPE_PROXIMITY）  \n调用函数**getProximitySensorValues()**\n* 压力传感器（SensorType.TYPE_PRESSURE）  \n调用函数**getPressureSensorValues()**\n* 温度传感器（SensorType.TYPE_TEMPERATURE）  \n调用函数**getTemperatureSensorValues()**\n\n#### 使用步骤\n\n1、导包\n\n```java\n// 导包\nimport com.onlylemi.processing.android.capture.*;\n```\n\n2、声明（**PAndroidSensor类**）\n\n```java\n// 声明\nAndroidSensor as;\n```\n\n3、在 **setup** 函数中初始化，并且开启数据捕捉\n\n```java\nvoid setup() {\n    size(720, 480);\n    background(0);\n    // 初始化对象\n    // 参数含义： 0 获取数据速率\n    as = new AndroidSensor(0);\n    as.start();\n}\n```\n\n4、在 **draw** 函数中调用相应函数进行数据获取（每种传感器数据获得都有两种方式）\n\n```java\nvoid draw() {\n    background(0);\n    fill(255);\n    textSize(15);\n    // 每种传感器都有两种方法获取数据\n    float[] values1 = as.getAccelerometerSensorValues();\n    float[] values1 = as.getSensorValues(SensorType.TYPE_ACCELEROMETER);\n    \n    float[] values2 = as.getOrientationSensorValues();\n    float[] values2 = as.getSensorValues(SensorType.TYPE_ORIENTATION);\n\n\n    float[] values3 = as.getMagneticFieldSensorValues();\n    float[] values3 = as.getSensorValues(SensorType.TYPE_MAGNETIC_FIELD);\n\n    float[] values4 = as.getGyroscopeSensorValues();\n    float[] values4 = as.getSensorValues(SensorType.TYPE_GYROSCOPE);\n\n    float values5 = as.getLightSensorValues();\n    float values5 = as.getSensorValues(SensorType.TYPE_LIGHT)[0];\n\n    float values6 = as.getProximitySensorValues();\n    float values6 = as.getSensorValues(SensorType.TYPE_PROXIMITY)[0];\n\n    float values7 = as.getPressureSensorValues();\n    float[] values7 = as.getSensorValues(SensorType.TYPE_PRESSURE);\n\n    float values8 = as.getTemperatureSensorValues();\n    float values8 = as.getSensorValues(SensorType.TYPE_TEMPERATURE);\n}\n```\n \n至此 **AndroidSensor** 类的功能就介绍完毕，具体效果在后面的实例中查看。\n\n## 具体示例\n\n代码1：[CameraImage](https://github.com/onlylemi/processing-android-capture/tree/master/examples/AndroidCamera/CameraImage)  \n效果1：  \n![CameraImage](https://raw.githubusercontent.com/onlylemi/res/master/processing-android-capture-camera_image.gif)\n\n---\n\n代码2：[CameraColor](https://github.com/onlylemi/res/master/examples/AndroidCamera/CameraColor)  \n效果2：  \n![CameraColor](https://raw.githubusercontent.com/onlylemi/res/master/processing-android-capture-camera_color.gif)\n\n---\n\n代码3：[AccSensor](https://github.com/onlylemi/processing-android-capture/tree/master/examples/AndroidSensor/AccSensor)  \n效果3：  \n![AccSensor](https://raw.githubusercontent.com/onlylemi/res/master/processing-android-capture-sensor_color.gif)\n\n--- \n\n代码4：[CameraMusic](https://github.com/onlylemi/processing-android-capture/tree/master/examples/AndroidCamera/CameraMusic)  \n效果4：  \n![CameraMusic](https://raw.githubusercontent.com/onlylemi/res/master/processing-android-capture-camera_music.gif)\n\n---\n\n代码5：[CameraPixel](https://github.com/onlylemi/processing-android-capture/tree/master/examples/AndroidCamera/CameraPixel)  \n效果5：  \n![CameraPixel](https://raw.githubusercontent.com/onlylemi/res/master/processing-android-capture-camera_pixel.gif)\n\n## END\n\n本篇文章中所有提到的代码都是该 **lib** 提供的[examples](https://github.com/onlylemi/processing-android-capture/tree/master/examples)，都可以在 **github** 上下载到，因为processing是由java语言实现的，所以整个项目我是采用 [IntelliJ IDEA](https://www.jetbrains.com/idea/) IDE所实现（强烈建议大家使用，写代码 so 爽），然后再转到 **processing** 下的。项目的android客户端使用 [Android studio](http://developer.android.com/sdk/index.html) 实现。所有代码都已开源到 **github** 上，欢迎大家指导批评。\n\nLib地址：[https://github.com/onlylemi/processing-android-capture](https://github.com/onlylemi/processing-android-capture)  \nIDEA原项目地址：[https://github.com/onlylemi/P5AndroidCapture](https://github.com/onlylemi/P5AndroidCapture)  \nAndroid APP地址：[https://github.com/onlylemi/AndroidCapture](https://github.com/onlylemi/AndroidCapture)\n\n## CONTACT\n\n**Weibo：** [@only乐秘](http://www.weibo.com/xiaomi0623)  \n**GitHub：** [@onlylemi](https://github.com/onlylemi)\n","funding_links":[],"categories":["Libraries"],"sub_categories":["Contributions"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonlylemi%2Fprocessing-android-capture","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonlylemi%2Fprocessing-android-capture","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonlylemi%2Fprocessing-android-capture/lists"}