raspberry pi 5 安裝 dnsmasq 來變成一台 dns 伺服器
sudo apt update
sudo apt upgrade
sudo apt install dnsmasq
sudo geany /etc/dnsmasq.conf
將 #domain-needed 的井字號拿掉
將 #bogus-p 的井字號拿掉
將 #no-resolv 的井字號拿掉
加入 server=8.8.8.8
加入 server=168.95.1.1
將 #cache-size=150 改成 cache-size=15000
儲存,離開
sudo systemctl restart dnsmasq
raspberry pi 5 的 chromium 軟體需要使用注音輸入法(fcitx5的chewing)
開啟 Chromium
chrome://flags/
將 Wayland text-input-v3 改為 Enabled
raspberry pi 5 調換左右螢幕
首先確定使用 X11 的配置
[terminal] echo $XDG_SESSION_TYPE
若顯示 X11 ,那就對了。若顯示為 wayland ,那就錯了。
若為 X11 則可用下面指令即時變更左右位置,
[terminal] xrandr --output HDMI-1 --left-of HDMI-2 (把 HDMI-1 搬到 HDMI-2 的左邊)
若要一開機就套用的話
[terminal] cd /etc/X11/Xsession.d/
[terminal] sudo geany 99-xrandr
新增下面兩行並儲存
#!/bin/bash
xrandr --output HDMI-2 --left-of HDMI-1
[terminal] sudo chmod +x 99-xrandr
[terminal] sudo reboot
從網路攝影機讀取QRCODE
執行看看
<!doctype html>
<html lang="zh-Hant-TW">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>QR Code Scanner From Webcam</title>
<style>
#myVideo
{
width: 300px;
height: 200px;
border: 1px solid black;
}
</style>
</head>
<body>
<div>引用 https://github.com/cozmo/jsQR/blob/master/dist/jsQR.js</div>
<div>純粹 JavaScript 解碼 QRCode</div>
<br>
<h1>QR Code Scanner with Webcam</h1>
<video id="myVideo" autoplay playsinline></video>
<p id="pResult">Waiting for QR Code...</p>
<textarea id="ta1" rows="20" cols="80"></textarea>
<!-- <script src="https://cdn.jsdelivr.net/npm/jsqr@1.4.0/dist/jsQR.js"></script> -->
<script src="jsQR.js"></script>
<script>
const oVideo = document.getElementById('myVideo');
const pResultElement = document.getElementById('pResult');
var strLastCode="";
// 獲取使用者的攝像頭
navigator.mediaDevices.getUserMedia({ video: { facingMode: "environment" } })
.then(
function(oStream)
{
oVideo.srcObject = oStream;
oVideo.play();
window.requestAnimationFrame(processOneFrame);
})
.catch(
function(oErr)
{
console.error('Error accessing webcam: ', oErr);
});
function processOneFrame()
{
if(oVideo.readyState===oVideo.HAVE_ENOUGH_DATA)
{
// 建立 canvas 用於獲取影像數據
const oCanvas = document.createElement('canvas');
const oCtx = oCanvas.getContext('2d');
oCanvas.width = oVideo.videoWidth;
oCanvas.height = oVideo.videoHeight;
oCtx.drawImage(oVideo, 0, 0, oCanvas.width, oCanvas.height);
// 從 oCanvas 中獲取影像數據
const oImageData = oCtx.getImageData(0, 0, oCanvas.width, oCanvas.height);
const oCode = jsQR(oImageData.data, oCanvas.width, oCanvas.height);
if(oCode)
{
pResultElement.textContent = 'QR Code 內容: ' + oCode.data;
pResultElement.style.color = 'green';
if(oCode.data!=strLastCode)
{
strLastCode=oCode.data;
document.getElementById("ta1").value
=oCode.data+"\r\n"
+document.getElementById("ta1").value;
}
}
else
{
pResultElement.textContent = 'No QR Code detected.';
pResultElement.style.color = 'red';
}
}
// 繼續下一幀的掃描
window.requestAnimationFrame(processOneFrame);
}
</script>
</body>
</html>
從檔案讀取QRCODE
執行看看
<!doctype html>
<html lang="zh-Hant-TW">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>QR Code Scanner From File</title>
</head>
<body>
<div>引用 https://github.com/cozmo/jsQR/blob/master/dist/jsQR.js</div>
<div>純粹 JavaScript 解碼 QRCode</div>
<br>
<input type="file" id="inpFile" accept="image/*">
<canvas id="myCanvas" style="display: none;"></canvas>
<p id="pResult">QR Code 內容將顯示在此處</p>
<!-- <script src="https://cdn.jsdelivr.net/npm/jsqr@1.4.0/dist/jsQR.js"></script> -->
<script src="jsQR.js"></script>
<script>
document.getElementById('inpFile').addEventListener(
'change',
function(oEvent1)
{
const oFile = oEvent1.target.files[0];
const oFileReader = new FileReader();
oFileReader.onload =
function(oEvent2)
{
const oImg = new Image();
oImg.src = oEvent2.target.result;
oImg.onload =
function()
{
const oCanvas = document.getElementById('myCanvas');
const oCtx = oCanvas.getContext('2d');
oCanvas.width = oImg.width;
oCanvas.height = oImg.height;
oCtx.drawImage(oImg, 0, 0, oImg.width, oImg.height);
const oImageData = oCtx.getImageData(0, 0, oCanvas.width, oCanvas.height);
const oCode = jsQR(oImageData.data, oCanvas.width, oCanvas.height);
if(oCode)
{
document.getElementById('pResult').textContent = 'QR Code 內容: ' + oCode.data;
}
else
{
document.getElementById('pResult').textContent = '無法辨識 QR Code';
}
};
};
oFileReader.readAsDataURL(oFile);
}
);
</script>
</body>
</html>