本文整理汇总了C++中Mat1b类的典型用法代码示例。如果您正苦于以下问题:C++ Mat1b类的具体用法?C++ Mat1b怎么用?C++ Mat1b使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mat1b类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Mat1b
void Nieto::nietoLaneMarkingsDetector(Mat1b &srcGRAY, Mat1b &dstGRAY, int tauInicio, int tauFim) {
Mat1b tempDst = Mat1b(srcGRAY.size(), 0);
int aux = 0;
double alturaInicioVariacao = (double)srcGRAY.rows / 2;
double tauTaxaVariacao = double(tauFim - tauInicio) / alturaInicioVariacao;
int tau = tauInicio;
for (int j = 0; j < srcGRAY.rows; ++j) {
unsigned char *ptRowSrc = srcGRAY.ptr<uchar>(j);
unsigned char *ptRowDst = tempDst.ptr<uchar>(j);
if (j > alturaInicioVariacao) tau = int(tauInicio + tauTaxaVariacao * (j - alturaInicioVariacao));
for (int i = tau; i < srcGRAY.cols - tau; ++i) {
unsigned char aux2 = ptRowSrc[i];
if (ptRowSrc[i] != 0) {
aux = 2 * ptRowSrc[i];
aux += -ptRowSrc[i - tau];
aux += -ptRowSrc[i + tau];
aux += -abs((int)(ptRowSrc[i - tau] - ptRowSrc[i + tau]));
aux = (aux < 0) ? 0 : aux;
aux = (aux > 255) ? 255 : aux;
ptRowDst[i] = (unsigned char)aux;
}
}
}
dstGRAY = tempDst.clone();
}
示例2: test_wcv
void test_wcv( const char* path, const char *txt_path )
{
Mat1b img;
try {
img = imread( path, IMREAD_GRAYSCALE ); }
catch (...) {
return; }
if (img.empty())
return;
//resize?if (img.rows())
cout << path << endl;
#if 0
blur( img, img, Size(3,3) );
#endif
// imshow("kotsu", img);
int hist[256]={0};
#if 1
for (int y=0; y<img.rows; y++)
{
for (int x=0; x<img.cols; x++)
{
hist[ img[y][x] ]++;
}
}
#endif
KOtsu kotsu( hist, sizeof(hist)/sizeof(hist[0]), 255 );
ifstream cin(txt_path);
int n;
cin >> n;
vector<int> arr(n + 1);
for (int i = 0; i < n; ++i)
cin >> arr[i];
arr[n] = 256;
int beg = 0;
double ans = 0;
for (int i = 0; i < n + 1; ++i)
{
int last_jump = beg;
int pos = arr[i];
double _sigsq = kotsu._sigma_sq(last_jump, pos);
ans += (kotsu.sum[pos] - kotsu.sum[last_jump])* _sigsq;
beg = arr[i];
}
cout << "Kotsu wcv for input file with " << n << "cuts result = " << (n + 1) * (n + 1) * ans / (img.cols * img.rows) << endl;
}
示例3: fht_vertical
void fht_vertical(Mat1b &input, Mat1i &outputl, Mat1i &outputr)
{
// увеличение размера
int st = 1;
while (st < input.rows)
st *= 2;
Mat1b myInput(st, input.cols);
myInput = 0;
Mat roi(myInput, Rect(0,0,input.cols,input.rows));
input.copyTo(roi);
fht_vertical_iteration_l(myInput, outputl, 0, st);
fht_vertical_iteration_r(myInput, outputr, 0, st);
//imshow("output_fht_l", outputl * 10);
//imshow("output_fht_r", outputr * 10);
Mat1i revtestl, testl;
//imshow ("testl", testl * 10);
// cout << outputl.rows << " " << testr.rows << endl;
//imshow("0", (testl - outputl) * 100);
//imshow("output_test", out * 10);
//cvWaitKey(0);
// DrawLines(myInput, outputl, outputr, 4000);
}
示例4: test_fht_vertical_l
void test_fht_vertical_l(Mat1b &input, Mat1i &output)
{
int st = 1;
while (st < input.rows)
st *= 2;
Mat1b myInput(st, input.cols);
myInput = 0;
Mat roi(myInput, Rect(0,0,input.cols,input.rows));
input.copyTo(roi);
Mat1b rev = myInput - myInput;
Mat1i revtestl, testl;
for (int x = 0; x < myInput.cols; ++x)
{
for (int y = 0; y < myInput.rows; ++y)
{
rev(y, x) = myInput(y, myInput.cols - x - 1);
}
}
test_fht_vertical_r(rev, revtestl);
testl = revtestl - revtestl;
for (int x = 0; x < myInput.cols; ++x)
{
for (int y = 0; y < myInput.rows; ++y)
{
testl(y, x) = revtestl(y, myInput.cols - x - 1);
}
}
output = testl;
}
示例5: displayBoolean
void displayBoolean(Mat1b& mat) {
if (!img_widget) {
img_widget = new ImageWidget(0);
img_widget->show();
}
Mat1b dup = mat.clone();
dup *= 255;
img_widget->setImage(dup);
}
示例6: computeEigenVector
void computeEigenVector(const Mat1f& X, const Mat1b& mask, Mat1f& dst, int num_pca_iterations, const Mat1f& rand_vec)
{
CV_DbgAssert( X.cols == rand_vec.cols );
CV_DbgAssert( X.rows == mask.size().area() );
CV_DbgAssert( rand_vec.rows == 1 );
dst.create(rand_vec.size());
rand_vec.copyTo(dst);
Mat1f t(X.size());
float* dst_row = dst[0];
for (int i = 0; i < num_pca_iterations; ++i)
{
t.setTo(Scalar::all(0));
for (int y = 0, ind = 0; y < mask.rows; ++y)
{
const uchar* mask_row = mask[y];
for (int x = 0; x < mask.cols; ++x, ++ind)
{
if (mask_row[x])
{
const float* X_row = X[ind];
float* t_row = t[ind];
float dots = 0.0;
for (int c = 0; c < X.cols; ++c)
dots += dst_row[c] * X_row[c];
for (int c = 0; c < X.cols; ++c)
t_row[c] = dots * X_row[c];
}
}
}
dst.setTo(0.0);
for (int k = 0; k < X.rows; ++k)
{
const float* t_row = t[k];
for (int c = 0; c < X.cols; ++c)
{
dst_row[c] += t_row[c];
}
}
}
double n = norm(dst);
divide(dst, n, dst);
}
示例7: skeleton
Mat1b Helper::skeleton(const Mat1b &binaryImage, const int size) {
Mat1b img = binaryImage.clone();
Mat skel(img.size(), CV_8UC1, Scalar(0));
Mat temp;
Mat eroded;
Mat element = getStructuringElement(MORPH_CROSS, cv::Size(size, size));
bool done;
do {
erode(img, eroded, element);
dilate(eroded, temp, element); // temp = open(img)
subtract(img, temp, temp);
bitwise_or(skel, temp, skel);
eroded.copyTo(img);
done = (countNonZero(img) == 0);
} while (!done);
return skel;
}
示例8: imadjust
void imadjust(const Mat1b& src, Mat1b& dst, int tol = 1, Vec2i in = Vec2i(0, 255), Vec2i out = Vec2i(0, 255))
{
// src : input CV_8UC1 image
// dst : output CV_8UC1 imge
// tol : tolerance, from 0 to 100.
// in : src image bounds
// out : dst image buonds
dst = src.clone();
tol = max(0, min(100, tol));
if (tol > 0)
{
// Compute in and out limits
// Histogram
vector<int> hist(256, 0);
for (int r = 0; r < src.rows; ++r) {
for (int c = 0; c < src.cols; ++c) {
hist[src(r,c)]++;
}
}
// Cumulative histogram
vector<int> cum = hist;
for (int i = 1; i < hist.size(); ++i) {
cum[i] = cum[i - 1] + hist[i];
}
// Compute bounds
int total = src.rows * src.cols;
int low_bound = total * tol / 100;
int upp_bound = total * (100-tol) / 100;
in[0] = distance(cum.begin(), lower_bound(cum.begin(), cum.end(), low_bound));
in[1] = distance(cum.begin(), lower_bound(cum.begin(), cum.end(), upp_bound));
}
// Stretching
float scale = float(out[1] - out[0]) / float(in[1] - in[0]);
for (int r = 0; r < dst.rows; ++r)
{
for (int c = 0; c < dst.cols; ++c)
{
int vs = max(src(r, c) - in[0], 0);
int vd = min(int(vs * scale + 0.5f) + out[0], out[1]);
dst(r, c) = saturate_cast<uchar>(vd);
}
}
}
示例9: do_extract
/// @see FeatureExtractor::do_extract()
// TODO scale the contour parts / histogram parts maybe
virtual return_error_code::return_error_code do_extract( const Mat3r& original_image, const Mat1b& saliency_map, const Mat1b& saliency_mask, const vector<Contour>& contours, Vec1r& o_features) const {
using namespace cv;
assert( original_image.size() == saliency_map.size() && "original_image and saliency map must have same dimensions");
return_error_code::return_error_code ret_contour, ret_histogram;
o_features.clear();
Vec1r contour_features, histogram_features;
ret_contour = _contour_extractor->extract( original_image, saliency_map, saliency_mask, contours, contour_features);
ret_histogram = _histogram_extractor->extract( original_image, saliency_map, saliency_mask, contours, histogram_features);
o_features.reserve( contour_features.size() + histogram_features.size());
o_features.insert(o_features.end(), contour_features.begin(), contour_features.end());
o_features.insert(o_features.end(), histogram_features.begin(), histogram_features.end());
return ret_contour;
}
示例10: DrawLines
void DrawLines(Mat1b &input, Mat1i &outputL, Mat1i &outputR, int trash)//рисует все линии вес которых больше чем trash
// для тестирования
{
Mat1b draw_mat;
input.copyTo(draw_mat);
draw_mat = draw_mat * 10;
for (int x = 0; x < outputR.cols; ++x)
for (int s = 0; s < outputR.rows; ++s)
if (outputR(s, x) > trash)
line(draw_mat, Point(x, 0), Point(x + s, outputR.rows - 1), 255, 1);
for (int x = 0; x < outputL.cols; ++x)
for (int s = 0; s < outputL.rows; ++s)
if (outputL(s, x) > trash)
line(draw_mat, Point(x, 0), Point(x - s, outputL.rows - 1), 255, 1);
imshow ("lines_more_the_tresh", draw_mat);
//cout << draw_mat.cols << " " << draw_mat.rows << endl;
//cvWaitKey(0);
}
示例11: test_fht_vertical_r
void test_fht_vertical_r(Mat1b &input, Mat1i &output)
{
int st = 1;
while (st < input.rows)
st *= 2;
Mat1b myInput(st, input.cols);
myInput = 0;
Mat roi(myInput, Rect(0,0,input.cols,input.rows));
input.copyTo(roi);
output = Mat1i(st, myInput.cols);
for (int i = 0; i < myInput.cols; ++i)
{
for (int i1 = 0; i1 < st; ++i1)
{
output(i1, i) = test_fht_vertical_line(myInput, Point(i, 0), Point(i + i1 + 1, st));
}
}
}
示例12: max
void xyVision::GetTarget::imadjust(const Mat1b& src, Mat1b& dst, int tol, Vec2i in, Vec2i out)
{
dst = src.clone();
tol = max(0, min(100, tol));
if (tol > 0)
{
// Compute in and out limits
// Histogram
vector<int> hist(256, 0);
for (int r = 0; r < src.rows; ++r) {
for (int c = 0; c < src.cols; ++c) {
hist[src(r,c)]++;
}
}
// Cumulative histogram
vector<int> cum = hist;
for (int i = 1; i < (int)hist.size(); ++i) {
cum[i] = cum[i - 1] + hist[i];
}
// Compute bounds
int total = src.rows * src.cols;
int low_bound = total * tol / 100;
int upp_bound = total * (100-tol) / 100;
in[0] = distance(cum.begin(), lower_bound(cum.begin(), cum.end(), low_bound));
in[1] = distance(cum.begin(), lower_bound(cum.begin(), cum.end(), upp_bound));
}
// Stretching
float scale = float(out[1] - out[0]) / float(in[1] - in[0]);
for (int r = 0; r < dst.rows; ++r)
{
for (int c = 0; c < dst.cols; ++c)
{
int vs = max(src(r, c) - in[0], 0);
int vd = min(int(vs * scale + 0.5f) + out[0], out[1]);
dst(r, c) = saturate_cast<uchar>(vd);
}
}
}
示例13: computeEta
void AdaptiveManifoldFilterN::computeEta(Mat& teta, Mat1b& cluster, vector<Mat>& etaDst)
{
CV_DbgAssert(teta.size() == srcSize && cluster.size() == srcSize);
Mat1f tetaMasked = Mat1f::zeros(srcSize);
teta.copyTo(tetaMasked, cluster);
float sigma_s = (float)(sigma_s_ / getResizeRatio());
Mat1f tetaMaskedBlur;
downsample(tetaMasked, tetaMaskedBlur);
h_filter(tetaMaskedBlur, tetaMaskedBlur, sigma_s);
Mat mul;
etaDst.resize(jointCnNum);
for (int i = 0; i < jointCnNum; i++)
{
multiply(tetaMasked, jointCn[i], mul);
downsample(mul, etaDst[i]);
h_filter(etaDst[i], etaDst[i], sigma_s);
divide(etaDst[i], tetaMaskedBlur, etaDst[i]);
}
}
示例14: Mat1b
Mat1b Helper::fillPerspectiva(const Mat1b &imgROI, const Rect &roi, const Size &tamanho, const uchar _default) {
Mat1b perspectiva = Mat1b(tamanho, uchar(_default));
imgROI.copyTo(perspectiva(roi));
return perspectiva;
}
示例15: main
int main(int argc, char** argv)
{
if(argc != 2){
cout<<"Provide input image";
return 0;
}
// Read image
Mat3b img = imread(argv[1]);
// Binarize image. Text is white, background is black
Mat1b bin;
cvtColor(img, bin, COLOR_BGR2GRAY);
bin = bin < 200;
// Rotate the image according to the found angle
Mat1b rotated;
bin.copyTo(rotated);
// Mat M = getRotationMatrix2D(box.center, box.angle, 1.0); //warpAffine(bin, rotated, M, bin.size());
// Compute horizontal projections
Mat1f horProj;
reduce(rotated, horProj, 1, CV_REDUCE_AVG);
// Remove noise in histogram. White bins identify space lines, black bins identify text lines
float th = 0;
Mat1b hist = horProj <= th;
// Get mean coordinate of white pixels groups
vector<int> ycoords;
int y = 0;
int count = 0;
bool isSpace = false;
for (int i = 0; i < rotated.rows; ++i)
{
if (!isSpace)
{
if (hist(i))
{
isSpace = true;
count = 1;
y = i;
}
}
else
{
if (!hist(i))
{
isSpace = false;
ycoords.push_back(y / count);
}
else
{
y += i;
count++;
}
}
}
// Draw line as final result
Mat3b result;
cvtColor(rotated, result, COLOR_GRAY2BGR);
if(ycoords.size()>0){
for (int i = 0; i < ycoords.size()-1; i++)
{
Rect rect1;
rect1.x = 0;
rect1.y = ycoords[i];
rect1.width = result.size().width;
rect1.height = ycoords[i+1]-ycoords[i];
if(rect1.height > 30){
Mat Image1 = result(rect1);
imshow("Display Image", Image1);
string name = "";
std::stringstream ss;
ss << i;
name = "Image"+ss.str()+".jpg";
imwrite(name,Image1);
waitKey(0);
}
if(i == ycoords.size()-2){
Rect rect1;
rect1.x = 0;
rect1.y = ycoords[i+1];
rect1.width = result.size().width;
rect1.height = result.size().height-ycoords[i+1];
if(rect1.height > 30){
Mat Image1 = result(rect1);
imshow("Display Image", Image1);
string name = "";
std::stringstream ss;
ss << i+1;
name = "Image"+ss.str()+".jpg";
imwrite(name,Image1);
waitKey(0);
}
}
}
}
//.........这里部分代码省略.........