Ejemplo n.º 1
0
 def encode(self):
     input_text = encode_c(self.encode_text.toPlainText())
     if input_text == '':
         msgBox = QMessageBox()
         msgBox.setIcon(QMessageBox.Information)
         msgBox.setText("不能是空的")
         msgBox.setWindowTitle("系统警告")
         msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
         msgBox.buttonClicked.connect(msgButtonClick)
         returnValue = msgBox.exec()
         if returnValue == QMessageBox.Ok:
             return
     length = 35
     temp = [
         input_text[i:i + length] for i in range(0, len(input_text), length)
     ]
     for i in range(len(temp)):
         length_payload = str(format(len(temp[i]), 'b'))  # 7자리
         if len(length_payload) < 8:
             length_payload = length_payload.zfill(8)
         print(temp[i])
         total = preamble + length_payload + temp[i]
         signal = ','.join(list(total))
         time_signal = N * len(total) / sampling_rate
         t = np.arange(0, time_signal, Ts)
         np_signal = np.fromstring(signal, dtype='int', sep=',')
         sample = np.repeat(np_signal, N)
         if (len(t) % 10) != 0:
             t = t[:len(t) - 1]
         y = np.sin(2 * np.pi * (f + sample * 2000) * t)
         write('first.wav', sampling_rate, y)
         samplerate, data = sio.wavfile.read('first.wav')
         sd.play(data, samplerate)
         time.sleep(time_signal + 1)
 def __BROKEN_extract_preview_image(
         buffer):  #FIXME -seems broken, only for jpeg stream
     #stream = urllib.request.urlopen('http://192.168.0.51/video.cgi?resolution=1920x1080')
     a = buffer.find(b'\xff\xd8')
     b = buffer.find(b'\xff\xd9')
     if a != -1 and b != -1 and b > a:
         jpg = buffer[a:b + 2]
         filename = 'capture.jpeg'
         import cv2, np
         i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),
                          cv2.IMREAD_COLOR)
         cv2.imwrite(filename, i)
         return filename
     else:
         print(">>>>>>>>", a, b, buffer)
         logger.warning(
             "Couldn't find a preview frame in RTSP buffer of length %s" %
             len(buffer))
     """ SEE:
Ejemplo n.º 3
0
import csv
import math
form_class = uic.loadUiType("gui_for_translate.ui")[0]

sampling_rate = 48000
symbol_duration = 0.025
f = 4000
N = sampling_rate * symbol_duration
Ts = 1 / sampling_rate
FILENAME = "tmp.wav"
preamble = '01010101010101010101'

preamble_signal = ','.join(list(preamble))
preamble_time_signal = N * len(preamble) / sampling_rate
preamble_t = np.arange(0, preamble_time_signal, Ts)
preamble_np_signal = np.fromstring(preamble_signal, dtype='int', sep=',')
preamble_sample = np.repeat(preamble_np_signal, N)
preamble_y = np.sin(2 * np.pi * (f + preamble_sample * 2000) * preamble_t)


def encode_c(s):
    return ''.join([bin(ord(c)).replace('0b', '') for c in s])


def decode_c(s):
    return ''.join([chr(i) for i in [int(b, 2) for b in s.split(' ')]])


class ThreadClass(QThread):
    def __init__(self):
        super().__init__()
Ejemplo n.º 4
0
def handler(q=False):
    if q is False:
        return False
    q = json.loads(q)
    filename = q['attachment']
    try:
        img_array = np.fromstring(binascii.a2b_base64(q['data']), np.uint8)
    except:
        err = "Couldn't fetch attachment (JSON 'data' is empty). Are you using the 'Query enrichment' action?"
        misperrors['error'] = err
        print(err)
        return misperrors
    image = cv2.imdecode(img_array, cv2.IMREAD_COLOR)
    if q:
        barcodes = pyzbar.decode(image)
    for item in barcodes:
        try:
            result = item.data.decode()
        except Exception as e:
            print(e)
            return
        if debug:
            print(debug_prefix + result)
        for item in cryptocurrencies:
            if item in result:
                try:
                    currency, address, extra = re.split('\:|\?', result)
                except Exception as e:
                    print(e)
                if currency in cryptocurrencies:
                    try:
                        amount = re.split('=', extra)[1]
                        if debug:
                            print(debug_prefix + address)
                            print(debug_prefix + amount)
                        return {
                            'results': [{
                                'types': ['btc'],
                                'values':
                                address,
                                'comment':
                                "BTC: " + amount + " from file " + filename
                            }]
                        }
                    except Exception as e:
                        print(e)
                else:
                    print(address)
        for item in schemas:
            if item in result:
                try:
                    url = result
                    if debug:
                        print(debug_prefix + url)
                    return {
                        'results': [{
                            'types': ['url'],
                            'values':
                            url,
                            'comment':
                            "from QR code of file " + filename
                        }]
                    }
                except Exception as e:
                    print(e)
            else:
                try:
                    return {
                        'results': [{
                            'types': ['text'],
                            'values':
                            result,
                            'comment':
                            "from QR code of file " + filename
                        }]
                    }
                except Exception as e:
                    print(e)
    misperrors['error'] = "Couldn't decode QR code in attachment."
    return misperrors