Exemple #1
0
    def add_a_drop(self, d_byte):
        a_drop = self.glass.droplet_from_Bytes(d_byte)
        print("++ seed: {}\tnum_chunk : {}\tdata len: {}+++++".format(a_drop.seed, a_drop.num_chunks, len(a_drop.data)))
        ew_drop = EW_Droplet(a_drop.data, a_drop.seed, a_drop.num_chunks)

        if self.glass.num_chunks == 0:
            print('init num_chunks : ', a_drop.num_chunks)
            self.glass = Glass(a_drop.num_chunks)
            self.chunk_size = len(a_drop.data)

        self.glass.addDroplet(ew_drop)
        self.recv_bit = self.glass.get_bits()
        #  print('recv bits length : ', int(self.recv_bit.length()))
        if (int(self.recv_bit.length()) > 0) and \
                (self.recv_bit.length() > self.current_recv_bits_len):
            self.current_recv_bits_len = self.recv_bit.length()
            self.i_spiht = self._123(self.recv_bit, self.chunk_size)
            try:
                self.i_dwt[0] = spiht_decode(self.i_spiht[0], self.eng)
                self.i_dwt[1] = spiht_decode(self.i_spiht[1], self.eng)
                self.i_dwt[2] = spiht_decode(self.i_spiht[2], self.eng)
                self.img_mat = [func_IDWT(ii) for ii in self.i_dwt]

                #  单通道处理
                #  self.idwt_coeff_r = spiht_decode(self.recv_bit, self.eng)
                #  self.r_mat =func_IDWT(self.idwt_coeff_r)
                self.img_shape = self.img_mat[0].shape
                self.show_recv_img()
            except:
                print('decode error in matlab')
Exemple #2
0
    def add_a_drop(self, d_byte):
        drop = self.glass.droplet_from_Bytes(d_byte)

        if self.glass.num_chunks == 0:
            print('init num_chunks : ', drop.num_chunks)
            self.glass = Glass(drop.num_chunks)
            self.chunk_size = len(drop.data)

        self.glass.addDroplet(drop)

        self.recv_bit = self.glass.get_bits()
        #  print('recv bits length : ', int(self.recv_bit.length()))
        if (int(self.recv_bit.length()) > 0) and \
                (self.recv_bit.length() > self.current_recv_bits_len):
            self.current_recv_bits_len = int(self.recv_bit.length())
            #  self.recv_bit.tofile(open('./recv_tmp.txt', 'w'))
            self.i_spiht = self._123(self.recv_bit, self.chunk_size)
            #  self.i_dwt = [spiht_decode(ii, self.eng) for ii in self.i_spiht]
            try:
                self.i_dwt[0] = spiht_decode(self.i_spiht[0], self.eng)
                self.i_dwt[1] = spiht_decode(self.i_spiht[1], self.eng)
                self.i_dwt[2] = spiht_decode(self.i_spiht[2], self.eng)
                self.img_mat = [func_IDWT(ii) for ii in self.i_dwt]

                #  单通道处理
                #  self.idwt_coeff_r = spiht_decode(self.recv_bit, self.eng)
                #  self.r_mat =func_IDWT(self.idwt_coeff_r)
                self.img_shape = self.img_mat[0].shape
                self.show_recv_img()
            except:
                print('decode error in matlab')
Exemple #3
0
    def rs_recv_main(self):
        recv_time_start = time.time()
        self.recv_byte = self.catch_rs_use_serial()

        if self.recv_byte is not None:
            rs_decode_start = time.time()
            rs_decoded = rs_decode_image(self.recv_byte)
            rs_decode_end = time.time()
            print('RS decode time:', rs_decode_end - rs_decode_start)
            bitarray_factory = bitarray.bitarray(endian='big')
            bitarray_factory.frombytes(rs_decoded)

            # if bitarray_factory is not None:
            # test = int(ceil(len(bitarray_factory) / 5))
            self.i_spiht = self._123(bitarray_factory)
            try:
                SPIHT_time_start = time.time()
                self.i_dwt[0] = spiht_decode(self.i_spiht[0], self.eng)
                self.i_dwt[1] = spiht_decode(self.i_spiht[1], self.eng)
                self.i_dwt[2] = spiht_decode(self.i_spiht[2], self.eng)
                self.img_mat = [func_IDWT(ii) for ii in self.i_dwt]
                SPIHT_time_end = time.time()
                print('SPIHT decode time:', SPIHT_time_end - SPIHT_time_start)
                self.img_shape = self.img_mat[0].shape
                self.show_recv_img()

                self.recv_done_flag = True
                recv_time_end = time.time()
                print('recv time total cost:', recv_time_end - recv_time_start)
                self.send_recv_done_ack()

            except:
                print('Decode error in matlab')
Exemple #4
0
    def add_a_drop(self, d_byte):
        recv_time_start = time.time()
        drop = self.glass.droplet_from_Bytes(d_byte)  # drop

        print('drop data len: ', len(drop.data))

        if self.glass.num_chunks == 0:
            print('init num_chunks : ', drop.num_chunks)
            self.glass = Glass(drop.num_chunks)  # 初始化接收glass
            self.chunk_size = len(drop.data)

        lt_decode_start = time.time()
        self.glass.addDroplet(drop)  # glass add drops

        logging.info('current chunks')
        logging.info(
            [ii if ii == None else '++++' for ii in self.glass.chunks])

        if self.glass.isDone():
            lt_decode_end = time.time()
            print('LT decode time:', lt_decode_end - lt_decode_start)

            self.recv_bit = self.glass.get_bits()  # bits

            # a = self.recv_bit.length()
            print('recv bits length : ', int(self.recv_bit.length()))

            if (int(self.recv_bit.length()) > 0) and \
                    (self.recv_bit.length() > self.current_recv_bits_len):
                self.current_recv_bits_len = int(self.recv_bit.length())

                self.i_spiht = self._123(self.recv_bit)
                try:
                    SPIHT_time_start = time.time()
                    self.i_dwt[0] = spiht_decode(self.i_spiht[0], self.eng)
                    self.i_dwt[1] = spiht_decode(self.i_spiht[1], self.eng)
                    self.i_dwt[2] = spiht_decode(self.i_spiht[2], self.eng)
                    self.img_mat = [func_IDWT(ii) for ii in self.i_dwt]
                    SPIHT_time_end = time.time()
                    print('SPIHT decode time:',
                          SPIHT_time_end - SPIHT_time_start)
                    print('recv time total cost:',
                          SPIHT_time_end - recv_time_start)

                    #  单通道处理
                    #  self.idwt_coeff_r = spiht_decode(self.recv_bit, self.eng)
                    #  self.r_mat =func_IDWT(self.idwt_coeff_r)
                    self.img_shape = self.img_mat[0].shape
                    self.show_recv_img()
                    self.recv_done_flag = True
                    self.send_recv_done_ack()
                except:
                    print('Decode error in matlab')
Exemple #5
0
    def add_a_drop(self, d_byte):
        a_drop = self.glass.droplet_from_Bytes(d_byte)
        print("seed: {}\tnum_chunk : {}\tdata len: {}".format(
            a_drop.seed, a_drop.num_chunks, len(a_drop.data)))
        ew_drop = EW_Droplet(a_drop.data, a_drop.seed, a_drop.num_chunks)

        if self.glass.num_chunks == 0:
            self.wlt_ds = time.time()
            print('init num_chunks : ', a_drop.num_chunks)
            self.glass = Glass(a_drop.num_chunks)
            self.chunk_size = len(a_drop.data)

        self.glass.addDroplet(ew_drop)

        logging.info('current chunks')
        logging.info(
            [ii if ii == None else '++++' for ii in self.glass.chunks])

        # 解码w1信息
        w1_size = 0.1
        if self.glass.is_w1_done(w1_size) and self.w1_done:
            print('w1_data complete!')
            w1_bits = self.glass.get_w1_bits(
                int(round(self.glass.num_chunks * w1_size)))
            self.w1_done = False
            if (int(w1_bits.length()) > 0) and \
                    (w1_bits.length() > self.current_recv_bits_len):
                self.current_recv_bits_len = w1_bits.length()
                self.i_spiht = self.w1_123(w1_bits)

                try:
                    self.i_dwt[0] = spiht_decode(self.i_spiht[0], self.eng)
                    self.i_dwt[1] = spiht_decode(self.i_spiht[1], self.eng)
                    self.i_dwt[2] = spiht_decode(self.i_spiht[2], self.eng)
                    self.img_mat = [func_IDWT(ii) for ii in self.i_dwt]

                    #  单通道处理
                    #  self.idwt_coeff_r = spiht_decode(self.recv_bit, self.eng)
                    #  self.r_mat =func_IDWT(self.idwt_coeff_r)
                    self.img_shape = self.img_mat[0].shape
                    self.show_recv_img()
                except:
                    print('decode error in matlab')

        # 解码全部信息
        if self.glass.isDone():  # 喷泉码接收译码完成
            wlt_de = time.time()
            print('Window LT decode time used:', wlt_de - self.wlt_ds)
            self.recv_bit = self.glass.get_bits()
            #  print('recv bits length : ', int(self.recv_bit.length()))
            if (int(self.recv_bit.length()) > 0) and \
                    (self.recv_bit.length() > self.current_recv_bits_len):
                self.current_recv_bits_len = self.recv_bit.length()
                self.i_spiht = self._123(self.recv_bit)
                try:
                    spihtstart = time.time()
                    self.i_dwt[0] = spiht_decode(self.i_spiht[0], self.eng)
                    self.i_dwt[1] = spiht_decode(self.i_spiht[1], self.eng)
                    self.i_dwt[2] = spiht_decode(self.i_spiht[2], self.eng)
                    self.img_mat = [func_IDWT(ii) for ii in self.i_dwt]
                    spihtend = time.time()
                    print('SPIHT decode time:', spihtend - spihtstart)
                    #  单通道处理
                    #  self.idwt_coeff_r = spiht_decode(self.recv_bit, self.eng)
                    #  self.r_mat =func_IDWT(self.idwt_coeff_r)
                    self.img_shape = self.img_mat[0].shape
                    self.show_recv_img()
                    self.recv_done_flag = True
                    self.send_recv_done_ack()
                except:
                    print('decode error in matlab')