• 概要
  • SERファイルまたは撮影画像から流星を検出します。
    SERはPCで処理、撮影画像はRaspberryPiで処理することを考えています。
    データは2023/08/13-14のものです。



  • リアルタイム版デモ


  • バッチ版デモ
  • マスク(作成のしやすさから黒塗エリアを有効範囲にしています)

    検出データの積算(一覧のしやすさから出力しています)

    検出データ(最終的な目視確認のため)

    一覧表
    Frame NoMeteor NoPathFrame No In FileDateTimeDetection pix ratex avr.y avr.x sigmay sigmax miny minx maxy maxin
    00010001./2176x2176_230813_211934_616730.ser01212023-08-1312:20:31.912060UTC0.0015%11941814 5 41182180712021820
    00020001./2176x2176_230813_211934_616730.ser01222023-08-1312:20:32.417774UTC0.0028%12211831 13 71202181912541848
    00030002./2176x2176_230813_215637_448856.ser01122023-08-1312:57:35.770398UTC0.0188%6621249 28 4360911637101321
    00040002./2176x2176_230813_215637_448856.ser01132023-08-1312:57:36.138127UTC0.0273%7771410 40 5270813198511500
    00050003./2176x2176_230813_220644_721094.ser00382023-08-1313:07:02.747051UTC0.0051%19111396 11 171890136619281425
    00060003./2176x2176_230813_220644_721094.ser00392023-08-1313:07:03.185460UTC0.0044%19401446 7 131927142319511468
    00070004./2176x2176_230813_221745_030835.ser00632023-08-1313:18:21.15068UTC0.0056%13121515 27 221256146913521547
    00080004./2176x2176_230813_221745_030835.ser00642023-08-1313:18:21.533953UTC0.0116%14171598 38 291352154714881652
    00090005./2176x2176_230813_221745_030835.ser00902023-08-1313:18:33.851868UTC0.0016%2009790 5 620017782017800
    00100006./2176x2176_230813_223149_940304.ser00672023-08-1313:32:30.664567UTC0.0039%1192852 20 1311398191222872
    00110006./2176x2176_230813_223149_940304.ser00682023-08-1313:32:31.191807UTC0.0196%1316936 48 33122487214061000
    00120007./2176x2176_230813_223450_285888.ser00532023-08-1313:35:15.447331UTC0.0020%884245 11 3862240902250
    00130008./2176x2176_230813_224610_016091.ser00862023-08-1313:46:50.721269UTC0.0030%10641686 10 11046168310811689
    00140009./2176x2176_230813_224917_303904.ser00212023-08-1313:49:26.976365UTC0.0026%9661126 12 1293710989851144
    00150009./2176x2176_230813_224917_303904.ser00222023-08-1313:49:27.399878UTC0.0271%10821232 49 44986114411621304
    00160009./2176x2176_230813_224917_303904.ser00232023-08-1313:49:28.29901UTC0.0039%11731313 7 61160130111891326
    00170010./2176x2176_230813_224917_303904.ser00282023-08-1313:49:30.232413UTC0.0022%563607 7 4551599575613
    00180011./2176x2176_230813_233213_421381.ser00472023-08-1314:32:35.620768UTC0.0014%530758 3 5524747536766
    00190011./2176x2176_230813_233213_421381.ser00482023-08-1314:32:36.143866UTC0.0043%548784 7 10535766561802
    00200012./2176x2176_230814_000519_032429.ser00372023-08-1315:05:36.552570UTC0.0054%260671 6 3248664273678
    00210013./2176x2176_230814_000619_156488.ser00732023-08-1315:06:53.706239UTC0.0098%1469801 39 1413757681525823
    00220013./2176x2176_230814_000619_156488.ser00742023-08-1315:06:54.187536UTC0.0045%1547831 12 615258211572842
    00230014./2176x2176_230814_000719_659948.ser01032023-08-1315:08:15.175133UTC0.0030%18881078 15 121860105819161101
    00240015./2176x2176_230814_000819_440829.ser00462023-08-1315:08:41.156424UTC0.0040%11781890 14 91148187012001905
    00250015./2176x2176_230814_000819_440829.ser00472023-08-1315:08:41.691351UTC0.0050%12251920 14 91199190412471934
    00260016./2176x2176_230814_002127_484953.ser00572023-08-1315:21:54.513382UTC0.0023%16501863 11 31626185616681868
    00270017./2176x2176_230814_004134_504531.ser00012023-08-1315:41:35.46634UTC0.0050%1295233 8 212812291314237
    00280018./2176x2176_230814_004934_951193.ser00202023-08-1315:49:44.434356UTC0.0005%882811 5 2873808891815
    00290019./2176x2176_230814_004934_951193.ser00492023-08-1315:49:58.663188UTC0.0022%4171124 1 941511044191138
    00300019./2176x2176_230814_004934_951193.ser00502023-08-1315:49:59.92860UTC0.0047%4181163 2 1341511394221184
    00310020./2176x2176_230814_005334_933494.ser00762023-08-1315:54:12.877761UTC0.0018%11291318 7 61117130811421331
    00320020./2176x2176_230814_005334_933494.ser00772023-08-1315:54:13.288725UTC0.0109%11921371 24 201147133312401408
    00330021./2176x2176_230814_011536_019767.ser01092023-08-1316:16:32.356214UTC0.0023%954103 6 4942 96965111
    00340022./2176x2176_230814_011636_191545.ser01122023-08-1316:17:33.415175UTC0.0022%477537 2 6473527480548
    00350023./2176x2176_230814_012136_226146.ser00112023-08-1316:21:41.443640UTC0.0052%7621648 63 6469816088921784
    00360024./2176x2176_230814_014037_501893.ser00712023-08-1316:41:11.72791UTC0.0023%578303 2 5575293582314
    00370024./2176x2176_230814_014037_501893.ser00722023-08-1316:41:11.589103UTC0.0079%587274 4 10579257596295
    00380025./2176x2176_230814_014937_012397.ser00982023-08-1316:50:24.444588UTC0.0027%14431888 9 61424187514571897
    00390026./2176x2176_230814_022039_208872.ser01032023-08-1317:21:27.947090UTC0.0083%812335 11 15791306832366
    00400027./2176x2176_230814_022239_413480.ser00462023-08-1317:23:01.193184UTC0.0083%1052672 22 310046661094678
    00410028./2176x2176_230814_023139_975004.ser00552023-08-1317:32:06.75529UTC0.0019%288778 6 2278775302781
    00420029./2176x2176_230814_023440_382094.ser00212023-08-1317:34:50.262129UTC0.0103%7831401 9 2576513498001440
    00430029./2176x2176_230814_023440_382094.ser00222023-08-1317:34:50.798696UTC0.0120%8161482 11 2679614388391532
    00440030./2176x2176_230814_024141_189535.ser00162023-08-1317:41:48.706278UTC0.0034%6811748 3 867417316881762
    00450031./2176x2176_230814_024141_189535.ser00432023-08-1317:42:01.546529UTC0.0009%5701161 7 655211485821171
    00460032./2176x2176_230814_024340_944089.ser00402023-08-1317:43:59.873203UTC0.0025%10401960 8 101024194210571979
    00470033./2176x2176_230814_024641_214383.ser00622023-08-1317:47:10.627026UTC0.0021%3181688 2 531416773211696
    00480033./2176x2176_230814_024641_214383.ser00632023-08-1317:47:11.51222UTC0.0083%3221717 3 1331416953291741
    00490034./2176x2176_230814_025541_298370.ser00192023-08-1317:55:50.357926UTC0.0044%10591945 12 161034191010881982
    00500035./2176x2176_230814_025741_528020.ser01032023-08-1317:58:30.285406UTC0.0033%516772 6 2504769529776
    00510036./2176x2176_230814_030141_980739.ser00672023-08-1318:02:13.722720UTC0.0005%1497487 15 114784851522488
    00520037./2176x2176_230814_030542_438484.ser00482023-08-1318:06:05.166190UTC0.0045%1553530 16 115245271583532
    00530038./2176x2176_230814_030642_559976.ser00082023-08-1318:06:46.375014UTC0.0014%8451258 3 684012488501269
    00540039./2176x2176_230814_031242_787598.ser00192023-08-1318:12:51.765136UTC0.0017%9251995 5 691719869352006
    00550040./2176x2176_230814_031742_867072.ser00432023-08-1318:18:03.221385UTC0.0034%457720 7 3444715471725
    00560041./2176x2176_230814_031742_867072.ser01242023-08-1318:18:41.560519UTC0.0017%6231066 2 761910536281078
    00570042./2176x2176_230814_032343_546878.ser00332023-08-1318:23:59.223849UTC0.0017%2241184 4 521611742321194
    00580043./2176x2176_230814_032443_192625.ser01122023-08-1318:25:36.281829UTC0.0012%12021746 5 71194173412111758
    00590044./2176x2176_230814_032743_575557.ser01252023-08-1318:28:42.770509UTC0.0035%19031605 8 81887159019151618
    00600045./2176x2176_230814_033143_576866.ser00072023-08-1318:31:46.842669UTC0.0075%417452 9 7401438436467
    00610046./2176x2176_230814_033243_692050.ser01012023-08-1318:33:31.449127UTC0.0059%6771953 5 1266719306881973
    00620047./2176x2176_230814_033943_953764.ser00412023-08-1318:40:03.368984UTC0.0015%1004131355848860561917951662
    00630048./2176x2176_230814_033943_953764.ser00502023-08-1318:40:07.692657UTC0.0014%1057127262545855869018471639


  • 検出アルゴリズム
    1. ひとつ前の画像と差の絶対値を取ります。
    2. ノイズを除去します。
    3. 検出エリアの指定があればそれ以外を除去します。
    4. 2値化します。
    5. 閾値以上の面積比を計算します。
    6. 標準偏差を計算します。
    7. 範囲内の場合、
      中点が変化した箇所か判定します。
      変化がなければ再度ノイズ除去と標準偏差を計算します。
    8. 範囲内の場合、検出フラグを立てます。
    9. 連続フレームでない場合は、検出通知します。


  • 画像処理関数
  • RAWで処理する関数を作成しました。
    14個から20個に増えました。
    void InitImage(unsigned short *dst, int width, int height, unsigned short val);
    void SLImage(unsigned short *dst, unsigned short *src, int width, int height, int num);
    void SDImage(unsigned short *dst, unsigned short *src, int width, int height, int num);
    void AvrImage(unsigned short *dst, unsigned short *src, int width, int height, int num);
    void SubImage(unsigned short *dst, unsigned short *src, int width, int height, int num);
    void DifImage(unsigned short *dst, unsigned short *src1, unsigned short *src2, int width, int height, int num);
    void AbsImage(unsigned short *dst, unsigned short *src, int width, int height, int num);
    void CopyImage(unsigned short *dst, unsigned short *src, int width, int height, int num);
    void BNRImage(unsigned short *dst, unsigned short threshold, int width, int height, int masksize);
    void BNRImageArea(unsigned short *dst, unsigned short threshold, int width, int height, int masksize, int *minx, int *miny, int *maxx, int *maxy);
    float BinzImage(unsigned short *dst, unsigned short threshold, int width, int height);
    void BinzImageArea(unsigned short *dst, unsigned short threshold, int width, int height, int *minx, int *miny, int *maxx, int *maxy);
    float CountImage(unsigned short *dst, unsigned short threshold, int width, int height);
    void SDeviImage(unsigned short *dst, unsigned short threshold, int width, int height, double *ax, double *ay, double *sx, double *sy);
    void MaxMinImage(unsigned short *dst, unsigned short threshold, int width, int height, int *minx, int *miny, int *maxx, int *maxy);
    void SDeviMaxImage(unsigned short *dst, unsigned short threshold, int width, int height, double *ax, double *ay, double *sx, double *sy, int *minx, int *miny, int *maxx, int *maxy);
    void SDeviMaxImageArea(unsigned short *dst, unsigned short threshold, int width, int height, double *ax, double *ay, double *sx, double *sy, int *minx, int *miny, int *maxx, int *maxy);
    void NRImage(unsigned short *dst, unsigned short threshold, int width, int height);
    void WBImageRG(unsigned short *src, int width, int height);
    bool GetPix(unsigned short *dst, unsigned short threshold, int width, int height, int x, int y);
    


  • バッチ版(meteordetector11)ソース
  • 赤字が前回との差分です。
    int readSer(char *path, float lthresh, float ratio, double sthresh, unsigned short bthresh){
        FILE *fpSer;
        serHeader SerHeader;
        char tmpc[41];
    
        printf("%s\n",path);
    
        fpSer = fopen64(path, "rb");
        int r = fread(&SerHeader.FileID, 1, sizeof(SerHeader.FileID), fpSer);
        strncpy(tmpc, SerHeader.FileID, 14);
        tmpc[14]='\0';
        r = fread(&SerHeader.LuID, 1, sizeof(SerHeader.LuID), fpSer);
        r = fread(&SerHeader.ColorID, 1, sizeof(SerHeader.ColorID), fpSer);
        r = fread(&SerHeader.LittleEndian, 1, sizeof(SerHeader.LittleEndian), fpSer);
        r = fread(&SerHeader.ImageWidth, 1, sizeof(SEEK_CUR), fpSer);
        r = fread(&SerHeader.ImageHeight, 1, sizeof(SerHeader.ImageHeight), fpSer);
        r = fread(&SerHeader.PixelDepthPerPlane, 1, sizeof(SerHeader.PixelDepthPerPlane), fpSer);
        r = fread(&SerHeader.FrameCount, 1, sizeof(SerHeader.FrameCount), fpSer);
        r = fread(&SerHeader.Observer, 1, sizeof(SerHeader.Observer), fpSer);
        strncpy(tmpc, SerHeader.Observer, 40);
        tmpc[40]='\0';
        r = fread(&SerHeader.Instrument, 1, sizeof(SerHeader.Instrument), fpSer);
        strncpy(tmpc, SerHeader.Instrument, 40);
        tmpc[40]='\0';
        r = fread(&SerHeader.Telescope, 1, sizeof(SerHeader.Telescope), fpSer);
        strncpy(tmpc, SerHeader.Telescope, 40);
        tmpc[40]='\0';//
        int year, month, day, hour, minute, second, microsec;
        r = fread(&SerHeader.DateTime, 1, sizeof(SerHeader.DateTime), fpSer);
        timestamp2date(SerHeader.DateTime, &year, &month, &day, &hour, &minute, &second, µsec);
        r = fread(&SerHeader.DateTime_UTC, 1, sizeof(SerHeader.DateTime_UTC), fpSer);
        timestamp2date(SerHeader.DateTime_UTC, &year, &month, &day, &hour, &minute, &second, µsec);
        unsigned long TrailerDate;
        unsigned long *TrailerDateP = (unsigned long *)malloc(SerHeader.FrameCount * sizeof(TrailerDate));
        fseek(fpSer, -1*SerHeader.FrameCount * sizeof(TrailerDate), SEEK_END);
        for(int i = 0; i < SerHeader.FrameCount; i++){
            r = fread(&TrailerDate, 1, sizeof(TrailerDate), fpSer);
            if(r < 1){
                printf("trailer read error\n");
                free(TrailerDateP);
                return(1);
            }
            TrailerDateP[i] = TrailerDate;
            timestamp2date(TrailerDate, &year, &month, &day, &hour, &minute, &second, µsec);
        }
    
        fseek(fpSer, 178, SEEK_SET);
        int RawSize = SerHeader.ImageWidth * SerHeader.ImageHeight * SerHeader.PixelDepthPerPlane / 8;
        cv::Mat rgb8BitMat(SerHeader.ImageHeight, SerHeader.ImageWidth, CV_8UC3);			// RGB用バッファを用意
        cv::Mat rgb8BitMat2(SerHeader.ImageHeight/2, SerHeader.ImageWidth/2, CV_8UC3);			// RGB用バッファを用意
        int oc = -1;
        for(int i=0; i<SerHeader.FrameCount; i++){
            Temp = OldImage;
            OldImage = NewImage;
            NewImage = Temp;
            int r = fread(NewImage, sizeof(char), RawSize, fpSer);
            if(r < RawSize){
                printf("image read error\n");
                break;
            }
            if(DarkImage != NULL)
                SubImage(NewImage, DarkImage, SerHeader.ImageWidth, SerHeader.ImageHeight, 0);
            WBImageRG((unsigned short *)NewImage, SerHeader.ImageWidth, SerHeader.ImageWidth);
            if(mask_r.data != NULL)
                bmask(mask_r, (unsigned short *)NewImage);
            if(i == 0)//
                continue;
            DifImage(DffImage, NewImage, OldImage, SerHeader.ImageWidth, SerHeader.ImageHeight, 0);
            NRImage(DffImage, bthresh, SerHeader.ImageWidth, SerHeader.ImageHeight);
            if(mask_d.data != NULL)
                bmask(mask_d, DffImage);
            float lrate = BinzImage(DffImage, bthresh, SerHeader.ImageWidth, SerHeader.ImageHeight) * 100;
            if(lrate < 0.03 && lrate > lthresh){
                double ax, ay, sx, sy;
                int minx, miny, maxx, maxy;
                SDeviMaxImage(DffImage, bthresh, SerHeader.ImageWidth, SerHeader.ImageHeight, &ax, &ay, &sx, &sy, &minx, &miny, &maxx, &maxy);
                if(!GetPix(DffImage, bthresh, SerHeader.ImageWidth, SerHeader.ImageHeight, (minx + maxx) / 2, (miny + maxy) / 2)){
                    BNRImageArea(DffImage, bthresh, SerHeader.ImageWidth, SerHeader.ImageHeight, sthresh * 2, &minx, &miny, &maxx, &maxy);
                    float lrate = BinzImage(DffImage, bthresh, SerHeader.ImageWidth, SerHeader.ImageHeight) * 100;
                    if(lrate <= lthresh){
                        continue;
                    }
                    SDeviMaxImage(DffImage, bthresh, SerHeader.ImageWidth, SerHeader.ImageHeight, &ax, &ay, &sx, &sy, &minx, &miny, &maxx, &maxy);
                }
                if(sx > sthresh || sy > sthresh){
                    fc++;
                    if(i != oc + 1){
                        mc++;
                        printf("Meteor No. %d, frame No. %d\n", mc, i);
                    }
    
                    oc = i;
                    cv::Mat OutImage(cv::Size(SerHeader.ImageWidth * 2, SerHeader.ImageHeight), CV_8UC3);   // 合成後のイメージ作成
                    cv::Mat imageLeft(OutImage, cv::Rect(                    0, 0, rgb8BitMat.cols, rgb8BitMat.rows));  // コピーする領域左側
                    cv::Mat imageRight(OutImage, cv::Rect(SerHeader.ImageWidth, 0, rgb8BitMat.cols, rgb8BitMat.rows));  // コピーする領域右側
    
                    cv::Mat bayer16BitMat(SerHeader.ImageHeight, SerHeader.ImageWidth, CV_16UC1, NewImage);	// 16bit用バッファを用意して取り込み
                    cv::Mat bayer8BitMat = bayer16BitMat.clone();                   // 8bit用バッファを用意
                    bayer8BitMat.convertTo(bayer8BitMat, CV_8UC1, 0.0625*ratio);	// 8bitに変換
                    cv::cvtColor(bayer8BitMat, rgb8BitMat, cv::COLOR_BayerRG2RGB);	// デベイヤー
                    rgb8BitMat.copyTo(imageRight);                                  // 右側にコピーして表示させる
    
                    cv::rectangle(imageRight, cv::Point(ax-1, ay-1), cv::Point(ax+1, ay+1), CV_RGB(255,0,0), 2, 10, 0);           // 赤の矩形
                    cv::rectangle(imageRight, cv::Point(ax-sx, ay-sy), cv::Point(ax+sx, ay+sy), CV_RGB(0,0,255), 2, 10, 0);       // 青の矩形
                    cv::rectangle(imageRight, cv::Point(minx, miny), cv::Point(maxx, maxy), CV_RGB(0,255,0), 2, 10, 0);           // 緑の矩形
    
                    cv::Mat bayer16BitMat2(SerHeader.ImageHeight, SerHeader.ImageWidth, CV_16UC1, DffImage); // 16bit用バッファを用意して取り込み
                    bayer8BitMat = bayer16BitMat2.clone();                          // 8bit用バッファを用意
                    bayer8BitMat.convertTo(bayer8BitMat, CV_8UC1, 0.0625*ratio);	// 8bitに変換
                    cv::cvtColor(bayer8BitMat, rgb8BitMat, cv::COLOR_BayerRG2RGB);	// デベイヤー
    
                    timestamp2date(TrailerDateP[i], &year, &month, &day, &hour, &minute, &second, µsec);
                    sprintf(str, "%4.4d %4.4d %4.4d:%2.4f%", fc, mc, i, lrate);
                    cv::putText(rgb8BitMat, str, cv::Point(20, 50),cv::FONT_HERSHEY_SIMPLEX, 1, CV_RGB(200,200,200), 1);
                    sprintf(str, "%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d.%4.4dUTC", year, month, day, hour, minute, second, microsec);
                    cv::putText(rgb8BitMat, str, cv::Point(20, 100),cv::FONT_HERSHEY_SIMPLEX, 1, CV_RGB(200,200,200), 1);
                    sprintf(str, "ax:%04.0lf ay:%04.0lf sx:%04.0lf sy:%04.0lf", ax, ay, sx, sy);
                    cv::putText(rgb8BitMat, str, cv::Point(20, SerHeader.ImageHeight - 20),cv::FONT_HERSHEY_SIMPLEX, 1, CV_RGB(200,200,200), 1);
                    rgb8BitMat.copyTo(imageLeft);                                   // 左側にコピーして表示させる
    
                    fprintf(fpLog,"%4.4d,%4.4d,%s,%4.4d,%4.4d-%2.2d-%2.2d,%2.2d:%2.2d:%2.2d.%4.4dUTC,%2.4f%,"
                                 , fc, mc, path, i, year, month, day, hour, minute, second, microsec, lrate);
                    fprintf(fpLog,"%3.0lf,%3.0lf,%3.0lf,%3.0lf,%3.0d,%3.0d,%3.0d,%3.0d\n"
                                 , ax, ay, sx, sy, minx, miny, maxx, maxy);
    
                    writer << OutImage;  										// 画像 image を動画ファイルへ書き出す
                    cv::resize(OutImage, OutImage, cv::Size(), 0.5, 0.5);		// 縮小
                    writer2 << OutImage;  										// 画像 image を動画ファイルへ書き出す
    
                    SLImage(StkImage, DffImage, SerHeader.ImageWidth, SerHeader.ImageHeight, 0);
                }
            }
        }
        free(TrailerDateP);
        fclose(fpSer);
        return 0;
    }
    


  • リアルタイム版(SensorLounch16)ソース
  • 赤字が前回との差分です。
        //-------------------------------------------------------------------
        // 画像を読み込み,表示する
        //-------------------------------------------------------------------
        timeout_counter = 0;
        frame_count = oc = 0;
        st = GetTime();
    
        zoom_setMouseCallback((char *)"se_cam", 1/(float)div);
    
        while (1) {
            if (ReadRAW(RawImage) == 0) {
                if (++timeout_counter > TIMEOUT) {
                    fprintf(stderr, "sensorlaunch: time out.\n");
                    return  1;
                }
                usleep(500);
                continue;
            }
            frame_count++;
            timeout_counter = 0;
    
            unsigned char *Temp = BinImage3;
            BinImage3 = BinImage2;
            BinImage2 = Temp;
            CnvertImage(BinImage2, RawImage, RawSize, rawbit, raw8_flag);
            if(mask_r.data != NULL)
                bmask(mask_r, (unsigned short *)BinImage2);
    
            if(mode == SERD_MODE){
                int sthresh = 5;
                float lthresh = 0.0002;
    
                DifImage((unsigned short *)DiffImage, (unsigned short *)BinImage2, (unsigned short *)BinImage3, width, height, 0);
                NRImage((unsigned short *)DiffImage, bthresh >> (16-bpp), width, height);
                if(mask_d.data != NULL)
                    bmask(mask_d, (unsigned short *)DiffImage);
                BinzImage((unsigned short *)DiffImage, bthresh >> (16-bpp), width, height);
                float lrate = CountImage((unsigned short *)DiffImage, bthresh >> (16-bpp), width, height) * 100;
                if(lrate > lthresh){
                    double ax, ay, sx, sy;
                    int minx, miny, maxx, maxy;
                    SDeviMaxImage((unsigned short *)DiffImage, bthresh >> (16-bpp), width, height, &ax, &ay, &sx, &sy, &minx, &miny, &maxx, &maxy);
                    if(!GetPix((unsigned short *)DiffImage, bthresh >> (16-bpp), width, height, (minx + maxx) / 2, (miny + maxy) / 2)){
                        BNRImageArea((unsigned short *)DiffImage, bthresh >> (16-bpp), width, height, sthresh * 2, &minx, &miny, &maxx, &maxy);
                        float lrate = BinzImage((unsigned short *)DiffImage, bthresh >> (16-bpp), width, height) * 100;
                        if(lrate <= lthresh){
                            continue;
                        }
                        SDeviMaxImage((unsigned short *)DiffImage, bthresh >> (16-bpp), width, height, &ax, &ay, &sx, &sy, &minx, &miny, &maxx, &maxy);
                    }
    
                    if(sx > sthresh || sy > sthresh){
                       printf("%5d:Diff Detect. sx:%04.0lf sy:%04.0lf\n", ++diffcount, sx, sy);
                        diff = ON;
                        if(frame_count != oc +1)
                            system("~/detect_voice.sh");
                        oc = frame_count;
                    }
                }
    
                // 差分表示用
                cv::Mat bayerXBitMat2(height, width, depth, DiffImage);         // Xbit用バッファを用意して取り込み
                cv::Mat bayer8BitMat2 = bayerXBitMat2.clone();                  // 8bit用バッファを用意
                resize(bayer8BitMat2, bayer8BitMat2, cv::Size(), 1/(float)div, 1/(float)div);       // 縮小
                cv::imshow("ImageDiff", bayer8BitMat2);                          // ウィンドウに画像を表示する
    
                // 差分積算表示用
                if(diff == ON){
                    SLImage((unsigned short *)StkImage, (unsigned short *)DiffImage, width, height, 0);
                    cv::Mat bayer8BitMat3(height, width, CV_16UC1, StkImage);   // 16bit用バッファを用意して取り込み
                    bayer8BitMat3.convertTo(bayer8BitMat3, CV_8UC1, 0.0625*2);  // 8bitに変換
                    sprintf(str, "%d differences detected", diffcount);
                    cv::putText(bayer8BitMat3, str, cv::Point(20, 50),cv::FONT_HERSHEY_SIMPLEX, 1, CV_RGB(200,200,200), 1);
                    resize(bayer8BitMat3, bayer8BitMat3, cv::Size(), 1/(float)div, 1/(float)div);   // 縮小
                    cv::imshow("ImageDiffStack", bayer8BitMat3);                 // ウィンドウに画像を表示する
                }
            }
    
            // メインのRAW表示用
            cv::Mat bayerXBitMat(height, width, depth, BinImage2);              // Xbit用バッファを用意して取り込み
            cv::Mat bayer8BitMat = bayerXBitMat.clone();                        // 8bit用バッファを用意
            if(!raw8_flag){
                bayer8BitMat.convertTo(bayer8BitMat, CV_8UC1, 0.02*4);          // 8bitに変換
            }
            cv::Mat rgb8BitMat(height, width, CV_8UC3);                         // 保存用RGBバッファを用意
            cv::Mat dsp8BitMat(height, width, CV_8UC3);	                        // 表示用RGBバッファを用意
            cv::cvtColor(bayer8BitMat, rgb8BitMat, cv::COLOR_BayerRG2RGB);      // デベイヤー
            resize(rgb8BitMat, dsp8BitMat, cv::Size(), 1/(float)div, 1/(float)div);     // 縮小
            zoom_imshow(rgb8BitMat, dsp8BitMat, 2.0);                           // 拡大表示ウィンドウに画像を表示する
            cv::imshow("se_cam", dsp8BitMat);                                   // ウィンドウに画像を表示する
    
            // キー入力の処理
    


  • 参考サイト