本文整理汇总了C++中Mat::elemSize方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat::elemSize方法的具体用法?C++ Mat::elemSize怎么用?C++ Mat::elemSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mat
的用法示例。
在下文中一共展示了Mat::elemSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: resizeMatChannelType
template<typename _Tp> void resizeMatChannelType(Mat& src_mat, Mat& dest_mat, double val)
{
CV_Assert(!src_mat.empty() && !dest_mat.empty());
CV_Assert(src_mat.cols == dest_mat.cols && src_mat.rows == dest_mat.rows);
int src_channel = src_mat.channels();
int dest_channel = dest_mat.channels();
int diff_channel = dest_channel - src_channel;
int byte_size = src_mat.elemSize1();
int src_block = src_mat.elemSize();
int dest_block = dest_mat.elemSize();
int mat_size = src_mat.rows * src_mat.cols;
int copy_channel = (diff_channel < 0) ? dest_channel : src_channel;
int copy_byte = copy_channel * byte_size;
int type = src_mat.depth();
unsigned char* src_data = src_mat.data;
unsigned char* dest_data = dest_mat.data;
unsigned char* dest_ptr;
int i,j;
for(i=0; i<mat_size; i++){
memcpy(dest_data+i*dest_block, src_data+i*src_block, copy_byte);
for(j=0;j<diff_channel;j++){
dest_ptr = dest_data + i*dest_block + copy_byte + j*byte_size;
*((_Tp*)dest_ptr) = (_Tp)val;
}
}
}
示例2: if
static void DCT_1D( const Mat& _src, Mat& _dst, int flags, const Mat& _wave=Mat() )
{
_dst.create( _src.size(), _src.type() );
int i, j, n = _dst.cols + _dst.rows - 1;
Mat wave = _wave;
int srcstep = 1, dststep = 1;
double* w;
CV_Assert( _src.cols + _src.rows - 1 == n);
if( wave.empty() )
wave = initDCTWave( n, (flags & DFT_INVERSE) != 0 );
w = wave.ptr<double>();
if( !_src.isContinuous() )
srcstep = (int)(_src.step/_src.elemSize());
if( !_dst.isContinuous() )
dststep = (int)(_dst.step/_dst.elemSize());
if( _src.type() == CV_32FC1 )
{
float *dst = _dst.ptr<float>();
for( i = 0; i < n; i++, dst += dststep )
{
const float* src = _src.ptr<float>();
double sum = 0;
for( j = 0; j < n; j++, src += srcstep )
sum += src[0]*w[j];
w += n;
dst[0] = (float)sum;
}
}
else if( _src.type() == CV_64FC1 )
{
double *dst = _dst.ptr<double>();
for( i = 0; i < n; i++, dst += dststep )
{
const double* src = _src.ptr<double>();
double sum = 0;
for( j = 0; j < n; j++, src += srcstep )
sum += src[0]*w[j];
w += n;
dst[0] = sum;
}
}
else
assert(0);
}
示例3: test_plateRecognizeMain
string test_plateRecognizeMain()
{
const char* fileName = "resources/image/7.jpg";
Mat img = cv::imread(fileName);
if (img.empty())
{
cout << "plate is empty" << endl;
return "";
}
int size = img.elemSize()*img.total();
vector<uchar> buff;//buffer for coding
vector<int> param = vector<int>(2);
param[0] = CV_IMWRITE_JPEG_QUALITY;
param[1] = 95;//default(95) 0-100
imencode(".jpg", img, buff, param);
uchar *pImg = &(buff[0]);
char *ppImg = (char*)pImg;
//Mat src = imdecode(Mat(1, size, CV_8U, pp), IMREAD_COLOR);
caffepr::CaffeRecognise cr;
string res;
res = cr.process(ppImg,size );
cout << "检测的车牌号为:" <<endl<< res << endl;
return res;
}
示例4:
float FAST::CFastImage::FastSum( Mat& _img, int _pVec[], int _n ) {
size_t elemSize = _img.elemSize();
float sum = 0.0f;
FOR (i, _n)
sum += (float)(*(uchar*)(_img.data+_pVec[i]*elemSize));
return sum;
}
示例5: loadCVimageAsTexture
//http://stackoverflow.com/questions/16809833/opencv-image-loading-for-opengl-texture
void loadCVimageAsTexture(Mat img)
{
if(img.empty()){
cout << "Image is empty" << endl;
}
else{
//align the opencv image to opengl 4-byte alignment
glPixelStorei(GL_UNPACK_ALIGNMENT, (img.step & 3) ? 1:4);
//set length of one complete row
glPixelStorei(GL_UNPACK_ROW_LENGTH, img.step/img.elemSize());
//OpenCv and Opengl stores images differently, flip the image so it is correct
cv::flip(img, img, 0);
GLuint tex_2d;
glGenTextures(1, &tex_2d);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex_2d);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img.cols, img.rows, 0, GL_BGR, GL_UNSIGNED_BYTE, img.ptr());
}
}
示例6: repeat
void repeat(InputArray _src, int ny, int nx, OutputArray _dst)
{
CV_Assert( _src.dims() <= 2 );
CV_Assert( ny > 0 && nx > 0 );
Size ssize = _src.size();
_dst.create(ssize.height*ny, ssize.width*nx, _src.type());
CV_OCL_RUN(_dst.isUMat(),
ocl_repeat(_src, ny, nx, _dst))
Mat src = _src.getMat(), dst = _dst.getMat();
Size dsize = dst.size();
int esz = (int)src.elemSize();
int x, y;
ssize.width *= esz; dsize.width *= esz;
for( y = 0; y < ssize.height; y++ )
{
for( x = 0; x < dsize.width; x += ssize.width )
memcpy( dst.data + y*dst.step + x, src.data + y*src.step, ssize.width );
}
for( ; y < dsize.height; y++ )
memcpy( dst.data + y*dst.step, dst.data + (y - ssize.height)*dst.step, dsize.width );
}
示例7: findDecoder
static ImageDecoder findDecoder( const Mat& buf )
{
size_t i, maxlen = 0;
if( buf.rows*buf.cols < 1 || !buf.isContinuous() )
return ImageDecoder();
for( i = 0; i < codecs.decoders.size(); i++ )
{
size_t len = codecs.decoders[i]->signatureLength();
maxlen = std::max(maxlen, len);
}
string signature(maxlen, ' ');
size_t bufSize = buf.rows*buf.cols*buf.elemSize();
maxlen = std::min(maxlen, bufSize);
memcpy( &signature[0], buf.data, maxlen );
for( i = 0; i < codecs.decoders.size(); i++ )
{
if( codecs.decoders[i]->checkSignature(signature) )
return codecs.decoders[i]->newDecoder();
}
return ImageDecoder();
}
示例8: glFuncTab
cv::GlBuffer::Impl::Impl(const Mat& m, unsigned int target) : buffer_(0)
{
if (!glFuncTab()->isGlContextInitialized())
throw_nogl;
CV_DbgAssert(m.rows > 0 && m.cols > 0);
CV_DbgAssert(m.depth() >= 0 && m.depth() <= CV_64F);
CV_Assert(m.isContinuous());
glFuncTab()->genBuffers(1, &buffer_);
CV_CheckGlError();
CV_Assert(buffer_ != 0);
size_t size = m.rows * m.cols * m.elemSize();
glFuncTab()->bindBuffer(target, buffer_);
CV_CheckGlError();
glFuncTab()->bufferData(target, size, m.data, GL_DYNAMIC_DRAW);
CV_CheckGlError();
glFuncTab()->bindBuffer(target, 0);
#ifdef HAVE_CUDA
if (g_isCudaGlDeviceInitialized)
cudaGlInterop_.registerBuffer(buffer_);
#endif
}
示例9: readData
bool WebPDecoder::readData(Mat &img)
{
if( m_width > 0 && m_height > 0 )
{
if (img.cols != m_width || img.rows != m_height || img.type() != m_type)
{
img.create(m_height, m_width, m_type);
}
uchar* out_data = img.data;
size_t out_data_size = img.cols * img.rows * img.elemSize();
uchar *res_ptr = 0;
if (channels == 3)
{
res_ptr = WebPDecodeBGRInto(data.data, data.total(), out_data,
out_data_size, img.step);
}
else if (channels == 4)
{
res_ptr = WebPDecodeBGRAInto(data.data, data.total(), out_data,
out_data_size, img.step);
}
if(res_ptr == out_data)
{
return true;
}
}
return false;
}
示例10: switch
cv::ogl::Buffer::Buffer(InputArray arr, Target target, bool autoRelease) : rows_(0), cols_(0), type_(0)
{
#ifndef HAVE_OPENGL
(void) arr;
(void) target;
(void) autoRelease;
throw_no_ogl();
#else
const int kind = arr.kind();
switch (kind)
{
case _InputArray::OPENGL_BUFFER:
case _InputArray::GPU_MAT:
copyFrom(arr, target, autoRelease);
break;
default:
{
Mat mat = arr.getMat();
CV_Assert( mat.isContinuous() );
const GLsizeiptr asize = mat.rows * mat.cols * mat.elemSize();
impl_.reset(new Impl(asize, mat.data, target, autoRelease));
rows_ = mat.rows;
cols_ = mat.cols;
type_ = mat.type();
break;
}
}
#endif
}
示例11: create
void cv::ocl::oclMat::upload(const Mat &m)
{
if (!Context::getContext()->supportsFeature(FEATURE_CL_DOUBLE) && m.depth() == CV_64F)
{
CV_Error(Error::OpenCLDoubleNotSupported, "Selected device doesn't support double");
return;
}
CV_DbgAssert(!m.empty());
Size wholeSize;
Point ofs;
m.locateROI(wholeSize, ofs);
create(wholeSize, m.type());
if (m.channels() == 3)
{
int pitch = wholeSize.width * 3 * m.elemSize1();
int tail_padding = m.elemSize1() * 3072;
int err;
cl_mem temp = clCreateBuffer(*(cl_context*)clCxt->getOpenCLContextPtr(), CL_MEM_READ_WRITE,
(pitch * wholeSize.height + tail_padding - 1) / tail_padding * tail_padding, 0, &err);
openCLVerifyCall(err);
openCLMemcpy2D(clCxt, temp, pitch, m.datastart, m.step, wholeSize.width * m.elemSize(), wholeSize.height, clMemcpyHostToDevice, 3);
convert_C3C4(temp, *this);
openCLSafeCall(clReleaseMemObject(temp));
}
else
openCLMemcpy2D(clCxt, data, step, m.datastart, m.step, wholeSize.width * elemSize(), wholeSize.height, clMemcpyHostToDevice);
rows = m.rows;
cols = m.cols;
offset = ofs.y * step + ofs.x * elemSize();
}
示例12: mean
cv::Scalar cv::mean( InputArray _src, InputArray _mask )
{
Mat src = _src.getMat(), mask = _mask.getMat();
CV_Assert( mask.empty() || mask.type() == CV_8U );
int k, cn = src.channels(), depth = src.depth();
SumFunc func = sumTab[depth];
CV_Assert( cn <= 4 && func != 0 );
const Mat* arrays[] = {&src, &mask, 0};
uchar* ptrs[2];
NAryMatIterator it(arrays, ptrs);
Scalar s;
int total = (int)it.size, blockSize = total, intSumBlockSize = 0;
int j, count = 0;
AutoBuffer<int> _buf;
int* buf = (int*)&s[0];
bool blockSum = depth <= CV_16S;
size_t esz = 0, nz0 = 0;
if( blockSum )
{
intSumBlockSize = depth <= CV_8S ? (1 << 23) : (1 << 15);
blockSize = std::min(blockSize, intSumBlockSize);
_buf.allocate(cn);
buf = _buf;
for( k = 0; k < cn; k++ )
buf[k] = 0;
esz = src.elemSize();
}
for( size_t i = 0; i < it.nplanes; i++, ++it )
{
for( j = 0; j < total; j += blockSize )
{
int bsz = std::min(total - j, blockSize);
int nz = func( ptrs[0], ptrs[1], (uchar*)buf, bsz, cn );
count += nz;
nz0 += nz;
if( blockSum && (count + blockSize >= intSumBlockSize || (i+1 >= it.nplanes && j+bsz >= total)) )
{
for( k = 0; k < cn; k++ )
{
s[k] += buf[k];
buf[k] = 0;
}
count = 0;
}
ptrs[0] += bsz*esz;
if( ptrs[1] )
ptrs[1] += bsz;
}
}
return s*(nz0 ? 1./nz0 : 0);
}
示例13: wrapCVMat
void wrapCVMat(Mat& cvMat, image_t& img) {
img.height = cvMat.rows;
img.width = cvMat.cols;
img.depth = cvMat.channels();
img.pitch = cvMat.cols*cvMat.elemSize();
img.itemSize = cvMat.elemSize1();
img.data = cvMat.ptr();
}
示例14: streamServer
/**
* This is the streaming server, run as separate thread
*/
void* streamServer(void* arg)
{
struct sockaddr_in serverAddr, clientAddr;
socklen_t clientAddrLen = sizeof(clientAddr);
/* make this thread cancellable using pthread_cancel() */
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
if ((listenSock = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
quit("socket() failed.", 1);
}
serverAddr.sin_family = PF_INET;
serverAddr.sin_addr.s_addr = htonl(INADDR_ANY);
serverAddr.sin_port = htons(listenPort);
if (bind(listenSock, (sockaddr*)&serverAddr, sizeof(serverAddr)) == -1) {
quit("bind() failed", 1);
}
if (listen(listenSock, 5) == -1) {
quit("listen() failed.", 1);
}
int imgSize = img.total()*img.elemSize();
char sockData[imgSize];
int bytes=0;
/* start receiving images */
while(1)
{
cout << "-->Waiting for TCP connection on port " << listenPort << " ...nn";
/* accept a request from a client */
if ((connectSock = accept(listenSock, (sockaddr*)&clientAddr, &clientAddrLen)) == -1) {
quit("accept() failed", 1);
}else{
cout << "-->Receiving image from " << inet_ntoa(clientAddr.sin_addr) << ":" << ntohs(clientAddr.sin_port) << "..." << endl;
}
memset(sockData, 0x0, sizeof(sockData));
while(1){
for (int i = 0; i < imgSize; i += bytes) {
if ((bytes = recv(connectSock, sockData +i, imgSize - i, 0)) == -1) {
quit("recv failed", 1);
}
}
/* convert the received data to OpenCV's Mat format, thread safe */
pthread_mutex_lock(&mutex);
for (int i = 0; i < img.rows; i++) {
for (int j = 0; j < img.cols; j++) {
(img.row(i)).col(j) = (uchar)sockData[((img.cols)*i)+j];
}
}
is_data_ready = 1;
memset(sockData, 0x0, sizeof(sockData));
pthread_mutex_unlock(&mutex);
}
}
/* have we terminated yet? */
pthread_testcancel();
/* no, take a rest for a while */
usleep(1000);
}
示例15: initUDPFetcher
bool initUDPFetcher(bool debug)
{
/////////////////////////////////UDP Initialization///////////////////////////////////
DBG = debug;
struct sockaddr_in addr;
sockfd=socket(AF_INET,SOCK_DGRAM,0);
if(sockfd<0)
{
fprintf(stderr,"Socket Error:%s\n",strerror(errno));
return false;
}
bzero(&addr,sizeof(struct sockaddr_in));
addr.sin_family=AF_INET;
addr.sin_addr.s_addr=htonl(INADDR_ANY);
addr.sin_port=htons(SERVER_PORT);
if(bind(sockfd,(struct sockaddr *)&addr,sizeof(struct sockaddr_in))<0)
{
fprintf(stderr,"Bind Error:%s\n",strerror(errno));
return false;
}
/////////////////////////////////Image Initialization///////////////////////////////
imgSize = image_left.total()*image_left.elemSize(); //calculate image size
if(DBG)
cout<<"image size is "<< imgSize <<endl;
k_times = imgSize / MAX_PKG_SIZE;
if(DBG)
cout << k_times << endl;
//////////////////////////////////multithread stuff///////////////////////////////
enableUDPImageFetcher(true);
errorT = pthread_create(&tid_left, NULL, fetchImageLeft, NULL);
if(errorT){
printf("pthread Left is not created...\n");
return false;
}
errorT = pthread_create(&tid_right, NULL, fetchImageRight, NULL);
if(errorT){
printf("pthread Right is not created...\n");
return false;
}
return true;
}