2024,江端さんの技術メモ

「Redisをインストールすることなく、Windows10で使う方法」がある、と、ChatGPTに言われて「ホンマかいな?」と思いながらやってみたのですが、さっくり動きました。

$ docker run --name redis -p 6379:6379 -d redis

これだけで、Windows上で動かしているGoプログラムの中のredisが動いています(理屈は分かりません)。

Redisの動作確認
Dockerコンテナ内のRedisが動作しているか確認するためには、以下のコマンドを実行します。

$ docker exec -it redis redis-cli ping

-----

また、「docker run --name redis -p 6379:6379 -d redis を次回再起動するには、どうしたら良いですか」と聞いてみたところ、

Redisコンテナを再起動するコマンド

  1. コンテナを再起動する コンテナが停止している場合、次のコマンドで再起動します:
    docker start redis
  2. コンテナが実行中かどうかを確認する docker psコマンドを使って、Redisコンテナが正しく動作しているか確認できます:
    docker ps

    Redisコンテナが実行中であれば、一覧に表示されます。

だ、そうです。ちなみに、

もし、Dockerが起動するたびにRedisコンテナを自動的に再起動させたい場合は、--restartオプションを使って自動再起動ポリシーを設定できます。次回docker runを実行するとき、--restartオプションを追加しておくと、自動再起動が設定されます。

$ docker run --name redis -p 6379:6379 -d --restart unless-stopped redis

私は、redisが必要のない時に立ち上げたくはないので、上記の設定はしていません。

以上

 

2024,江端さんの技術メモ

(1)地図DBに接続されている状態であること。

(2)go.modが入っていること

(3)prune_isonodes.go の依存パッケージのインストール方法が変っていること

// 依存パッケージ  $ go get github.com/lib/pq
//↓
G:\home\ebata\hakata\hakata_db>go get github.com/lib/pq
G:\home\ebata\hakata\hakata_db>go install github.com/lib/pq
go: 'go install' requires a version when current directory is not in a module
        Try 'go install github.com/lib/pq@latest' to install the latest version
G:\home\ebata\hakata\hakata_db>go install github.com/lib/pq@latest
package github.com/lib/pq is not a main package

(4)prune_isonodes.goに書き込まれたターゲットのdb名称を変更すること

    dbParam := fmt.Sprintf("host=localhost port=%d user=postgres password=password dbname=hakata_db sslmode=disable", *dbPort)
"go run prune_isonodes.go"で孤立ノードが削除されます。
G:\home\ebata\hakata>go run prune_isonodes.go
[ノード#1からのスキャン] 到達数: 60781 未到達: 1108
削除対象のノード (1108個):
[57493 59415 46635 51008 46336 59154 48022 59511 39412 22789 59166 59535 59531 53964 31094 45646 55303 45386 51069 59394 59129 59175 59215 59190 59297 45602 61062 50473 53933 51663 60258 17471 17566 59406 48023 60228 49200 49186 58539 60103 51007 59546 51006 57326 59547 45680 59250 59598 46354 47335 47010 58527 54516 31095 59323 45327 45676 60125 46868 53953 60226 32888 50574 60213 18763 59290 60114 59520 60264 59393 59538 32894 51854 59477 59061 59245 47003 59615 53958 60245 59325 61661 59064 58529 52435 47547 47001 60231 39841 61645 59130 45613 46221 46356 59059 28051 59191 59237 59286 59125 59229 59548 42380 59074 53967 59424 58543 59305 59524 59413 45664 53966 47343 59292 50984 47012 60109 58530 58678 60156 45606 59184 49184 53951 37012 42383 46334 59195 59362 45599 59601 60266 29342 59056 47337 45699 45648 59635 59293 5237 47004 22462 61660 45621 61655 53239 49196 59077 59112 60255 53934 42382 59179 56864 45620 52871 46817 59216 59512 5238 19595 48020 46326 59610 60221 47340 61734 61737 45647 45638 58568 59132 50582 59288 57488 61668 59244 31964 51274 59161 47315 19587 51327 45628 49198 59576 59550 51158 45674 53950 59401 45669 59226 46226 58528 35214 59348 37000 53921 18761 51267 60256 53968 17485 51273 48352 50363 59501 59211 57485 59636 59084 50580 19594 31093 59055 53928 37013 45600 60104 53970 60214 59234 28899 60110 50578 47334 32889 59505 60219 41557 60239 50267 53939 29424 59239 60131 57486 39415 59343 49201 53243 45662 60252 45665 60217 46223 61658 46864 58083 59334 45610 60155 59327 59131 59542 53940 46342 59478 59388 59392 59414 59296 45653 59879 59169 61644 53238 59500 59549 45655 57484 45614 59360 59345 59316 59135 59122 59568 59176 59251 60251 50577 59158 59509 45618 60102 22775 59196 59361 59203 52870 53686 59595 58537 59491 45670 59142 53975 42610 60337 53947 53919 53973 59618 59145 39409 24519 45654 59289 53931 46220 47002 46866 59355 45625 60260 60257 53962 53235 37018 57327 37008 59308 45962 53937 53932 59354 59160 59194 37023 53957 53961 59384 59342 37020 61724 59349 59621 53237 59537 47316 51665 59173 22114 32892 46007 46327 59609 53942 59157 46974 59486 59495 59356 51853 53226 50355 50979 59137 54531 59508 51206 59205 59487 40314 53926 45659 59221 50983 45601 60262 59526 36997 53955 59232 59163 18757 60237 45675 57324 53930 59209 53242 22115 45698 19576 59206 59144 59240 59515 59522 45673 59189 45656 59220 59386 59407 59399 59604 45637 61643 57332 59111 59385 46331 60240 59162 59303 54923 36998 60232 59299 56623 59498 59607 60218 55301 49189 31966 59338 57906 45690 45322 59423 45615 59301 60716 60115 53687 60121 45660 37019 45619 50354 51165 52437 48272 32059 60243 59307 59306 53241 59228 58534 59602 59319 59082 60238 50474 45666 59310 59391 10298 60116 59496 59417 59081 61871 45617 59411 59078 59597 37016 59558 46949 40315 46324 60119 59553 59219 59422 32897 59507 59243 59523 59114 45639 46329 59287 47339 59350 60242 53959 59247 43492 59118 61738 61880 45325 59076 53948 53972 5240 59324 40316 59155 59242 59187 59426 60224 59479 45624 59183 59128 59246 58580 45678 39840 46862 59476 59344 59201 43246 59620 59492 59113 59351 59612 59418 59224 60216 60222 59121 45645 59217 59494 59359 57904 53971 53922 59159 45679 59115 55300 59347 58581 50592 59561 59529 60248 59592 59563 36996 45663 60215 53943 59140 59480 59880 45603 59060 59197 53949 58351 60227 44923 58541 56622 37007 40313 60122 46975 45627 59565 59126 58082 57487 59593 49190 57914 60233 45634 59554 45671 45324 59198 59400 46330 59124 59594 17541 19581 60120 19593 47033 38208 5236 59412 60334 28944 53927 61725 5239 59171 60154 46335 59180 59285 45640 60254 59427 61061 45644 45414 31965 53918 57490 59284 17522 57489 52439 59138 59534 60261 59489 50589 54396 47902 59398 37011 59225 45658 51068 59313 54423 50583 61662 57910 45689 50586 59613 57325 53965 47904 58532 59346 60241 59182 60124 60267 59231 50982 52436 61666 61495 46315 61665 58544 32891 51174 59341 59599 46227 59235 37005 32895 53240 61872 59300 45436 60111 53935 46225 59419 60338 59227 59622 46867 59167 46339 59283 54517 60246 45616 53236 45657 48021 59249 51330 45650 22452 54922 59172 59395 59409 46950 59202 47901 60106 61642 46861 59533 10301 59062 59352 59403 59544 52438 45608 59340 57909 59617 59605 45642 53234 54530 45635 50360 59207 38209 59192 52440 37014 59320 56855 45672 59482 54525 44926 59141 19597 59545 59119 59248 42064 57331 61672 59199 42381 59164 45641 45677 59566 59499 17519 46341 50595 57323 51070 58579 50576 59567 58695 60108 49188 45609 59065 31967 22778 46333 59136 59185 59337 59624 17539 59506 29339 46222 52872 48010 59485 51326 59357 50978 53944 59490 45626 53941 50585 57911 45629 56621 49194 48011 39411 58538 53689 59302 59304 53923 59497 61663 37024 59282 59358 59188 32890 46332 59521 59483 59488 60220 50361 60234 56713 59430 53945 47336 59335 22783 50991 37022 32896 53936 50575 59133 59551 53920 57913 58526 45661 59608 59170 59389 50587 59058 52447 54398 59339 50992 53946 60259 10300 45611 53954 60235 15200 45651 46355 59397 93 46863 60236 61657 36995 50591 59311 59193 59156 45323 32893 59353 10297 60126 61063 53960 37021 59314 59513 59402 49192 22776 50980 59484 42379 59063 59390 59315 45633 59562 37017 15165 46337 60107 57482 53925 39413 59637 59429 59318 59208 59168 49195 45623 59552 58533 49193 22769 59143 59222 37009 47903 22782 37004 50594 45604 60112 61060 39408 54397 59085 53938 59174 59564 59493 59421 53963 19588 46318 59178 60153 59241 61659 59600 45630 43493 43480 59083 59123 60244 59139 46224 59186 53924 58542 59117 59606 60113 59218 50590 59238 44919 59181 61656 38207 59416 50579 51662 57329 60223 59312 24502 58536 6768 46321 59134 61654 55302 59322 59057 17560 39414 45649 49191 50334 51329 59387 59326 50879 53312 59420 37010 60229 61059 32898 45643 49185 37003 59611 59410 59619 59404 59054 59514 39416 59317 53969 53974 53952 55795 18764 50596 3068 59532 47314 59295 60249 47014 50588 39574 59294 60265 60263 37015 45326 3066 45668 37006 43491 51325 10299 61667 59536 60105 45605 58535 59503 45631 57905 51664 59556 60118 59212 45622 22780 45667 59309 22768 59502 57912 59616 46317 53956 59396 57483 45632 59405 59210 59321 47017 57491 59623 6767 44924 45607 58509 60253 59213 50593 59177 58531 48351 57328 3067 45319 45652 60225 50993 51328 50584 59120 61494 31036 49199 22791 59328 45612 59075 37574 22443 59577 59408 59614 39410 60117 59603 59230 53688 50581 59557 40312 59291 59596 45697 59080 61879 59336 59236 59214 59079 60230 37002 36999 46366 46865 19584 59116 49187 58540 45636 53929 52794 59200 60247 58084 60618 59428 52446 59233 46338 59629 18762 49197 59204 59165 59127 60123 60250 59223 61664 59425 57492 59298 37001 59504 19592 57330]
削除を実行します。
完了しました。

2024,江端さんの技術メモ

この地図のプロパティは、424 x 379

で、

set datafile separator "," # データの区切り文字をコンマに指定
set title "Cluster Data with Map" # グラフタイトル
set xlabel "X-axis" # X軸のラベル
set ylabel "Y-axis" # Y軸のラベル
set zlabel "Z-axis" # Z軸のラベル
set xrange [0:1] # X軸の範囲をデータに合わせて調整
set yrange [0:1] # Y軸の範囲をデータに合わせて調整
set zrange [0:1] # Z軸の範囲
set ticslevel 0 # Z軸を平面上に表示
set xyplane at 0 # XY平面をZ=0に設定
set view 40, 30, 1, 1 # 視点の角度とスケールを調整

# 地図画像をXY平面に表示 (画像のX軸、Y軸範囲を設定し、Z軸は0に固定)
splot "img_664a03bcd2376.png" binary filetype=png dx=1.0/424 dy=1.0/379 with rgbimage, \
'Cluster1.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" title 'Cluster 1', \
'Cluster2.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster3.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster4.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster5.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster6.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster7.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster8.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster9.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster10.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster11.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster12.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster13.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster14.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster15.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster16.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster17.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster18.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster19.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster20.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster21.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster22.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster23.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster24.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster25.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster26.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster27.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster28.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster29.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster30.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster31.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster32.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster33.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster34.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster35.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster36.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster37.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster38.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster39.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster40.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle, \
'Cluster41.csv' using 1:2:3 with points pt 7 ps 2 lc rgb "blue" notitle

cluster1.csvの内容はこんな感じ
0.63, 0.65, 0.58
0.62, 0.65, 0.56
0.61, 0.65, 0.56
0.61, 0.65, 0.56
0.62, 0.65, 0.56
0.62, 0.66, 0.55
0.63, 0.65, 0.55
0.62, 0.65, 0.56
0.62, 0.66, 0.57
0.62, 0.65, 0.58
0.62, 0.65, 0.58
(後略)

2024,江端さんの技術メモ

chartjs-plugin-streaming.js は、今も便利に使わせて貰っています。

Golangから送り込んだデータを、chartjs-plugin-streaming(リアルタイムストリーミングデータ向け Chart.js プラグイン)で表示してみた件

で、今回、リアルタイムは必要なくて、単にグラフ表示が必要になりました。

このライブラリが必要です。https://www.papaparse.com/ からダウンロードできます。

sample.htmlという名前で以下のファイルをセーブします。

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSV to Chart.js</title>
  <script src="./chart.js"></script>
  <script src="./papaparse.min.js"></script> <!-- 正しいPapaParseのCDN -->
</head>
<body>
  <canvas id="myChart" width="400" height="200"></canvas>
  <script>
    // サンプルのCSVファイルを読み込む処理
    fetch('sample.csv')
      .then(response => response.text())
      .then(csvData => {
        Papa.parse(csvData, {
          header: true,
          dynamicTyping: true,
          complete: function(results) {
            const data = results.data;
            const labels = [];
            const values = [];

            // CSVファイルからラベルとデータを抽出
            data.forEach(row => {
              labels.push(row['label_column']);  // 'label_column' はラベル用の列名
              values.push(row['value_column']);  // 'value_column' は値用の列名
            });

            // Chart.jsでグラフを描画
            const ctx = document.getElementById('myChart').getContext('2d');
            const chart = new Chart(ctx, {
              type: 'line',  // 折れ線グラフの例
              data: {
                labels: labels,
                datasets: [{
                  label: 'CSV Data',
                  data: values,
                  borderColor: 'rgba(75, 192, 192, 1)',
                  borderWidth: 1,
                  fill: false
                }]
              },
              options: {
                scales: {
                  x: {
                    beginAtZero: true
                  },
                  y: {
                    beginAtZero: true
                  }
                }
              }
            });
          }
        });
      });
  </script>
</body>
</html>

sample.csv は以下の通り。

label_column,value_column
January,10
February,15
March,20
April,25
May,30
June,35
July,40
August,45
September,50
October,55
November,60
December,65

あとは、

python3 -m http.server 8000

などとしてサーバを立ち上げておいて、ブラウザから、

http://localhost:8000/sample.html

とすれば、

2024,江端さんの技術メモ

Keyword: WordPress アップロード 拡張子

WP Add Mime Types 管理設定で、
py = text/py
を追加したのですが *.pyのアップロードができません

WP Add Mime Types プラグインで .py ファイルのアップロードを許可する設定を行ったにもかかわらず、アップロードができない場合、いくつかの点を確認し、設定を調整する必要があります。

1. MIMEタイプの設定を確認する

text/py の代わりに、次の MIME タイプを試してみてください。

py = text/x-python

で、このあとブラウザでWordPressの立ち上げをしたらアップロードできるようになりました。
-----
Keyword: WordPress アップロード 拡張子

2024,江端さんの技術メモ

ラズパイに、ラズパイにWebカメラ C270n HD 720Pを接続して、RTSPカメラを作ろうとしました。

以下のソースコードをコンパイルしました。

/*
  dummy_usbcam_0.2.c
  
  ■環境設定を行います。
  sudo apt-get update
  sudo apt-get install libgstrtspserver-1.0-dev

  export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH

 
  ■プログラムをコンパイルして実行するには、以下のコマンドを使用します:
  gcc -o dummy_usbcam_0.2 dummy_usbcam_0.2.c `pkg-config --cflags --libs gstreamer-1.0 gstreamer-rtsp-server-1.0`

  ./dummy_usbcam_0.2 -r rtsp://127.0.0.1:8554/custom -d /dev/video0

  ■また、ヘルプメッセージを表示するには、以下のコマンドを使用します:

  ./dummy_usbcam_0.2 -h

  ■稼動確認環境
   (車上) 192.168.101.30
   cam@cam-desktop:~/cpp/src$ ./dummy_usbcam_0.2
   cam@cam-desktop:~/cpp/src$ ./abc_vtp_0.1 -i 192.168.101.10 -p 38089 -r rtsp://127.0.0.1:8554/test

   (地上) 192.168.101.10
pt@pt-desktop:~/go/src$ more srt_rtsp_server_38089.sh 

#!/bin/bash
gst-launch-1.0 srtsrc uri=srt://:38089 keep-listening=true ! decodebin ! autovid
eosink

  
*/

#include <gst/gst.h>
#include <gst/rtsp-server/rtsp-server.h>
#include <stdio.h>
#include <string.h>

void print_usage(const char *prog_name) {
    g_print("Usage: %s -r [RTSP_URL] -d [DEVICE]\n", prog_name);
    g_print("Default RTSP_URL: rtsp://127.0.0.1:8554/test\n");
    g_print("Default DEVICE: /dev/video0\n");
    g_print("Example: %s -r rtsp://127.0.0.1:8554/test -d /dev/video0\n", prog_name);
}

int main(int argc, char *argv[]) {
    GMainLoop *loop;
    GstRTSPServer *server;
    GstRTSPMountPoints *mounts;
    GstRTSPMediaFactory *factory;
    const char *default_url = "rtsp://127.0.0.1:8554/test";
    const char *default_device = "/dev/video0";
    const char *rtsp_url = default_url;
    const char *device = default_device;
    char path[256] = "/test";
    char service[6] = "8554";  // ポート番号のデフォルト値

    for (int i = 1; i < argc; i++) {
        if (strcmp(argv[i], "-h") == 0) {
            print_usage(argv[0]);
            return 0;
        } else if (strcmp(argv[i], "-r") == 0 && i + 1 < argc) {
            rtsp_url = argv[++i];
            // RTSP URLのポート番号とパス部分を抽出
            const char *url_port = strchr(rtsp_url + strlen("rtsp://"), ':');
            if (url_port != NULL) {
                url_port++;
                const char *url_path = strchr(url_port, '/');
                if (url_path != NULL) {
                    strncpy(path, url_path, sizeof(path) - 1);
                    path[sizeof(path) - 1] = '\0';  // Null terminatorを追加

                    int port_length = url_path - url_port;
                    if (port_length < sizeof(service)) {
                        strncpy(service, url_port, port_length);
                        service[port_length] = '\0';  // Null terminatorを追加
                    }
                }
            }
        } else if (strcmp(argv[i], "-d") == 0 && i + 1 < argc) {
            device = argv[++i];
        }
    }

    gst_init(&argc, &argv);

    loop = g_main_loop_new(NULL, FALSE);

    server = gst_rtsp_server_new();
    gst_rtsp_server_set_service(server, service);

    mounts = gst_rtsp_server_get_mount_points(server);

    factory = gst_rtsp_media_factory_new();
    char launch_string[512];
    snprintf(launch_string, sizeof(launch_string),
             "( v4l2src device=%s ! videoconvert ! x264enc speed-preset=ultrafast tune=zerolatency ! rtph264pay pt=96 name=pay0 )",
             device);
    gst_rtsp_media_factory_set_launch(factory, launch_string);

    gst_rtsp_mount_points_add_factory(mounts, path, factory);

    g_object_unref(mounts);

    gst_rtsp_server_attach(server, NULL);

    g_print("Stream ready at %s with device %s\n", rtsp_url, device);
    g_main_loop_run(loop);

    return 0;
}

で、

$ ./dummy_usbcam_0.2

をして、

$ gst-launch-1.0 rtspsrc location=rtsp://127.0.0.1:8554/test ! decodebin ! autovideosink

で、映像を受信しようとしたのですが、動きませんでした。

-----

そもそも、"/dev/video0"が見つかりません。

Raspberry PiがWebカメラを認識できるように、必要なパッケージをインストールします。

$ sudo apt-get update
$ sudo apt-get install v4l-utils

v4l-utilsは、Video4Linux(V4L)デバイスを操作するためのツールセットです。

次に、WebカメラがRaspberry Piに認識されているかを確認します。以下のコマンドを実行して、デバイスが認識されているか確認します。

$ lsusb

このコマンドは、接続されているUSBデバイスのリストを表示します。

Bus 001 Device 004: ID 046d:0825 Logitech, Inc. Webcam C270

が表示されれば、成功です。

で、あとはGStreamerでデバイスが動くことを確認しました。

$ gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! autovideosink

後は念の為、GStreamerのインストールができているかを確認して下さい。

$ sudo apt-get update
$ sudo apt-get install gstreamer1.0-tools gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav

で、

$ gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! autovideosink

で、ローカルにカメラ映像が表示されれば成功です。

で、この後、プログラムを起動して、リモートで、

$ gst-launch-1.0 rtspsrc location=rtsp://192.168.0.200:8554/test ! decodebin ! autovideosink

(192.168.0.200はラズパイのIPアドレスです)

で、RTSPプロトコルで転送された映像が表示されるようになりました。

以上

 

2024,江端さんの技術メモ

.emacs はこんなかんじ

;; 英字フォントを設定
(set-face-attribute 'default nil
:family "Ubuntu Mono"
:height 120
:weight 'normal
:width 'normal)

;; 日本語フォントを設定
(set-fontset-font t 'japanese-jisx0208
		  (font-spec :family "Noto Sans CJK JP" :size 14))


(require 'skk-autoloads)
(setq skk-user-directory "~/.emacs.d/skk")
;(setq skk-large-jisyo "/usr/share/skk/SKK-JISYO.L")
(setq skk-large-jisyo "~/.emacs.d/skk/SKK-JISYO.L")
(setq skk-server-host "localhost")
(setq skk-server-portnum 1178)
(global-set-key (kbd "C-x C-j") 'skk-mode)

;; ネイティブコンパイルの警告を無効にする
(setq native-comp-async-report-warnings-errors nil)

で、あとはこんなことをやっておく

$ wget https://skk-dev.github.io/dict/SKK-JISYO.L.gz
$ gunzip SKK-JISYO.L.gz
$ mkdir -p ~/.emacs.d/skk
$ mv SKK-JISYO.L ~/.emacs.d/skk/

$ sudo apt update
$ sudo apt install ddskk

とりあえず「動けばいい」の方向で。

2024,江端さんの技術メモ

C言語のプログラムで、コマンドパラメタを入力する部分をつくっていたのですが、ファイルを作ってほしくないケースが出てきました。

// 引数からIPアドレス、ポート、RTSP URL、ファイル名を取得
    char *srt_ip = DEFAULT_IP;
    int srt_port = DEFAULT_PORT;
    char *rtsp = DEFAULT_RTSP;
    char *filename = DEFAULT_FILENAME;
    int udp_port = DEFAULT_UDP_PORT;

    for (int i = 1; i < argc; i++) {
      if (strcmp(argv[i], "-i") == 0 && i + 1 < argc) {
        srt_ip = argv[i + 1];
        i++;
      } else if (strcmp(argv[i], "-p") == 0 && i + 1 < argc) {
        srt_port = atoi(argv[i + 1]);
        i++;
      } else if (strcmp(argv[i], "-r") == 0 && i + 1 < argc) {
        rtsp = argv[i + 1];
        i++;
      } else if (strcmp(argv[i], "-f") == 0 && i + 1 < argc) {
        filename = argv[i + 1];
        i++;
      } else if (strcmp(argv[i], "-u") == 0 && i + 1 < argc) {  // UDPポート番号の引数を追加
        udp_port = atoi(argv[i + 1]);
        i++;
      } else {
        printf("Usage: %s [-i ip_address] [-p port] [-r rtsp_url] [-f filename] [-u udp_port]\n", argv[0]);
	    printf("./abc_vtp_0.3 -i 192.168.101.10 -p 38090 -r rtsp://cam:Cam12345@192.168.0.11/Src/MediaInput/stream_1 -f 2jcie/data_test2.csv -u 12346 \n");
    	    printf("-f /dev/null とすることでSRTメトリックス情報は廃棄されます \n");
	    printf("-u 0 とすることで制御用スレッドは起動しなくなります\n ");


        return 1;
      }
    }
    
    printf("IP: %s\nPort: %d\nRTSP: %s\nFilename: %s\nUDP Port: %d\n", srt_ip, srt_port, rtsp, filename, udp_port);

しかし上記のプログラムでは、ファイル名を無視すると、デフォルトのファイル名を選んでしまいます。そんでもって、プログラムの改造もしたくありませんでした。

今更ながらなのですが、ファイル名を

/dev/null

とすると、ファイルを作らずにデータを捨ててくれるようです。
(コマンドプロンプトでしか使えないと思っていた)

いや、本当に助かった。変なコード追加しなくて済んだし。

それ以上に、この程度のことを、今の今まで、私が知らなかったことが驚きです。

まあ、私の力量などこの程度です(乾いた笑い)。

 

 

2024,江端さんの技術メモ

ubuntu 22.04をホストOSとして、ubuntu24.04 をゲストOSとした、そのゲストosの環境で、fastapiをインストールしようとしましたが、上手く動きませんでした。

pythonでFastAPIを試す

cam@cam-desktop:/$ pip3 install fastapi uvicorn error: externally-managed-environment といわれました。
「システム全体のPython環境にパッケージをインストールする必要がある場合は、--break-system-packagesオプションを使用して強制的にインストールすることも可能です」
と言われました。
「システム全体」でかまわなかったので、強行しました。
cam@cam-desktop:~/testapi$ pip install fastapi uvicorn --break-system-packages
$make testapi
$cd testapi
$touch main.py

以下のサンプルコードを main.py に記述します。

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
    return {"Hello": "World"}
で、
$ uvicorn main:app --host 0.0.0.0 --port 8000
http://localhost:8000 で稼働確認できましたので、とりあえずここからです。
cam@cam-desktop:~/fastapi6d$ pip3 install request --break-system-packages
で、(私の場合)ようやく起動しました。

2024,江端さんの技術メモ

GISでシミュレーションを行う上で、鈴木紀明先生のこの方法を使い倒させていただいております。

先生には大変申し訳ないのですが、もし、このリンクが消えたら私にとって大打撃なので、先生に無許諾で切り取り&貼り付けをさせて頂いております(御叱り頂ければ、このページを即時抹消致します)。