Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

convert c_ubyte_Array_ to opencv

def Mono_numpy(data, nWidth, nHeight):
    data_ = np.frombuffer(data, count=int(nWidth * nHeight), dtype=np.uint8, offset=0)
    data_mono_arr = data_.reshape(nHeight, nWidth)
    numArray = np.zeros([nHeight, nWidth, 1], "uint8")
    numArray[:, :, 0] = data_mono_arr
    return numArray


def Color_numpy(data, nWidth, nHeight):
    data_ = np.frombuffer(data, count=int(nWidth * nHeight * 3), dtype=np.uint8, offset=0)
    data_r = data_[0:nWidth * nHeight * 3:3]
    data_g = data_[1:nWidth * nHeight * 3:3]
    data_b = data_[2:nWidth * nHeight * 3:3]

    data_r_arr = data_r.reshape(nHeight, nWidth)
    data_g_arr = data_g.reshape(nHeight, nWidth)
    data_b_arr = data_b.reshape(nHeight, nWidth)
    numArray = np.zeros([nHeight, nWidth, 3], "uint8")

    numArray[:, :, 0] = data_r_arr
    numArray[:, :, 1] = data_g_arr
    numArray[:, :, 2] = data_b_arr
    return numArray
Comment

PREVIOUS NEXT
Code Example
Python :: python get num classes from label encoder 
Python :: use miraculous with token 
Python :: Square of numbers in non-decreasing order 
Python :: hoe maak je machten in python 
Python :: python Split a file path into root and extension 
Python :: Simulate webcam and microphone selenium 
Python :: error popup in django not visible 
Python :: what is the meaning of illiteral with base 10 
Python :: get current file location 
Python :: python program for simple interest 
Python :: matplotlib subtitle 
Python :: python program for geometric progression 
Python :: virtual env in mac 
Python :: python init matrix 
Python :: copy file in python3 
Python :: reverse keys and values in dictionary with zip python 
Python :: build spacy custom ner model stackoverflow 
Python :: fizzbuzz python 
Python :: python dump object print 
Python :: python make integer into a list 
Python :: python temp directory 
Python :: replace the jinja template value inside the dictionary python 
Python :: youtube to mp3 python 
Python :: firebase python upload storage 
Python :: np.sort descending 
Python :: how to subtract minutes from time in python 
Python :: python remove non empty read only directory 
Python :: how many data types are specified to numeric values in python 
Python :: Replace empty string and "records with only spaces" with npnan pandas 
Python :: write txt python 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =