Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 4800|回復: 5
打印 上一主題 下一主題

有關於熱影像arduino矩陣問題

[複製鏈接]
跳轉到指定樓層
1#
發表於 2018-3-28 13:59:04 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
大家好 ,目前在做有關熱影像的問題
想請問大家 如何把熱影像的讀值轉為矩陣 並且找出最大值的位置和最大值
謝謝
(這是原始的程式檔 )
#include <Wire.h>
#include <Adafruit_AMG88xx.h>

Adafruit_AMG88xx amg;

float pixels[AMG88xx_PIXEL_ARRAY_SIZE];

void setup() {
    Serial.begin(9600);
    Serial.println(F("AMG88xx pixels"));

    bool status;
   
    // default settings
    status = amg.begin();
    if (!status) {
        Serial.println("Could not find a valid AMG88xx sensor, check wiring!");
        while (1);
    }
   
    Serial.println("-- Pixels Test --");

    Serial.println();

    delay(100); // let sensor boot up
}


void loop() {
    //read all the pixels
    amg.readPixels(pixels);

    Serial.print("[");
    for(int i=1; i<=AMG88xx_PIXEL_ARRAY_SIZE; i++){
      Serial.print(pixels[i-1]);
      Serial.print(", ");
      if( i%8 == 0 ) Serial.println();
    }
    Serial.println("]");
    Serial.println();

    //delay a second
    delay(1000);
}
2#
發表於 2018-3-28 16:49:40 | 只看該作者
本帖最後由 超新手 於 2018-3-28 17:03 編輯

定義兩個變數
一個是最大值max,一個是最大值的指標index
在for迴圈先給初始值
max=pixels[0];
index=0;
然後在迴圈內, 一個一個和 Max 比
如果值pixels[ i-1]比Max 大,
就更新 Max 的值為pixels[ i-1], 同時更新 Index 的值為 i-1,
一共比 AMG88xx_PIXEL_ARRAY_SIZE 次
最後就可取得最大值Max和它的位置index
3#
 樓主| 發表於 2018-4-9 14:11:35 | 只看該作者
超新手 發表於 2018-3-28 16:49
定義兩個變數
一個是最大值max,一個是最大值的指標index
在for迴圈前先給初始值


你好 謝謝你 我想在請問一下 因為跑出來的結果是8*8的矩陣
再從矩陣中找最大值和最大值位置  比如30為最大值,那30的位置為[2,3],那這樣如何改 謝謝
4#
發表於 2018-4-9 15:09:20 | 只看該作者
跑出來的並不是8x8的二維矩陣
而是一個 64 BYTES 的一維矩陣
只是在印出來的時候, 把它 8 個印一行
所以你才以為你拿到的是二維矩陣

其實只要把 Index /8 和 Index %8
也就是分別取 Index 的商和餘數
就是你要的 行和列值
5#
 樓主| 發表於 2018-4-9 15:24:06 | 只看該作者
超新手 發表於 2018-4-9 15:09
跑出來的並不是8x8的二維矩陣
而是一個 64 BYTES 的一維矩陣
只是在印出來的時候, 把它 8 個印一行

那可以請問要在哪裡該程式嗎 謝謝
這是修改過可是還是跑不出來的




#include <Wire.h>
#include <Adafruit_AMG88xx.h>

Adafruit_AMG88xx amg;

float pixels[AMG88xx_PIXEL_ARRAY_SIZE];

void setup() {
    Serial.begin(9600);
    Serial.println(F("AMG88xx pixels"));

    bool status;
   
    // default settings
    status = amg.begin();
    if (!status) {
        Serial.println("Could not find a valid AMG88xx sensor, check wiring!");
        while (1);
    }
   
    Serial.println("-- Pixels Test --");

    Serial.println();

    delay(100); // let sensor boot up
}


void loop() {
    //read all the pixels
    amg.readPixels(pixels);

    Serial.print("[");

   int max=pixels[0];
   int Index=0;
    for(int i=1; i<=AMG88xx_PIXEL_ARRAY_SIZE; i++){
      //Serial.print(pixels[i-1]);
      //Serial.print(", ");
      if( pixels[i-1]>max )
       max=pixels[i-1];
       Index=i-1;
       Serial.print(max);
       Serial.print(",   ");
       Serial.print(Index);
      Serial.print("   ");
    }
   
   
   
    //Serial.println("]");
    //Serial.println();

    //delay a second
    delay(1000);
}
6#
發表於 2018-4-9 15:41:03 | 只看該作者
本帖最後由 超新手 於 2018-4-9 15:43 編輯

for(int i=0; i< AMG88xx_PIXEL_ARRAY_SIZE; i++){
      if( pixels[ i]>max )  {
       max=pixels[ i];
       Index=i;
      }
    }
    Serial.print(max);
    Serial.print(",   ");
    Serial.println(Index);
1.   沒括號
2. 全部算完的 MAX, 才是對的...
3. 可以讓 i = 0 ~AMG88xx_PIXEL_ARRAY_SIZE-1,
    程式比較簡單
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-4-19 14:10 , Processed in 0.067612 second(s), 7 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表