本文整理汇总了C++中cv::Mat::elemSize方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat::elemSize方法的具体用法?C++ Mat::elemSize怎么用?C++ Mat::elemSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv::Mat
的用法示例。
在下文中一共展示了Mat::elemSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: save
void save(Archive & ar, const ::cv::Mat& m, const unsigned int version)
{
size_t elem_size = m.elemSize();
size_t elem_type = m.type();
ar & m.cols;
ar & m.rows;
ar & elem_size;
ar & elem_type;
const size_t data_size = m.cols * m.rows * elem_size;
ar & boost::serialization::make_array(m.ptr(), data_size);
}
示例2: glTexToCVmat
void glTexToCVmat(cv::Mat& image, int width, int height) {
// http://stackoverflow.com/questions/9097756/converting-data-from-glreadpixels-to-opencvmat/
image.create(height, width, CV_8UC3);
// Use fast 4-byte alignment (default anyway) if possible
glPixelStorei(GL_PACK_ALIGNMENT, (image.step & 3) ? 1 : 4);
// Set length of one complete row in destination data (doesn't need to equal image.cols)
glPixelStorei(GL_PACK_ROW_LENGTH, image.step/image.elemSize());
// Read pixels into Mat. OpenCV stores colors as BGR rather than RGB
glReadPixels(0, 0, image.cols, image.rows, GL_BGR, GL_UNSIGNED_BYTE, image.data);
}
示例3: type
void cv::ocl::oclMat::download(cv::Mat &m) const
{
CV_DbgAssert(!this->empty());
// int t = type();
// if(download_channels == 3)
//{
// t = CV_MAKETYPE(depth(), 3);
//}
m.create(wholerows, wholecols, type());
if(m.channels() == 3)
{
int pitch = wholecols * 3 * m.elemSize1();
int tail_padding = m.elemSize1() * 3072;
int err;
cl_mem temp = clCreateBuffer((cl_context)clCxt->oclContext(), CL_MEM_READ_WRITE,
(pitch * wholerows + tail_padding - 1) / tail_padding * tail_padding, 0, &err);
openCLVerifyCall(err);
convert_C4C3(*this, temp);
openCLMemcpy2D(clCxt, m.data, m.step, temp, pitch, wholecols * m.elemSize(), wholerows, clMemcpyDeviceToHost, 3);
//int* cputemp=new int[wholecols*wholerows * 3];
//int* cpudata=new int[this->step*this->wholerows/sizeof(int)];
//openCLSafeCall(clEnqueueReadBuffer(clCxt->impl->clCmdQueue, temp, CL_TRUE,
// 0, wholecols*wholerows * 3* sizeof(int), cputemp, 0, NULL, NULL));
//openCLSafeCall(clEnqueueReadBuffer(clCxt->impl->clCmdQueue, (cl_mem)data, CL_TRUE,
// 0, this->step*this->wholerows, cpudata, 0, NULL, NULL));
//for(int i=0;i<wholerows;i++)
//{
// int *a = cputemp+i*wholecols * 3,*b = cpudata + i*this->step/sizeof(int);
// for(int j=0;j<wholecols;j++)
// {
// if((a[3*j] != b[4*j])||(a[3*j+1] != b[4*j+1])||(a[3*j+2] != b[4*j+2]))
// printf("rows=%d,cols=%d,cputtemp=%d,%d,%d;cpudata=%d,%d,%d\n",
// i,j,a[3*j],a[3*j+1],a[3*j+2],b[4*j],b[4*j+1],b[4*j+2]);
// }
//}
//delete []cputemp;
//delete []cpudata;
openCLSafeCall(clReleaseMemObject(temp));
}
else
{
openCLMemcpy2D(clCxt, m.data, m.step, data, step, wholecols * elemSize(), wholerows, clMemcpyDeviceToHost);
}
Size wholesize;
Point ofs;
locateROI(wholesize, ofs);
m.adjustROI(-ofs.y, ofs.y + rows - wholerows, -ofs.x, ofs.x + cols - wholecols);
}
示例4: ReadMatBin
void ReadMatBin(std::ifstream& stream, cv::Mat &output_mat)
{
// Read in the number of rows, columns and the data type
int row, col, type;
stream.read((char*)&row, 4);
stream.read((char*)&col, 4);
stream.read((char*)&type, 4);
output_mat = cv::Mat(row, col, type);
int size = output_mat.rows * output_mat.cols * output_mat.elemSize();
stream.read((char *)output_mat.data, size);
}
示例5: detectandshow
bool detectandshow( Alpr* alpr, cv::Mat frame, std::string region, bool writeJson)
{
timespec startTime;
getTimeMonotonic(&startTime);
std::vector<AlprRegionOfInterest> regionsOfInterest;
regionsOfInterest.push_back(AlprRegionOfInterest(0,0, frame.cols, frame.rows));
AlprResults results = alpr->recognize(frame.data, frame.elemSize(), frame.cols, frame.rows, regionsOfInterest );
timespec endTime;
getTimeMonotonic(&endTime);
double totalProcessingTime = diffclock(startTime, endTime);
if (measureProcessingTime)
std::cout << "Total Time to process image: " << totalProcessingTime << "ms." << std::endl;
if (writeJson)
{
std::cout << alpr->toJson( results ) << std::endl;
}
else
{
for (int i = 0; i < results.plates.size(); i++)
{
std::cout << "plate" << i << ": " << results.plates[i].topNPlates.size() << " results";
if (measureProcessingTime)
std::cout << " -- Processing Time = " << results.plates[i].processing_time_ms << "ms.";
std::cout << std::endl;
if (results.plates[i].regionConfidence > 0)
std::cout << "State ID: " << results.plates[i].region << " (" << results.plates[i].regionConfidence << "% confidence)" << std::endl;
for (int k = 0; k < results.plates[i].topNPlates.size(); k++)
{
std::cout << " - " << results.plates[i].topNPlates[k].characters << "\t confidence: " << results.plates[i].topNPlates[k].overall_confidence;
if (templatePattern.size() > 0)
std::cout << "\t pattern_match: " << results.plates[i].topNPlates[k].matches_template;
std::cout << std::endl;
}
}
}
return results.plates.size() > 0;
}
示例6: readMatBinary
//! Read cv::Mat from binary
void readMatBinary(std::ifstream& ifs, cv::Mat& in_mat)
{
if(!ifs.is_open()){
throw new orArgException("Not opened");
}
int rows, cols, type;
ifs.read((char*)(&rows), sizeof(int));
ifs.read((char*)(&cols), sizeof(int));
ifs.read((char*)(&type), sizeof(int));
in_mat.release();
in_mat.create(rows, cols, type);
ifs.read((char*)(in_mat.data), in_mat.elemSize() * in_mat.total());
}
示例7: matToTexture
// Function turn a cv::Mat into a texture
void matToTexture(GLuint textureID, cv::Mat& mat)
{
// Bind to our texture handle
glBindTexture(GL_TEXTURE_2D, textureID);
// Set texture interpolation methods for minification and magnification
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S , GL_REPEAT );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
//use fast 4-byte alignment (default anyway) if possible
glPixelStorei(GL_PACK_ALIGNMENT, (mat.step & 3) ? 1 : 4);
//set length of one complete row in destination data (doesn't need to equal img.cols)
glPixelStorei(GL_PACK_ROW_LENGTH, mat.step/mat.elemSize());
// Set incoming texture format
GLenum inputColourFormat = GL_BGR;
GLenum inputType = GL_UNSIGNED_BYTE;
GLenum internalFormat = GL_RGBA;
if (mat.channels() == 1)
{
if (mat.depth() == CV_8U)
{
inputColourFormat = GL_RED_INTEGER;
inputType = GL_UNSIGNED_BYTE;
internalFormat = GL_RGBA8UI;
}
else
{
inputColourFormat = GL_RED_INTEGER;
inputType = GL_UNSIGNED_SHORT;
internalFormat = GL_RGBA16UI;
}
}
// Create the texture
glTexImage2D(GL_TEXTURE_2D, // Type of texture
0, // Pyramid level (for mip-mapping) - 0 is the top level
internalFormat, // Internal colour format to convert to
mat.cols, // Image width i.e. 640 for Kinect in standard mode
mat.rows, // Image height i.e. 480 for Kinect in standard mode
0, // Border width in pixels (can either be 1 or 0)
inputColourFormat, // Input image format (i.e. GL_RGB, GL_RGBA, GL_BGR etc.)
inputType, // Image data type
mat.data); // The actual image data itself
glBindTexture(GL_TEXTURE_2D, 0);
}
示例8: readMatBin
void hulo::readMatBin(std::string filename, cv::Mat& mat) {
std::ifstream ifs(filename, std::ios::binary);
CV_Assert(ifs.is_open());
int rows, cols, type;
ifs.read((char*) (&rows), sizeof(int));
if (rows == 0) {
return;
}
ifs.read((char*) (&cols), sizeof(int));
ifs.read((char*) (&type), sizeof(int));
mat.release();
mat.create(rows, cols, type);
ifs.read((char*) (mat.data), mat.elemSize() * mat.total());
}
示例9: saveMatBin
void hulo::saveMatBin(std::string filename, cv::Mat& mat) {
std::ofstream ofs(filename, std::ios::binary);
CV_Assert(ofs.is_open());
if (mat.empty()) {
int s = 0;
ofs.write((const char*) (&s), sizeof(int));
return;
}
int type = mat.type();
ofs.write((const char*) (&mat.rows), sizeof(int));
ofs.write((const char*) (&mat.cols), sizeof(int));
ofs.write((const char*) (&type), sizeof(int));
ofs.write((const char*) (mat.data), mat.elemSize() * mat.total());
}
示例10: applyIntensityCorrection
void DiffImage::applyIntensityCorrection(cv::Mat &image)
{
if (image.total() != intensityCorrectionImage_.total()) return;
#pragma omp parallel for private(x, y, c)
for (int x = 0; x < image.cols; ++x) {
for (int y = 0; y < image.rows; ++y) {
for (int c = 0; c < image.channels(); ++c) {
const int index = y * image.step + x * image.elemSize() + c;
auto val = image.data[index] * (1.0 * intensityCorrectionImage_.data[index] / 100);
if (val > 255) val = 255;
image.data[index] = static_cast<int>(pow(val / 255.0, gamma_) * 255);
}
}
}
}
示例11: setUserDataRaw
void SensorData::setUserDataRaw(const cv::Mat & userDataRaw)
{
if(!userDataRaw.empty() && (!_userDataCompressed.empty() || !_userDataRaw.empty()))
{
UWARN("Cannot write new user data (%d bytes) over existing user "
"data (%d bytes, %d compressed). Set user data of %d to null "
"before setting a new one.",
int(userDataRaw.total()*userDataRaw.elemSize()),
int(_userDataRaw.total()*_userDataRaw.elemSize()),
_userDataCompressed.cols,
this->id());
return;
}
_userDataRaw = userDataRaw;
_userDataCompressed = cv::Mat();
}
示例12: if
ptrobot2D_test_world_impl(const std::string& aFileName, double aRobotRadius = 1.0) {
#ifdef REAK_HAS_OPENCV
world_map_image = cv::imread(aFileName);
if(world_map_image.empty())
throw std::ios_base::failure("Could not open the world map image '" + aFileName + "'! File is missing, empty or invalid!");
world_map_output = world_map_image.clone();
grid_width = world_map_image.size().width;
grid_height = world_map_image.size().height;
bpp = world_map_image.elemSize();
for(int y = 0; y < grid_height; ++y) {
uchar* color_bits = world_map_image.ptr(y);
for(int x = 0; x < grid_width; ++x) {
if( (color_bits[2] == 0) &&
(color_bits[0] == 255) &&
(color_bits[1] == 0) ) {
//this is the start position.
start_pos[0] = x;
start_pos[1] = y;
} else if( (color_bits[2] == 0) &&
(color_bits[0] == 0) &&
(color_bits[1] == 255) ) {
//this is the goal position.
goal_pos[0] = x;
goal_pos[1] = y;
};
color_bits += bpp;
};
};
// int iRobotRadius = int(std::fabs(aRobotRadius));
// if(iRobotRadius > 0) {
// cv::GaussianBlur(world_map_output,world_map_image,
// cv::Size(iRobotRadius * 2 + 1, iRobotRadius * 2 + 1),
// aRobotRadius
// );
// };
#else
grid_width = 500;
grid_height = 500;
start_pos = ptrobot2D_test_world::point_type(1.0,1.0);
goal_pos = ptrobot2D_test_world::point_type(498.0,498.0);
#endif
};
示例13: convertKeypoints
void CFast::convertKeypoints(const cv::Mat& cvmKeyPoints_, std::vector<cv::KeyPoint>* pvKeyPoints_)
{
if (cvmKeyPoints_.empty()) return;
CV_Assert(cvmKeyPoints_.rows == ROWS_COUNT && cvmKeyPoints_.elemSize() == 4);
int nPoints = cvmKeyPoints_.cols;
pvKeyPoints_->resize(nPoints);
const short2* ps2LocationRow = cvmKeyPoints_.ptr<short2>(LOCATION_ROW);
const float* pfResponseRow = cvmKeyPoints_.ptr<float>(RESPONSE_ROW);
for (int i = 0; i < nPoints; ++i){
cv::KeyPoint kp(ps2LocationRow[i].x, ps2LocationRow[i].y, static_cast<float>(FEATURE_SIZE), -1, pfResponseRow[i]);
(*pvKeyPoints_)[i] = kp;
}
return;
}
示例14: writeMatBinary
/*!
\param[out] ofs output file stream
\param[in] out_mat mat to save
*/
bool writeMatBinary(std::ofstream& ofs, const cv::Mat& out_mat)
{
if(!ofs.is_open()){
return false;
}
if(out_mat.empty()){
int s = 0;
ofs.write((const char*)(&s), sizeof(int));
return true;
}
int type = out_mat.type();
ofs.write((const char*)(&out_mat.rows), sizeof(int));
ofs.write((const char*)(&out_mat.cols), sizeof(int));
ofs.write((const char*)(&type), sizeof(int));
ofs.write((const char*)(out_mat.data), out_mat.elemSize() * out_mat.total());
return true;
}
示例15: Send
// image는 흑백 영상이어야 한다.
// 크기는 640/480 이어야 한다.
int cStreamingSender::Send(const cv::Mat &image)
{
if (READY == m_state)
{
// 이미지를 변조한다.
uchar *data = image.data;
int buffSize = image.total() * image.elemSize();
// Gray Scale
if (m_isConvertGray)
{
cvtColor(image, m_gray, CV_RGB2GRAY);
data = m_gray.data;
buffSize = m_gray.total() * m_gray.elemSize();
}
// 압축
if (m_isCompressed)
{
vector<int> p(3);
p[0] = CV_IMWRITE_JPEG_QUALITY;
p[1] = m_jpgCompressQuality;
p[2] = 0;
cv::imencode(".jpg", m_isConvertGray ? m_gray : image, m_compBuffer, p);
data = (uchar*)&m_compBuffer[0];
buffSize = m_compBuffer.size();
}
return SendImage(data, buffSize, m_isConvertGray, m_isCompressed);
}
else if (SPLIT == m_state)
{
if (SendSplit())
{
m_state = READY;
++m_chunkId;
if (m_chunkId > 100)
m_chunkId = 0;
}
}
return 0;
}