本文整理汇总了C++中ImageBuf::error方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageBuf::error方法的具体用法?C++ ImageBuf::error怎么用?C++ ImageBuf::error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageBuf
的用法示例。
在下文中一共展示了ImageBuf::error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: add
ImageBuf
ImageBufAlgo::add(Image_or_Const A, Image_or_Const B, ROI roi, int nthreads)
{
ImageBuf result;
bool ok = add(result, A, B, roi, nthreads);
if (!ok && !result.has_error())
result.error("ImageBufAlgo::add() error");
return result;
}
示例2: switch
bool
ImageBufAlgo::reorient (ImageBuf &dst, const ImageBuf &src, int nthreads)
{
ImageBuf tmp;
bool ok = false;
switch (src.orientation()) {
case 1:
ok = dst.copy (src);
break;
case 2:
ok = ImageBufAlgo::flop (dst, src);
break;
case 3:
ok = ImageBufAlgo::rotate180 (dst, src);
break;
case 4:
ok = ImageBufAlgo::flip (dst, src);
break;
case 5:
ok = ImageBufAlgo::rotate270 (tmp, src);
if (ok)
ok = ImageBufAlgo::flop (dst, tmp);
else
dst.error ("%s", tmp.geterror());
break;
case 6:
ok = ImageBufAlgo::rotate90 (dst, src);
break;
case 7:
ok = ImageBufAlgo::flip (tmp, src);
if (ok)
ok = ImageBufAlgo::rotate90 (dst, tmp);
else
dst.error ("%s", tmp.geterror());
break;
case 8:
ok = ImageBufAlgo::rotate270 (dst, src);
break;
}
dst.set_orientation (1);
return ok;
}
示例3:
bool
ImageBufAlgo::resample (ImageBuf &dst, const ImageBuf &src,
bool interpolate, ROI roi, int nthreads)
{
if (! IBAprep (roi, &dst, &src))
return false;
if (dst.nchannels() != src.nchannels()) {
dst.error ("channel number mismatch: %d vs. %d",
dst.spec().nchannels, src.spec().nchannels);
return false;
}
if (dst.spec().depth > 1 || src.spec().depth > 1) {
dst.error ("ImageBufAlgo::resample does not support volume images");
return false;
}
OIIO_DISPATCH_TYPES2 ("resample", resample_,
dst.spec().format, src.spec().format,
dst, src, interpolate, roi, nthreads);
return false;
}
示例4: logtime
bool
ImageBufAlgo::add(ImageBuf& dst, Image_or_Const A_, Image_or_Const B_, ROI roi,
int nthreads)
{
pvt::LoggedTimer logtime("IBA::add");
if (A_.is_img() && B_.is_img()) {
const ImageBuf &A(A_.img()), &B(B_.img());
if (!IBAprep(roi, &dst, &A, &B))
return false;
ROI origroi = roi;
roi.chend = std::min(roi.chend, std::min(A.nchannels(), B.nchannels()));
bool ok;
OIIO_DISPATCH_COMMON_TYPES3(ok, "add", add_impl, dst.spec().format,
A.spec().format, B.spec().format, dst, A, B,
roi, nthreads);
if (roi.chend < origroi.chend && A.nchannels() != B.nchannels()) {
// Edge case: A and B differed in nchannels, we allocated dst to be
// the bigger of them, but adjusted roi to be the lesser. Now handle
// the channels that got left out because they were not common to
// all the inputs.
ASSERT(roi.chend <= dst.nchannels());
roi.chbegin = roi.chend;
roi.chend = origroi.chend;
if (A.nchannels() > B.nchannels()) { // A exists
copy(dst, A, dst.spec().format, roi, nthreads);
} else { // B exists
copy(dst, B, dst.spec().format, roi, nthreads);
}
}
return ok;
}
if (A_.is_val() && B_.is_img()) // canonicalize to A_img, B_val
A_.swap(B_);
if (A_.is_img() && B_.is_val()) {
const ImageBuf& A(A_.img());
cspan<float> b = B_.val();
if (!IBAprep(roi, &dst, &A,
IBAprep_CLAMP_MUTUAL_NCHANNELS | IBAprep_SUPPORT_DEEP))
return false;
IBA_FIX_PERCHAN_LEN_DEF(b, A.nchannels());
if (dst.deep()) {
// While still serial, set up all the sample counts
dst.deepdata()->set_all_samples(A.deepdata()->all_samples());
return add_impl_deep(dst, A, b, roi, nthreads);
}
bool ok;
OIIO_DISPATCH_COMMON_TYPES2(ok, "add", add_impl, dst.spec().format,
A.spec().format, dst, A, b, roi, nthreads);
return ok;
}
// Remaining cases: error
dst.error("ImageBufAlgo::add(): at least one argument must be an image");
return false;
}
示例5:
bool
ImageBufAlgo::histogram (const ImageBuf &A, int channel,
std::vector<imagesize_t> &histogram, int bins,
float min, float max, imagesize_t *submin,
imagesize_t *supermax, ROI roi)
{
if (A.spec().format != TypeDesc::TypeFloat) {
A.error ("Unsupported pixel data format '%s'", A.spec().format);
return false;
}
if (A.nchannels() == 0) {
A.error ("Input image must have at least 1 channel");
return false;
}
if (channel < 0 || channel >= A.nchannels()) {
A.error ("Invalid channel %d for input image with channels 0 to %d",
channel, A.nchannels()-1);
return false;
}
if (bins < 1) {
A.error ("The number of bins must be at least 1");
return false;
}
if (max <= min) {
A.error ("Invalid range, min must be strictly smaller than max");
return false;
}
// Specified ROI -> use it. Unspecified ROI -> initialize from A.
if (! roi.defined())
roi = get_roi (A.spec());
histogram_impl<float> (A, channel, histogram, bins, min, max,
submin, supermax, roi);
return ! A.has_error();
}
示例6: lock
bool
ImageBufAlgo::capture_image (ImageBuf &dst, int cameranum, TypeDesc convert)
{
#ifdef USE_OPENCV
IplImage *frame = NULL;
{
// This block is mutex-protected
lock_guard lock (opencv_mutex);
CvCapture *cvcam = cameras[cameranum];
if (! cvcam) {
dst.error ("Could not create a capture camera (OpenCV error)");
return false; // failed somehow
}
frame = cvQueryFrame (cvcam);
if (! frame) {
dst.error ("Could not cvQueryFrame (OpenCV error)");
return false; // failed somehow
}
}
time_t now;
time (&now);
struct tm tmtime;
Sysutil::get_local_time (&now, &tmtime);
std::string datetime = Strutil::format ("%4d:%02d:%02d %02d:%02d:%02d",
tmtime.tm_year+1900, tmtime.tm_mon+1,
tmtime.tm_mday, tmtime.tm_hour,
tmtime.tm_min, tmtime.tm_sec);
bool ok = ImageBufAlgo::from_IplImage (dst, frame, convert);
// cvReleaseImage (&frame); // unnecessary?
if (ok)
dst.specmod().attribute ("DateTime", datetime);
return ok;
#else
dst.error ("capture_image not supported -- no OpenCV support at compile time");
return false;
#endif
}
示例7: filterptr
bool
ImageBufAlgo::resize (ImageBuf &dst, const ImageBuf &src,
Filter2D *filter, ROI roi, int nthreads)
{
if (! IBAprep (roi, &dst, &src))
return false;
if (dst.nchannels() != src.nchannels()) {
dst.error ("channel number mismatch: %d vs. %d",
dst.spec().nchannels, src.spec().nchannels);
return false;
}
if (dst.spec().depth > 1 || src.spec().depth > 1) {
dst.error ("ImageBufAlgo::resize does not support volume images");
return false;
}
// Set up a shared pointer with custom deleter to make sure any
// filter we allocate here is properly destroyed.
boost::shared_ptr<Filter2D> filterptr ((Filter2D*)NULL, Filter2D::destroy);
bool allocfilter = (filter == NULL);
if (allocfilter) {
// If no filter was provided, punt and just linearly interpolate.
const ImageSpec &srcspec (src.spec());
const ImageSpec &dstspec (dst.spec());
float wratio = float(dstspec.full_width) / float(srcspec.full_width);
float hratio = float(dstspec.full_height) / float(srcspec.full_height);
float w = 2.0f * std::max (1.0f, wratio);
float h = 2.0f * std::max (1.0f, hratio);
filter = Filter2D::create ("triangle", w, h);
filterptr.reset (filter);
}
OIIO_DISPATCH_TYPES2 ("resize", resize_,
dst.spec().format, src.spec().format,
dst, src, filter, roi, nthreads);
return false;
}
示例8:
bool
ImageBufAlgo::flatten (ImageBuf &dst, const ImageBuf &src,
ROI roi, int nthreads)
{
if (! src.deep()) {
// For some reason, we were asked to flatten an already-flat image.
// So just copy it.
return dst.copy (src);
}
// Construct an ideal spec for dst, which is like src but not deep.
ImageSpec force_spec = src.spec();
force_spec.deep = false;
force_spec.channelformats.clear();
if (! IBAprep (roi, &dst, &src, NULL, &force_spec, IBAprep_SUPPORT_DEEP))
return false;
if (dst.spec().deep) {
dst.error ("Cannot flatten to a deep image");
return false;
}
const ImageSpec &srcspec (src.spec());
int alpha_channel, RA_channel, GA_channel, BA_channel;
int R_channel, G_channel, B_channel, Z_channel, Zback_channel;
if (! find_deep_channels (srcspec, alpha_channel,
RA_channel, GA_channel, BA_channel,
R_channel, G_channel, B_channel,
Z_channel, Zback_channel)) {
dst.error ("No alpha channel could be identified");
return false;
}
bool ok;
OIIO_DISPATCH_TYPES (ok, "flatten", flatten_, dst.spec().format,
dst, src, roi, nthreads);
return ok;
}
示例9:
bool
ImageBufAlgo::mad (ImageBuf &dst, const ImageBuf &A, const float *B,
const float *C, ROI roi, int nthreads)
{
if (!A.initialized()) {
dst.error ("Uninitialized input image");
return false;
}
if (! IBAprep (roi, &dst, &A))
return false;
bool ok;
OIIO_DISPATCH_COMMON_TYPES2 (ok, "mad", mad_implf, dst.spec().format,
A.spec().format, dst, A, B, C,
roi, nthreads);
return ok;
}
示例10: fixNonFinite
// DEPRECATED 2-argument version
bool
ImageBufAlgo::fixNonFinite (ImageBuf &dst, const ImageBuf &src,
NonFiniteFixMode mode, int *pixelsFixed)
{
ROI roi;
IBAprep (roi, &dst, &src);
if (dst.nchannels() != src.nchannels()) {
dst.error ("channel number mismatch: %d vs. %d",
dst.spec().nchannels, src.spec().nchannels);
return false;
}
if ((const ImageBuf *)&dst != &src)
if (! dst.copy (src))
return false;
return fixNonFinite (dst, mode, pixelsFixed, roi);
}
示例11: logtime
bool
ImageBufAlgo::div(ImageBuf& dst, Image_or_Const A_, Image_or_Const B_, ROI roi,
int nthreads)
{
pvt::LoggedTimer logtime("IBA::div");
if (A_.is_img() && B_.is_img()) {
const ImageBuf &A(A_.img()), &B(B_.img());
if (!IBAprep(roi, &dst, &A, &B, IBAprep_CLAMP_MUTUAL_NCHANNELS))
return false;
bool ok;
OIIO_DISPATCH_COMMON_TYPES3(ok, "div", div_impl, dst.spec().format,
A.spec().format, B.spec().format, dst, A, B,
roi, nthreads);
return ok;
}
if (A_.is_val() && B_.is_img()) // canonicalize to A_img, B_val
A_.swap(B_);
if (A_.is_img() && B_.is_val()) {
const ImageBuf& A(A_.img());
cspan<float> b = B_.val();
if (!IBAprep(roi, &dst, &A,
IBAprep_CLAMP_MUTUAL_NCHANNELS | IBAprep_SUPPORT_DEEP))
return false;
IBA_FIX_PERCHAN_LEN_DEF(b, dst.nchannels());
int nc = dst.nchannels();
float* binv = OIIO_ALLOCA(float, nc);
for (int c = 0; c < nc; ++c)
binv[c] = (b[c] == 0.0f) ? 0.0f : 1.0f / b[c];
b = cspan<float>(binv, nc); // re-wrap
if (dst.deep()) {
// While still serial, set up all the sample counts
dst.deepdata()->set_all_samples(A.deepdata()->all_samples());
return mul_impl_deep(dst, A, b, roi, nthreads);
}
bool ok;
OIIO_DISPATCH_COMMON_TYPES2(ok, "div", mul_impl, dst.spec().format,
A.spec().format, dst, A, b, roi, nthreads);
return ok;
}
// Remaining cases: error
dst.error("ImageBufAlgo::div(): at least one argument must be an image");
return false;
}
示例12: B
bool
ImageBufAlgo::mad (ImageBuf &dst, const ImageBuf &A, float b,
float c, ROI roi, int nthreads)
{
if (!A.initialized()) {
dst.error ("Uninitialized input image");
return false;
}
if (! IBAprep (roi, &dst, &A))
return false;
std::vector<float> B (roi.chend, b);
std::vector<float> C (roi.chend, c);
bool ok;
OIIO_DISPATCH_COMMON_TYPES2 (ok, "mad", mad_implf, dst.spec().format,
A.spec().format, dst, A, &B[0], &C[0],
roi, nthreads);
return ok;
}
示例13: if
static bool
histogram_impl (const ImageBuf &A, int channel,
std::vector<imagesize_t> &histogram, int bins,
float min, float max, imagesize_t *submin,
imagesize_t *supermax, ROI roi)
{
// Double check A's type.
if (A.spec().format != BaseTypeFromC<Atype>::value) {
A.error ("Unsupported pixel data format '%s'", A.spec().format);
return false;
}
// Initialize.
ImageBuf::ConstIterator<Atype, float> a (A, roi);
float ratio = bins / (max-min);
int bins_minus_1 = bins-1;
bool submin_ok = submin != NULL;
bool supermax_ok = supermax != NULL;
if (submin_ok)
*submin = 0;
if (supermax_ok)
*supermax = 0;
histogram.assign(bins, 0);
// Compute histogram.
for ( ; ! a.done(); a++) {
float c = a[channel];
if (c >= min && c < max) {
// Map range min->max to 0->(bins-1).
histogram[ (int) ((c-min) * ratio) ]++;
} else if (c == max) {
histogram[bins_minus_1]++;
} else {
if (submin_ok && c < min)
(*submin)++;
else if (supermax_ok)
(*supermax)++;
}
}
return true;
}
示例14: ImageSpec
bool
ImageBufAlgo::histogram_draw (ImageBuf &R,
const std::vector<imagesize_t> &histogram)
{
// Fail if there are no bins to draw.
int bins = histogram.size();
if (bins == 0) {
R.error ("There are no bins to draw, the histogram is empty");
return false;
}
// Check R and modify it if needed.
int height = R.spec().height;
if (R.spec().format != TypeDesc::TypeFloat || R.nchannels() != 1 ||
R.spec().width != bins) {
ImageSpec newspec = ImageSpec (bins, height, 1, TypeDesc::FLOAT);
R.reset ("dummy", newspec);
}
// Fill output image R with white color.
ImageBuf::Iterator<float, float> r (R);
for ( ; ! r.done(); ++r)
r[0] = 1;
// Draw histogram left->right, bottom->up.
imagesize_t max = *std::max_element (histogram.begin(), histogram.end());
for (int b = 0; b < bins; b++) {
int bin_height = (int) ((float)histogram[b]/(float)max*height + 0.5f);
if (bin_height != 0) {
// Draw one bin at column b.
for (int j = 1; j <= bin_height; j++) {
int row = height - j;
r.pos (b, row);
r[0] = 0;
}
}
}
return true;
}
示例15: if
bool
ImageBufAlgo::noise (ImageBuf &dst, string_view noisetype,
float A, float B, bool mono, int seed,
ROI roi, int nthreads)
{
if (! IBAprep (roi, &dst))
return false;
bool ok;
if (noisetype == "gaussian" || noisetype == "normal") {
OIIO_DISPATCH_TYPES (ok, "noise_gaussian", noise_gaussian_, dst.spec().format,
dst, A, B, mono, seed, roi, nthreads);
} else if (noisetype == "uniform") {
OIIO_DISPATCH_TYPES (ok, "noise_uniform", noise_uniform_, dst.spec().format,
dst, A, B, mono, seed, roi, nthreads);
} else if (noisetype == "salt") {
OIIO_DISPATCH_TYPES (ok, "noise_salt", noise_salt_, dst.spec().format,
dst, A, B, mono, seed, roi, nthreads);
} else {
ok = false;
dst.error ("noise", "unknown noise type \"%s\"", noisetype);
}
return ok;
}