搜索
bottom↓
回复: 33

鼠标也能成为摄像头

  [复制链接]

出0入0汤圆

发表于 2013-1-7 17:20:27 | 显示全部楼层 |阅读模式
一日看网络发现这个,modules:opticalmouse [Small Electronic Thingies for All Kinds of Fun Stuff]
http://wiki.edwindertien.nl/doku.php?id=modules:opticalmouse
// Getting to see what your mouse sees
// grabbing binary image data from the serial port
import processing.serial.*;
Serial port;
int pixelsize=20;
int x_size = 18;
int y_size = 18;
int pict;
String buff = "";
void setup(){
  size(pixelsize*x_size,pixelsize*y_size);
  println("Available serial ports:");
  println(Serial.list());
  port = new Serial(this, Serial.list()[0], 38400);
  port.buffer(x_size*y_size);
  frameRate(20);  // delay of 50 ms, 20Hz update
  background(255);
}
void draw(){
if (pict>0){ // if there's a picture
    for(int y=0;y<y_size;y++){
    for (int x=0;x<x_size;x++){
     fill(4*(byte)buff.charAt(y*y_size+x));
      rect(pixelsize*x,pixelsize*y,pixelsize*x+pixelsize,pixelsize*y+pixelsize);
      }
    }
  }
}  
void serialEvent(Serial port) {
  buff =port.readString();
  pict++;
}
--------------------------------------------------------------------------------------------
// inspired by Martijn The's sketch, adding all functionality of the 2610 chip, skipping
// the whole library-thing
#define SCLK 2  // Serial clock pin on the Arduino
#define SDIO 3  // Serial data (I/O) pin on the Arduino
#define sensorConfig 0x00
#define sensorStatus 0x01
#define Delta_Y        0x02
#define Delta_X        0x03
#define SQUAL   0x04
#define Maximum_pixel 0x05
#define Minimum_pixel 0x06
#define Pixel_Sum 0x07
#define picture 0x08
#define Shutter_MSB 0x09
#define Shutter_LSB 0x0A

unsigned char pixels[325];

void setup(){
  Serial.begin(38400);
  pinMode (SCLK, OUTPUT);
  pinMode (SDIO, INPUT);
  reSync();
  forceAwake(1); // LED on
}

void loop(){
    getPicture();  // take snapshot
    sendPicture(); // send the picture
    delay(100);
}
void reSync(){
  // ReSync (startup) mouse
  digitalWrite(SCLK, HIGH);                     
  delayMicroseconds(5);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);       
  // wait for OptiMouse serial transaction timer to time out:
  delay(1000);
}
void getPicture(void){
  writeRegister(picture,0); // default write: initiate picture transfer
  for (int x=0;x<18;x++){   // 18 rows of pixels
    for (int y=17;y>=0;y--){// 18 collumns (reverse order)
      unsigned char pix = readRegister(picture); // SPI read operation
      int timeout = 12;                          // Try 12 times max to
      while (!(pix & 0x40) && timeout>0){        // check for valid data
        pix = readRegister(picture);             // read the picture data
        timeout--;
      }
      pixels[x*18+y]=pix&0x3F; // store the data (might still be invalid after 12 tries) // was pix&0x2F
    }
  }
}
void sendPicture(void){
  for(int z=0;z<324;z++)  {
    Serial.print((unsigned char)(pixels[z]&0x3F)); // send block of 324 bytes //was pixels[z]&0x2F
  }
}
void forceAwake(char value){
  if (value>0) writeRegister(sensorConfig,0x01);
  else writeRegister(sensorConfig,0x00);
}
signed char getDx(void){
  return (signed char) readRegister(Delta_X);
}
signed char getDy(void){
  return (signed char) readRegister(Delta_Y);
}
signed int getShutter(void){
  signed int shutter = readRegister(Shutter_MSB) <<8;
  shutter += readRegister(Shutter_LSB); // + LSB
  return shutter;
}
uint8_t readRegister(uint8_t address){ // Bitbang SPI read operation
  int i = 7;
  uint8_t r = 0;
  pinMode (SDIO, OUTPUT);   // Write the address of the register we want to read:
  for (; i>=0; i--)  {
    digitalWrite (SCLK, LOW);
    digitalWrite (SDIO, address & (1 << i));
    digitalWrite (SCLK, HIGH);
  }
  pinMode (SDIO, INPUT);    // Switch data line from OUTPUT to INPUT
  delayMicroseconds(100);   // Wait according to datasheet
  for (i=7; i>=0; i--)        {     // Fetch the data!                          
    digitalWrite (SCLK, LOW);
    digitalWrite (SCLK, HIGH);
    r |= (digitalRead (SDIO) << i);
  }
  delayMicroseconds(100);
  return r;
}
void writeRegister(uint8_t address, uint8_t data){
   int i = 7;       
   // Set MSB high, to indicate write operation:
  address |= 0x80;       
  // Write the address:
  pinMode (SDIO, OUTPUT);
  for (; i>=0; i--){
    digitalWrite (SCLK, LOW);
    digitalWrite (SDIO, address & (1 << i));
    digitalWrite (SCLK, HIGH);
  }       
  // Write the data:
  for (i=7; i>=0; i--){
    digitalWrite (SCLK, LOW);
    digitalWrite (SDIO, data & (1 << i));
    digitalWrite (SCLK, HIGH);
  }
}
-----------------------------------------------------------------------------------

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

发表于 2013-1-7 17:23:29 | 显示全部楼层
看见过用鼠标扫描硬币的帖子。。。真实性没去验证过。。。

出0入0汤圆

 楼主| 发表于 2013-1-7 17:27:28 | 显示全部楼层
这个搞起来要多少钱

出0入0汤圆

发表于 2013-1-7 22:12:55 | 显示全部楼层
介于牛A和牛C之间

出0入0汤圆

发表于 2013-1-7 22:38:49 | 显示全部楼层
之前見過用鼠標做掃描儀的。

出0入34汤圆

发表于 2013-1-8 09:59:03 | 显示全部楼层
这个概念蛮有意思的..

出0入0汤圆

发表于 2013-1-8 10:46:25 | 显示全部楼层
这个有创意,挺好。。

出0入0汤圆

发表于 2013-1-8 11:10:20 | 显示全部楼层
便宜啊,实验材料好找!

出0入0汤圆

发表于 2013-1-8 11:21:55 | 显示全部楼层
介于牛A和牛C之间

出0入0汤圆

发表于 2013-1-8 11:23:33 来自手机 | 显示全部楼层
分辨率如何,还能成像?

出0入0汤圆

发表于 2013-1-8 11:27:21 | 显示全部楼层
这个能干什么用呢?

出0入0汤圆

发表于 2013-1-8 11:46:54 | 显示全部楼层
N年前就见过老外做扫描仪:
http://www.bidouille.org/hack/mousecam/index.php
http://spritesmods.com/?art=mouseeye

出0入0汤圆

 楼主| 发表于 2013-1-8 11:58:21 | 显示全部楼层
从商业角度来讲,性价比没有那个器件比这个更便宜,相当于18*18摄像头+dsp+单片机=1-3元,另外就是你的商业化视觉啦

出0入0汤圆

发表于 2013-1-8 12:42:09 来自手机 | 显示全部楼层
唉哟…这可是高精尖的货吖!

出0入0汤圆

发表于 2013-1-8 13:18:15 | 显示全部楼层
光电鼠标本身就是基于图像识别,本身就是靠拍照比对前后图像检测位移的

出0入0汤圆

发表于 2013-1-8 13:46:16 | 显示全部楼层
这个分辨率惨不忍睹吧

出10入210汤圆

发表于 2013-1-8 19:07:14 | 显示全部楼层
bbsview 发表于 2013-1-8 13:46
这个分辨率惨不忍睹吧

这个不是为了照像而折腾的。

出0入0汤圆

发表于 2013-1-9 08:40:08 | 显示全部楼层
这个有意思,好像的确有些用处。

出0入0汤圆

发表于 2013-1-9 08:50:38 | 显示全部楼层
应该可以用于某种识别方式?

出0入0汤圆

 楼主| 发表于 2013-1-9 08:56:44 | 显示全部楼层
bbssilverkey 发表于 2013-1-9 08:50
应该可以用于某种识别方式?

最广泛的应用应该是识别位移,另外配套合适的透镜应该可以用于简单的机器视觉,像素少,51单片机也可以处理

出0入0汤圆

发表于 2013-1-9 09:14:44 | 显示全部楼层
好东西。。。非常正。。。

出0入0汤圆

发表于 2013-1-9 12:29:25 | 显示全部楼层
有意思,很有趣

出0入0汤圆

发表于 2013-1-9 12:44:44 | 显示全部楼层
可以应用在别的场合。

出0入0汤圆

发表于 2013-1-9 13:15:56 | 显示全部楼层
这个拍照速率很高的,好像超过2000fps

出0入0汤圆

发表于 2013-1-9 15:05:27 | 显示全部楼层


去年5月分做的,显示的图像是办公室的窗子格子,18*18=324像素。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

 楼主| 发表于 2013-1-9 15:14:50 | 显示全部楼层
Delong_z 发表于 2013-1-9 15:05
去年5月分做的,显示的图像是办公室的窗子格子,18*18=324像素。

高手啊,买一个行不行

出0入0汤圆

发表于 2013-1-9 16:39:51 | 显示全部楼层
巧妙的图像扫描啊!

出0入0汤圆

发表于 2013-1-9 17:00:18 | 显示全部楼层
分辨率感觉是不高,但是也是一种方法,呵呵。。。

出0入0汤圆

发表于 2013-1-10 10:47:27 | 显示全部楼层

   思路不错,学习了,不过实用性还需进一步……

出0入0汤圆

发表于 2013-8-14 10:48:54 | 显示全部楼层
我估计是最节能的摄像头,也许可以加光学镜片更有用。

出0入0汤圆

发表于 2013-8-14 18:59:52 | 显示全部楼层
好强大 啊 ,鼠标原来还能这么用

出0入0汤圆

发表于 2013-8-14 19:05:20 来自手机 | 显示全部楼层
高端大气上档次

出0入0汤圆

发表于 2014-7-21 12:56:18 | 显示全部楼层
顶起,标记

出0入0汤圆

发表于 2014-7-21 14:09:21 | 显示全部楼层
好神奇,没有这么细心!
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-5 12:01

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表