示例#1
0
    def _run_(self):
        '''
        '''
        #print '- Running Mjpeg Decoder...'
        hf = h.HuffCoDec(self.hufftables)
        r, c, chnl = self.R, self.C, self.NCHNL
        Z = self.Z
        
        #hufcd = self.huffcodes#self.fl.readline()[:-1]
        if self.mode == '444':
            for ch in range(chnl):                #hufcd = self.fl.readline()[:-1]            #    print hufcd[0:20]
                nblk, seqrec = hf.invhuff(self.huffcodes[ch], ch)
                for i in range(self.nBlkRows):
                    for j in range(self.nBlkCols):
                        blk = h.zagzig(seqrec[i*self.nBlkCols + j])
                        self.imRaw[r*i:r*i+r, c*j:c*j+c, ch] = np.round_( cv2.idct( blk*Z[:,:,ch] ))
                        
        elif self.mode == '420':
            #import math as m
            if chnl == 1:
                rYmg = self.imRaw
            else:                #Y = self.imRaw[:,:,0]
                Y = np.zeros( (self.M, self.N) )
                dims, CrCb = h.adjImg( downsample(np.zeros( (self.M, self.N, 2) ), self.mode)[1] )
                rYmg = [ Y, CrCb[:,:,0], CrCb[:,:,1] ]
                
            for ch in range(chnl):
                #hufcd = self.fl.readline()[:-1]
                if ch == 0:
                    rBLK = self.nBlkRows
                    cBLK = self.nBlkCols
                else:
                    rBLK, cBLK = int(np.floor(dims[0]/self.R)), int(np.floor(dims[1]/self.C))
            #    print hufcd[0:20]
                nblk, self.seqrec = hf.invhuff(self.huffcodes[ch], ch)
                for i in range(rBLK):
                    for j in range(cBLK):
                        blk = h.zagzig(self.seqrec[i*cBLK + j])
                        #print rYmg[ch][r*i:r*i+r, c*j:c*j+c].shape, ch, i, j
                        rYmg[ch][r*i:r*i+r, c*j:c*j+c] = np.round_( cv2.idct( blk*Z[:,:,ch] ))
            # UPSAMPLE
            if chnl == 1:
                self.imRaw = rYmg #[:self.Mo, : self.No]
            else:
                self.imRaw[:,:,0] = rYmg[0]
                self.imRaw[:,:,1] = upsample(rYmg[1], self.mode)[:self.M, :self.N]
                self.imRaw[:,:,2] = upsample(rYmg[2], self.mode)[:self.M, :self.N]
        
        #self.fl.close()
        
#        imrec = cv2.cvtColor((self.imRaw[:self.Mo, :self.No]+128), cv2.COLOR_YCR_CB2BGR)
#        imrec = self.imRaw[:self.Mo, :self.No]+128
        imrec = self.imRaw+128.0
#        imrec[imrec>255.0]=255.0
#        imrec[imrec<0.0]=0.0
								
        #print 'Mjpeg Decoder Complete...'
        
        return imrec
示例#2
0
 def _run_(self):
     '''
     '''
     print '- Running Decoder...'
     hf = h.HuffCoDec()
     r, c, chnl = self.R, self.C, self.NCHNL
     Z = self.Z
     
     if self.mode == '444':
         for ch in range(chnl):
             hufcd = self.fl.readline()[:-1]
         #    print hufcd[0:20]
             nblk, seqrec = hf.invhuff(hufcd, ch)
             for i in range(self.nBlkRows):
                 for j in range(self.nBlkCols):
                     blk = h.zagzig(seqrec[i*self.nBlkCols + j])
                     self.imRaw[r*i:r*i+r, c*j:c*j+c, ch] = np.round_( cv2.idct( blk*Z[:,:,ch] ))
                     
     elif self.mode == '420':
         #import math as m
         if chnl == 1:
             rYmg = self.imRaw
         else:                #Y = self.imRaw[:,:,0]
             Y = np.zeros( (self.M, self.N) )
             dims, CrCb = h.adjImg( downsample(np.zeros( (self.M, self.N, 2) ), self.mode)[1] )
             rYmg = [ Y, CrCb[:,:,0], CrCb[:,:,1] ]
             
         for ch in range(chnl):
             hufcd = self.fl.readline()[:-1]
             if ch == 0:
                 rBLK = self.nBlkRows
                 cBLK = self.nBlkCols
             else:
                 rBLK, cBLK = int(np.floor(dims[0]/self.R)), int(np.floor(dims[1]/self.C))
         #    print hufcd[0:20]
             nblk, self.seqrec = hf.invhuff(hufcd, ch)
             for i in range(rBLK):
                 for j in range(cBLK):
                     blk = h.zagzig(self.seqrec[i*cBLK + j])
                     #print rYmg[ch][r*i:r*i+r, c*j:c*j+c].shape, ch, i, j
                     rYmg[ch][r*i:r*i+r, c*j:c*j+c] = np.round_( cv2.idct( blk*Z[:,:,ch] ))
         # UPSAMPLE
         if chnl == 1:
             self.imRaw = rYmg #[:self.Mo, : self.No]
         else:
             self.imRaw[:,:,0] = rYmg[0]
             self.imRaw[:,:,1] = upsample(rYmg[1], self.mode)[:self.M, :self.N]
             self.imRaw[:,:,2] = upsample(rYmg[2], self.mode)[:self.M, :self.N]
     
     self.fl.close()
     
     imrec = cv2.cvtColor((self.imRaw[:self.Mo, :self.No]+128), cv2.COLOR_YCR_CB2BGR)
     imrec[imrec>255]=255
     imrec[imrec<0]=0
     
     print 'Decoder Complete...'
     
     return np.uint8(imrec)
示例#3
0
    def _run_(self):
        '''
        '''
        #print '- Running Mjpeg Decoder...'
        hf = h.HuffCoDec(self.hufftables)
        r, c, chnl = self.R, self.C, self.NCHNL


        if self.mode == '444':
            for ch in range(chnl):                #hufcd = self.fl.readline()[:-1]            #    print hufcd[0:20]
                nblk, seqrec = hf.invhuff(self.huffcodes[ch], ch)
                a, b = [0, 0]
                for i in range(self.nBlkRows):
                    for j in range(self.nBlkCols):
                
                        #    SELEÇÃO DA MATRIZ DE QUANTIZAÇÃO
                        vec_index = int(a*(self.nBlkCols/2)+b)
                        # Quantization table
                        Z = 0
                        if len(self.motionVec[vec_index]) == 2:
                            Z = self.hvstables[abs(self.motionVec[vec_index][0])][abs(self.motionVec[vec_index][1])]
                        elif len(self.motionVec[vec_index]) == 3:
                            Z = self.hvstables[abs(self.motionVec[vec_index][1])][abs(self.motionVec[vec_index][2])]
                        else:
                            Z = self.hvstables[int((abs(self.motionVec[vec_index][1])+abs(self.motionVec[vec_index][3]))/2.)][int((abs(self.motionVec[vec_index][2])+abs(self.motionVec[vec_index][4]))/2.)]
      
                        blk = h.zagzig(seqrec[i*self.nBlkCols + j])
                        self.imRaw[r*i:r*i+r, c*j:c*j+c, ch] = np.round_( cv2.idct( blk*Z ))
                        if j%2 != 0:
                            b += 1
                    if i%2 != 0:																												
                        a += 1
                        b = 0
                    else:
                        b = 0
                        
        elif self.mode == '420':
            #import math as m
            if chnl == 1:
                rYmg = self.imRaw
            else:                #Y = self.imRaw[:,:,0]
                Y = np.zeros( (self.M, self.N) )
                dims, CrCb = h.adjImg( downsample(np.zeros( (self.M, self.N, 2) ), self.mode)[1] )
                rYmg = [ Y, CrCb[:,:,0], CrCb[:,:,1] ]
                
            for ch in range(chnl):
                a, b = [0, 0]
                if ch == 0:
                    rBLK = self.nBlkRows
                    cBLK = self.nBlkCols
                else:
                    rBLK, cBLK = int(np.floor(dims[0]/self.R)), int(np.floor(dims[1]/self.C))
            #    print hufcd[0:20]
                nblk, self.seqrec = hf.invhuff(self.huffcodes[ch], ch)
                for i in range(rBLK):
                    for j in range(cBLK):
                        
                
                        #    SELEÇÃO DA MATRIZ DE QUANTIZAÇÃO
                        vec_index = 0
                        if ch == 0: #LUMINANCIA
                            vec_index = int(a*(self.nBlkCols/2)+b)
                        else:       #CROMINANCIA
                            vec_index = int(a*(self.nBlkCols/2)+b)
                        # Quantization table
                        Z = 0
                        if len(self.motionVec[vec_index]) == 2:
                            Z = self.hvstables[abs(self.motionVec[vec_index][0])][abs(self.motionVec[vec_index][1])]
                        elif len(self.motionVec[vec_index]) == 3:
                            Z = self.hvstables[abs(self.motionVec[vec_index][1])][abs(self.motionVec[vec_index][2])]
                        else:
                            Z = self.hvstables[int((abs(self.motionVec[vec_index][1])+abs(self.motionVec[vec_index][3]))/2.)][int((abs(self.motionVec[vec_index][2])+abs(self.motionVec[vec_index][4]))/2.)]
                            
                        blk = h.zagzig(self.seqrec[i*cBLK + j])
                        #print rYmg[ch][r*i:r*i+r, c*j:c*j+c].shape, ch, i, j
                        rYmg[ch][r*i:r*i+r, c*j:c*j+c] = np.round_( cv2.idct( blk*Z ))
                        if ch == 0:
                            if j%2 != 0:
                                b += 1
                            else:
                                pass
                        else:
                            b += 1
                    if ch == 0:
                        if i%2 != 0:
                            a += 1
                            b = 0
                        else:
                            b = 0
                    else:
                        a += 1
                        b = 0
            # UPSAMPLE
            if chnl == 1:
                self.imRaw = rYmg #[:self.Mo, : self.No]
            else:
                self.imRaw[:,:,0] = rYmg[0]
                self.imRaw[:,:,1] = upsample(rYmg[1], self.mode)[:self.M, :self.N]
                self.imRaw[:,:,2] = upsample(rYmg[2], self.mode)[:self.M, :self.N]
        
        #self.fl.close()
        
#        imrec = cv2.cvtColor((self.imRaw[:self.Mo, :self.No]+128), cv2.COLOR_YCR_CB2BGR)
#        imrec = self.imRaw[:self.Mo, :self.No]+128
        imrec = self.imRaw+128.0
#        imrec[imrec>255.0]=255.0
#        imrec[imrec<0.0]=0.0
								
        #print 'Mjpeg Decoder Complete...'
        
        return imrec
示例#4
0
    def _run_(self):
        '''
        '''
        #print '- Running Mjpeg Decoder...'
        hf = h.HuffCoDec(self.hufftables)
        r, c, chnl = self.R, self.C, self.NCHNL

        if self.mode == '444':
            for ch in range(
                    chnl
            ):  #hufcd = self.fl.readline()[:-1]            #    print hufcd[0:20]
                nblk, seqrec = hf.invhuff(self.huffcodes[ch], ch)
                a, b = [0, 0]
                for i in range(self.nBlkRows):
                    for j in range(self.nBlkCols):

                        #    SELEÇÃO DA MATRIZ DE QUANTIZAÇÃO
                        vec_index = int(a * (self.nBlkCols / 2) + b)
                        # Quantization table
                        Z = 0
                        if len(self.motionVec[vec_index]) == 2:
                            Z = self.hvstables[abs(
                                self.motionVec[vec_index][0])][abs(
                                    self.motionVec[vec_index][1])]
                        elif len(self.motionVec[vec_index]) == 3:
                            Z = self.hvstables[abs(
                                self.motionVec[vec_index][1])][abs(
                                    self.motionVec[vec_index][2])]
                        else:
                            Z = self.hvstables[int(
                                (abs(self.motionVec[vec_index][1]) +
                                 abs(self.motionVec[vec_index][3])) / 2.)][int(
                                     (abs(self.motionVec[vec_index][2]) +
                                      abs(self.motionVec[vec_index][4])) / 2.)]

                        blk = h.zagzig(seqrec[i * self.nBlkCols + j])
                        self.imRaw[r * i:r * i + r, c * j:c * j + c,
                                   ch] = np.round_(cv2.idct(blk * Z))
                        if j % 2 != 0:
                            b += 1
                    if i % 2 != 0:
                        a += 1
                        b = 0
                    else:
                        b = 0

        elif self.mode == '420':
            #import math as m
            if chnl == 1:
                rYmg = self.imRaw
            else:  #Y = self.imRaw[:,:,0]
                Y = np.zeros((self.M, self.N))
                dims, CrCb = h.adjImg(
                    downsample(np.zeros((self.M, self.N, 2)), self.mode)[1])
                rYmg = [Y, CrCb[:, :, 0], CrCb[:, :, 1]]

            for ch in range(chnl):
                a, b = [0, 0]
                if ch == 0:
                    rBLK = self.nBlkRows
                    cBLK = self.nBlkCols
                else:
                    rBLK, cBLK = int(np.floor(dims[0] / self.R)), int(
                        np.floor(dims[1] / self.C))
            #    print hufcd[0:20]
                nblk, self.seqrec = hf.invhuff(self.huffcodes[ch], ch)
                for i in range(rBLK):
                    for j in range(cBLK):

                        #    SELEÇÃO DA MATRIZ DE QUANTIZAÇÃO
                        vec_index = 0
                        if ch == 0:  #LUMINANCIA
                            vec_index = int(a * (self.nBlkCols / 2) + b)
                        else:  #CROMINANCIA
                            vec_index = int(a * (self.nBlkCols / 2) + b)
                        # Quantization table
                        Z = 0
                        if len(self.motionVec[vec_index]) == 2:
                            Z = self.hvstables[abs(
                                self.motionVec[vec_index][0])][abs(
                                    self.motionVec[vec_index][1])]
                        elif len(self.motionVec[vec_index]) == 3:
                            Z = self.hvstables[abs(
                                self.motionVec[vec_index][1])][abs(
                                    self.motionVec[vec_index][2])]
                        else:
                            Z = self.hvstables[int(
                                (abs(self.motionVec[vec_index][1]) +
                                 abs(self.motionVec[vec_index][3])) / 2.)][int(
                                     (abs(self.motionVec[vec_index][2]) +
                                      abs(self.motionVec[vec_index][4])) / 2.)]

                        blk = h.zagzig(self.seqrec[i * cBLK + j])
                        #print rYmg[ch][r*i:r*i+r, c*j:c*j+c].shape, ch, i, j
                        rYmg[ch][r * i:r * i + r, c * j:c * j + c] = np.round_(
                            cv2.idct(blk * Z))
                        if ch == 0:
                            if j % 2 != 0:
                                b += 1
                            else:
                                pass
                        else:
                            b += 1
                    if ch == 0:
                        if i % 2 != 0:
                            a += 1
                            b = 0
                        else:
                            b = 0
                    else:
                        a += 1
                        b = 0
            # UPSAMPLE
            if chnl == 1:
                self.imRaw = rYmg  #[:self.Mo, : self.No]
            else:
                self.imRaw[:, :, 0] = rYmg[0]
                self.imRaw[:, :, 1] = upsample(rYmg[1],
                                               self.mode)[:self.M, :self.N]
                self.imRaw[:, :, 2] = upsample(rYmg[2],
                                               self.mode)[:self.M, :self.N]

        #self.fl.close()


#        imrec = cv2.cvtColor((self.imRaw[:self.Mo, :self.No]+128), cv2.COLOR_YCR_CB2BGR)
#        imrec = self.imRaw[:self.Mo, :self.No]+128
        imrec = self.imRaw + 128.0
        #        imrec[imrec>255.0]=255.0
        #        imrec[imrec<0.0]=0.0

        #print 'Mjpeg Decoder Complete...'

        return imrec