import warnings
warnings.simplefilter('ignore')
import nussl
import numpy as np
# from common import viz
mix = nussl.AudioSignal('pop.mp3')
# stft = signal1.stft()
repet = nussl.separation.primitive.Repet(mix)
repet.run()
repet_bg, repet_fg = repet.make_audio_signals()
# Will run the algorithm and return AudioSignals in one step
repet = nussl.separation.primitive.Repet(mix)
repet_bg, repet_fg = repet()
repet_bg.istft()
repet_bg.embed_audio()
repet_fg.istft()
repet_fg.embed_audio()
repet_bg.write_audio_to_file('bg2.wav')
repet_fg.write_audio_to_file('fg2.wav')
[Blockchain] ラズパイでBitcoinのマイニングを実行する
ビットコイン用のウォレットを「Blockchain.com」で作成します。

### raspberry pi
$ git clone –depth 1 https://github.com/tpruvot/cpuminer-multi.git
$ cd cpuminer-multi/
$ sudo apt-get install automake autoconf pkg-config libcurl4-openssl-dev libjansson-dev libssl-dev libgmp-dev make g++
$ ./build.sh
### mining
$ ./cpuminer -a sha256d –user=${bitcoin address} –url=stratum+tcp://sha256.jp.nicehash.com:3334
[2021-12-11 19:37:49] sha256d block 14160074, diff 1110110280.114
[2021-12-11 19:37:49] CPU #3: 982.61 kH/s
[2021-12-11 19:37:49] CPU #1: 969.81 kH/s
[2021-12-11 19:37:49] CPU #2: 955.35 kH/s
[2021-12-11 19:37:49] CPU #0: 924.83 kH/s
[2021-12-11 19:37:56] sha256d block 717892, diff 206739871308.642
[2021-12-11 19:37:56] CPU #3: 1013 kH/s
[2021-12-11 19:37:56] CPU #1: 1020 kH/s
[2021-12-11 19:37:56] CPU #2: 1002 kH/s
[2021-12-11 19:37:56] CPU #0: 965.80 kH/s

おおおお、これなんか凄いわ
bitcoinはレベルが違う
### NiceHashの場合
$ ./cpuminer -a sha256d –user=${NiceHash wallet}.raspberrypi4 –url=stratum+tcp://sha256.jp.nicehash.com:3334 -p x –no-color
基本的にはBitcoin.comと同じ
ただ、NiceHashの場合はNiceHash側の管理画面で状況が表示されれる

これは凄いわ、全然レベちだわ
[Blockchain] ラズパイでKotoのマイニング
koto
https://ko-to.org/
### install
$ sudo apt install cpulimit
$ sudo git clone https://github.com/KotoDevelopers/cpuminer-yescrypt cpuminer-koto
$ cd cpuminer-koto
$ sudo ./autogen.sh
$ sudo ./configure CFLAGS=”-O3 -march=native -funroll-loops -fomit-frame-pointer”
$ sudo make
### mining
$ /opt/cpuminer-koto/minerd -a yescrypt -o stratum+tcp://koto.mofumofu.me:3301 -u ZhZYp2PkWNSUXgvWS17bRJgjg6iEuCUY8E
2-11 17:46:41] Stratum authentication failed
[2021-12-11 17:46:41] …retry after 30 seconds
[2021-12-11 17:47:11] Stratum authentication failed
[2021-12-11 17:47:11] …retry after 30 seconds2-11 17:46:41] Stratum authentication failed
[2021-12-11 17:46:41] …retry after 30 seconds
[2021-12-11 17:47:11] Stratum authentication failed
[2021-12-11 17:47:11] …retry after 30 seconds
あれ、authentication failedになっとる… 何故?
もにゃ で、koto用の受け取りアドレスを取得して、再度実行
$ /opt/cpuminer-koto/minerd -a yescrypt -o stratum+tcp://koto.mofumofu.me:3301 -u jzzxRHes5zVvmpweuSc6Kk6vVLsGFiHzyNT
どうやら、bitzenyのアドレスだったので、エラーになっていたっぽい
なるほどー
仮想通貨の価値が低いとminingする気にならんな
[Blockchain] ラズパイでBitZenyのマイニング
BitZenyとはYescryptを採用して普通のPCでもminingできる仮想通貨
https://bitzeny.tech/
まず「もにゃ」というウォレットアプリでウォレットを作ります
https://monya-wallet.github.io/

受け取りマークを押すとアドレスが表示される
ZhZYp2PkWNSUXgvWS17bRJgjg6iEuCUY8E
続いてraspberry pi上での操作
### bitzeny CPU miner
$ sudo apt update
$ sudo apt upgrade
$ cd /opt/
$ sudo git clone https://github.com/bitzeny/cpuminer.git cpuminer
$ cd cpuminer
$ sudo apt install automake
$ sudo apt install gcc
$ sudo apt install libcurl4-openssl-dev
$ sudo ./autogen.sh
$ sudo ./configure CFLAGS=”-O3 -march=native -funroll-loops -fomit-frame-pointer”
$ sudo make
### マイニングプール
https://zny.mofumofu.me/
### mining
$ /opt/cpuminer/minerd -a yescrypt -o stratum+tcp://zny.mofumofu.me:3331 -u ZhZYp2PkWNSUXgvWS17bRJgjg6iEuCUY8E
cpu使用率が100%で張り付いてる

### cpu使用率を抑える方法
オプションで -t 1 をつける
$ /opt/cpuminer/minerd -a yescrypt -o stratum+tcp://zny.mofumofu.me:3331 -u ZhZYp2PkWNSUXgvWS17bRJgjg6iEuCUY8E -t 1
ウォレットに反映されるまで半日〜1日程度かかる
なんだこれえええええええええええええええええ
電気代の方が高そうだけど、なんか凄いわ…
### 追記
よっしゃああああああああああああああああああ
マイニングで稼いだぜ、 0.0218円(無事死亡)

[Blockchain] Helium
ヘリウムはIoTデバイスが低コストでインターネットに送信するネットワーク機器(ホットスポット)
家に設置されたヘリウムは、ノードの位置確認、データのシーケンス確認、ネットワーク経由でデータを送信するデバイスの位置確認など、ネットワークに有益なタスクを実行
公式: https://www.helium.com/
network

eplore
https://explorer.helium.com/
うむ、マイニング装置を置くだけでheliumを貰える理由がよくわらんな…
[Bitcoin] ウォレット
Bitcoinのウォレットとは?
-> 一般的なユーザがビットコインを管理するためのアプリ
-> 主な機能はビットコインの保管と送受信
– 秘密鍵
– ビットコインアドレス
– トランザクションの作成
– 電子署名の作成
秘密鍵とビットコインアドレスで個人を識別している
一人で複数のアドレスを持つことも当たり前となっている
Hierarchical Deterministic Wallet
– 一つのマスター鍵から複数の秘密鍵・アドレスを階層的に生成できる
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
from pycoin.tx import Tx
from pycoin.services import spendables_for_address
from pycoin.services.blockchain_info import BlockchainInfoProvider, send_tx
from pycoin.tx.tx_utils import create_signed_tx
from PyQt5.QtWidgets import (QLabel, QLineEdit, QGridLayout, QWidget,
QApplication, QPushButton, QDesktopWidget,
QTextEdit)
class MainWindow(QWidget):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
address = ""
destination = ""
self.fromaddress = QLineEdit()
self.fromaddress.setText(address)
self.sendto = QLineEdit()
self.sendto.setText(destination)
self.transaction = QTextEdit()
self.transaction.setReadOnly(True)
sendTxBtn = QPushButton('send Tx', self)
sndTxBtn.clicked.connect(self.createTx)
grid = QGridLayout()
grid.setSpacing(10)
grid.addWidget(QLabel('From'), 1,0)
grid.addWidget(self.fromaddress, 1,1)
grid.addWidget(QLabel('Send to'), 2,0)
grid.addWidget(self.sendto, 2,1)
grid.addWidget(QLabel('Transaction'), 3,0)
grid.addWidget(self.transaction, 3, 1, 1, 2)
get.addWidget(sndTxBtn, 4, 1)
self.setLayout(grid)
self.resize(320, 180)
self.center()
self.setWindowTitle('Create transaction demo')
self.show()
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def createTx(self):
address = self.fromaddress.text()
destination = self.sendto.text()
wif = ""
sndtx = BlockchainInfoProvider('BTC')
sendables = sendables_for_address(address, "BTC")
tx = create_signed_tx(sendables, payables=[destination], wifs=[wif])
sndtx.broadcast_tx(tx)
self.transaction.setText(tx.as_hex())
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
sys.exit(app.exec())
generate-key.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
from pycoin.tx import Tx
from pycoin.key.BIP32Node import BIP32Node
from PyQt5.QtWidgets import (QLabel, QLineEdit, QGridLayout, QWidget,
QApplication, QPushButton, QDesktopWidget,
QTextEdit)
def KeyGenerater(s):
key = BIP32Node.from_master_secret(s.encode("utf8"))
return key.wif(), key.address()
class MainWindow(QWidget):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.inputLine = QLineEidt()
self.privateKey = QTextEdit()
self.privateKey.setReadOnly(True)
self.publicKey = QTextEdit()
self.publicKey.setReadOnly(True)
generateBtn = QPushButton('Generate', self)
generateBtn.clicked.connect(self.showKeys)
grid = QGridLayout()
grid.setSpacing(10)
grid.addWidget(QLabel('Input'), 1,0)
grid.addWidget(self.inputLine, 1,1)
grid.addWidget(generateBtn, 1, 2)
grid.addWidget(QLabel('Private Key'), 2,0)
grid.addWidget(self.privateKey, 2,1, 1, 2)
grid.addWidget(QLabel('Public Key'), 3,0)
grid.addWidget(self.publicKey, 3, 1, 1, 2)
self.setLayout(grid)
self.resize(320, 150)
self.center()
self.setWindowTitle('Key generate demo')
self.show()
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def showKeys(self):
text = self.inputLine.text()
private, public = KeyGenerater(text)
self.publicKey.setText(private)
self.publicKey.setText(public)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
sys.exit(app.exec())
OK, keep going
[Bitcoin] マイニング
from hashlib import sha256
text = "ABC"
print(sha256(text.encode('ascii')).hexdigest())
$ python3 main.py
b5d4045c3f466fa91fe2cc6abe79232a1a57cdf104f7a26e716e0a1e2789df78
from hashlib import sha256
MAX_NONCE = 10000000000
def SHA256(text):
return sha256(text.encode('ascii')).hexdigest()
def mine(block_number, transactions, previous_hash, prefix_zeros):
prefix_str = '0'*prefix_zeros
for nonce in range(MAX_NONCE):
text = str(block_number) + transactions + previous_hash + str(nonce)
new_hash = SHA256(text)
if new_hash.startswith(prefix_str):
print(f"Yay! Successfully mined bitcoins with nonce value:{nonce}")
return new_hash
raise BaseException(f"Couldn't find correct has after trying {MAX_NONCE} times")
if __name__ == '__main__':
transactions='''
Bob->Alice->20,
Ken->Ryu->45
'''
difficulty=6
new_hash = mine(5, transactions, '00000000000008a3a41b85b8b29ad444def299fee21793cd8b9e567eab02cd81', difficulty)
print(new_hash)
bitcoin hardware
https://www.buybitcoinworldwide.com/mining/hardware/
bitcoin explore
https://www.blockchain.com/explorer
https://www.blockchain.com/btc/blocks?page=1
bitcoin block1
https://www.blockchain.com/btc/block/1
なるほど、前後の処理が知りたいのう
パスポートの文字をtesseractで読み込む
try:
from PIL import Image
except ImportError:
import Image
import pytesseract
FILENAME = 'test.jpg'
text = pytesseract.image_to_string(Image.open(FILENAME))
lines = text.split("\n")
for line in lines:
if '<<<' in line:
t = line.replace(' ', '')
print(t)
test1.png P<GBRUK<SPECIMEN<<ANGELA<ZOE<<<<<<<<<<<<<<<< 5334755143GBR8812049F2509286<<<<<<<<<<c<<<04 test2.png PDCYPPOLITIS<<ZINONAS<<<<<<<<<<<<<<KKKKKKKKK FOOOOOD005CYP8012148M3006151<<<<<<<<<<<<<<02 test3.png PTNOROESTENBYEN<<AASAMUND<SPECIMEN<<<<<<<<<< FHCO023539NOR5604230M2506126<<<<<<<<<<<<<<00
なぜか変な文字列が混ざりますね
def convert(Filename):
img = Image.open(Filename)
img=img.convert('RGB')
size=img.size
img2=Image.new('RGB',size)
border=110
for x in range(size[0]):
for y in range(size[1]):
r,g,b=img.getpixel((x,y))
if r > border or g > border or b > border:
r = 255
g = 255
b = 255
img2.putpixel((x,y),(r,g,b))
return img2
text = pytesseract.image_to_string(convert('test.jpg'))
lines = text.split("\n")
for line in lines:
if '<<<' in line:
print(line)
うーむ、ちょっと違うかな
VPSでLet’s encryptを導入する
IPアドレス指定でアクセスする場合のSSLには対応していないので、独自ドメインをあらかじめ取得・設定しておく必要がある
$ sudo a2enmod ssl
$ sudo a2ensite default-ssl
$ service apache2 reload
$ sudo vi /etc/apache2/sites-available/virtual.host.conf
<VirtualHost *:80>
DocumentRoot /var/www/node
ServerName hoge.site
#ServerAlias www.hoge.site
# Other directives here
RewriteEngine on
RewriteCond %{SERVER_NAME} =hoge.site [OR]
RewriteCond %{SERVER_NAME} =www.hoge.site
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost _default_:443>
DocumentRoot /var/www/node
ServerName hoge.site
ServerAlias www.hoge.site
# Other directives here
SSLCertificateFile /etc/letsencrypt/live/hoge.site/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hoge.site/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
$ sudo apt install firewalld
$ sudo firewall-cmd –add-service=http –zone=public –permanent
$ sudo firewall-cmd –add-service=https –zone=public –permanent
$ sudo systemctl restart firewalld
$ sudo firewall-cmd –list-all
services: dhcpv6-client http https ssh
$ sudo apt-get install certbot python3-certbot-apache
$ certbot –apache -d hoge-test.site

ほう
Pythonでインスタンスセグメンテーション
$ sudo apt -y install python3-six python3-wheel python3-numpy python3-grpcio python3-protobuf python3-termcolor python3-typing-extensions python3-h5py python3-markdown python3-werkzeug python3-requests-oauthlib python3-rsa python3-cachetools python3-google-auth
$ sudo apt -y install python3-numpy python3-sklearn python3-matplotlib python3-seaborn
$ sudo pip3 install -U tensorflow tensorflow_datasets
$ pip3 install pixellib
$ curl -LO https://github.com/ayoolaolafenwa/PixelLib/releases/download/1.2/mask_rcnn_coco.h5
sample2.jpegをDLしてdataフォルダに格納
https://pixellib.readthedocs.io/en/latest/Image_instance.html
import pixellib
from pixellib.instance import instance_segmentation
segment_image = instance_segmentation()
segment_image.load_model("data/mask_rcnn_coco.h5")
segment_image.segmentImage("data/sample2.jpeg", output_image_name = "image_new.jpg")

どういう仕組みなのかは理解したが、イマイチ上手くいかんな…
環境のせいか…