本文整理汇总了C++中ImageRef类的典型用法代码示例。如果您正苦于以下问题:C++ ImageRef类的具体用法?C++ ImageRef怎么用?C++ ImageRef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ImageRef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: leftRect
ImageRef Scene::parallelRaytrace(CameraRef camera, RenderOption option)
{
Rect leftRect(0.0f, 0.0f, camera->width(), floor(camera->height() / 2.0f));
Rect rightRect(0.0f, leftRect.maxY(), camera->width(), camera->height() - leftRect.size.height);
p1.scene = this;
p1.camera = camera;
p1.rect = leftRect;
p1.option = option;
p1.image = new Image(leftRect.size.width, leftRect.size.height);
p2.scene = this;
p2.camera = camera;
p2.rect = rightRect;
p2.option = option;
p2.image = new Image(rightRect.size.width, rightRect.size.height);
pthread_t thread1, thread2;
int iret1, iret2;
std::cout << this;
iret1 = pthread_create(&thread1, NULL, raytraceThread, &p1);
iret2 = pthread_create(&thread2, NULL, raytraceThread, &p2);
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
ImageRef image = new Image(camera->width(), camera->height());
image->drawImageAtPoint(p1.image, p1.rect.origin);
image->drawImageAtPoint(p2.image, p2.rect.origin);
delete p1.image;
delete p2.image;
return image;
}
示例2: getSSD
float getSSD( BasicImage<float> &templatePatch, BasicImage<float> &targetPatch, float matchThreshold )
{
#ifdef USE_ACCELERATE
float score = 0;
int N = templatePatch.size().x * templatePatch.size().y;
vDSP_vsub( templatePatch.data(), 1, targetPatch.data(), 1, targetPatch.data(), 1, N );
vDSP_svesq( targetPatch.data(), 1, &score, N );
return score;
#else
float score = 0;
ImageRef loc = ImageRef( 0, 0 );
do {
float templateVal = templatePatch[loc];
float targetVal = targetPatch[loc];
float diff = templateVal - targetVal;
score += diff * diff;
if ( score > matchThreshold ) break;
} while ( loc.next( templatePatch.size() ) );
return score;
#endif
}
示例3: WithSprite
ReplaceImage::ReplaceImage(Sprite* sprite, const ImageRef& oldImage, const ImageRef& newImage)
: WithSprite(sprite)
, m_oldImageId(oldImage->id())
, m_newImageId(newImage->id())
, m_newImage(newImage)
{
}
示例4: sprite
void ReplaceImage::onRedo()
{
ImageRef oldImage = sprite()->getImageRef(m_oldImageId);
ASSERT(oldImage);
ASSERT(!sprite()->getImageRef(m_newImageId));
m_copy->setId(m_newImageId);
replaceImage(m_oldImageId, m_copy);
m_copy.reset(Image::createCopy(oldImage.get()));
}
示例5: imToBlur
void CalibCornerPatch::MakeTemplateWithCurrentParams() {
double dBlurSigma = 2.0;
int nExtraPixels = (int)(dBlurSigma * 6.0) + 2;
Image<float> imToBlur(mimTemplate.size() +
ImageRef(nExtraPixels, nExtraPixels));
Image<float> imTwiceToBlur(imToBlur.size() * 2);
// Make actual template:
int nOffset;
{
Matrix<2> m2Warp = mParams.m2Warp();
CVD::transform(mimSharedSourceTemplate, imTwiceToBlur, M2Inverse(m2Warp),
vec(mimSharedSourceTemplate.size() - ImageRef(1, 1)) * 0.5,
vec(imTwiceToBlur.size() - ImageRef(1, 1)) * 0.5);
halfSample(imTwiceToBlur, imToBlur);
convolveGaussian(imToBlur, dBlurSigma);
nOffset = (imToBlur.size().x - mimTemplate.size().x) / 2;
copy(imToBlur, mimTemplate, mimTemplate.size(), ImageRef(nOffset, nOffset));
};
// Make numerical angle jac images:
for (int dof = 0; dof < 2; dof++) {
Matrix<2> m2Warp;
for (int i = 0; i < 2; i++) {
double dAngle = mParams.v2Angles[i];
if (dof == i)
dAngle += 0.01;
m2Warp[0][i] = cos(dAngle);
m2Warp[1][i] = sin(dAngle);
};
CVD::transform(mimSharedSourceTemplate, imTwiceToBlur, M2Inverse(m2Warp),
vec(mimSharedSourceTemplate.size() - ImageRef(1, 1)) * 0.5,
vec(imTwiceToBlur.size() - ImageRef(1, 1)) * 0.5);
halfSample(imTwiceToBlur, imToBlur);
convolveGaussian(imToBlur, dBlurSigma);
ImageRef ir;
do
mimAngleJacs[ir][dof] =
(imToBlur[ir + ImageRef(nOffset, nOffset)] - mimTemplate[ir]) / 0.01;
while (ir.next(mimTemplate.size()));
};
// Make the image of image gradients here too (while we have the bigger
// template to work from)
ImageRef ir;
do {
mimGradients[ir][0] = 0.5 * (imToBlur[ir + ImageRef(nOffset + 1, nOffset)] -
imToBlur[ir + ImageRef(nOffset - 1, nOffset)]);
mimGradients[ir][1] = 0.5 * (imToBlur[ir + ImageRef(nOffset, nOffset + 1)] -
imToBlur[ir + ImageRef(nOffset, nOffset - 1)]);
} while (ir.next(mimGradients.size()));
}
示例6:
float FastCorner::shiTomasiScore_10(const ImageRef<unsigned char>& im, const Point2i& pos)
{
const unsigned char* p3 = &(im.data())[(pos.y - 3) * im.width()];
const unsigned char* p2 = &(im.data())[(pos.y - 2) * im.width()];
const unsigned char* p1 = &(im.data())[(pos.y - 1) * im.width()];
const unsigned char* s = &(im.data())[pos.y * im.width()];
const unsigned char* n1 = &(im.data())[(pos.y + 1) * im.width()];
const unsigned char* n2 = &(im.data())[(pos.y + 2) * im.width()];
const unsigned char* n3 = &(im.data())[(pos.y + 3) * im.width()];
float Dxx = 0.0f;
float Dxy = 0.0f;
float Dyy = 0.0f;
const int endx = pos.x + 3;
for (int x = pos.x - 3; x<=endx; ++x) {
float dx = (float)(p2[x+1] - p2[x-1]); float dy = (float)(p1[x] - p3[x]);
Dxx += dx * dx; Dyy += dy * dy; Dxy += dx * dy;
dx = (float)(p1[x+1] - p1[x-1]); dy = (float)(s[x] - p2[x]);
Dxx += dx * dx; Dyy += dy * dy; Dxy += dx * dy;
dx = (float)(s[x+1] - s[x-1]); dy = (float)(n1[x] - p1[x]);
Dxx += dx * dx; Dyy += dy * dy; Dxy += dx * dy;
dx = (float)(n1[x+1] - n1[x-1]); dy = (float)(n2[x] - s[x]);
Dxx += dx * dx; Dyy += dy * dy; Dxy += dx * dy;
dx = (float)(n2[x+1] - n2[x-1]); dy = (float)(n3[x] - n1[x]);
Dxx += dx * dx; Dyy += dy * dy; Dxy += dx * dy;
}
const float sum_Dxx_Dyy = Dxx + Dyy;
float r = 0.04f * 0.5f * (sum_Dxx_Dyy - std::sqrt(sum_Dxx_Dyy * sum_Dxx_Dyy - 4.0f * (Dxx * Dyy - Dxy * Dxy)));
return r;
}
示例7: ASSERT
ImageRef SubObjectsFromSprite::getImageRef(ObjectId imageId)
{
auto it = m_images.find(imageId);
if (it != m_images.end()) {
ImageRef image = it->second;
ASSERT(image->id() == imageId);
ASSERT(!m_sprite->getImageRef(imageId));
return image;
}
else
return m_sprite->getImageRef(imageId);
}
示例8: MakeSharedTemplate
void CalibCornerPatch::MakeSharedTemplate() {
const int nSideSize = 100;
const int nHalf = nSideSize / 2;
mimSharedSourceTemplate.resize(ImageRef(nSideSize, nSideSize));
ImageRef ir;
do {
float fX = (ir.x < nHalf) ? 1.0 : -1.0;
float fY = (ir.y < nHalf) ? 1.0 : -1.0;
mimSharedSourceTemplate[ir] = fX * fY;
} while (ir.next(mimSharedSourceTemplate.size()));
}
示例9: Image
ImageRef Scene::rasterize(CameraRef camera)
{
ImageRef image = new Image(camera->width(), camera->height());
for (unsigned int y = 0; y < camera->height(); y++) {
for (unsigned int x = 0; x < camera->width(); x++) {
float xPos = (float)x / (float) camera->width() - 0.5f;
float yPos = (float)y / (float) camera->height() - 0.5f;
Ray viewRay = camera->viewRay(xPos, yPos);
HitInfo hitInfo;
if (m_rootGroup->hit(viewRay, &hitInfo)) {
image->setPixelColor(x, y, hitInfo.material->color());
}
}
}
return image;
}
示例10: vec
double CalibCornerPatch::Iterate(Image<byte>& im) {
Vector<2> v2TL =
mParams.v2Pos - vec(mimTemplate.size() - ImageRef(1, 1)) / 2.0;
if (!(v2TL[0] >= 0.0 && v2TL[1] >= 0.0))
return -1.0;
Vector<2> v2BR = v2TL + vec(mimTemplate.size() - ImageRef(1, 1));
if (!(v2BR[0] < (im.size().x - 1.0) && v2BR[1] < (im.size().y - 1.0)))
return -1.0;
image_interpolate<Interpolate::Bilinear, byte> imInterp(im);
Matrix<6> m6JTJ = Zeros;
Vector<6> v6JTD = Zeros;
ImageRef ir;
double dSum = 0.0;
do {
Vector<2> v2Pos_Template =
vec(ir) - vec(mimTemplate.size() - ImageRef(1, 1)) / 2.0;
Vector<2> v2Pos_Image = mParams.v2Pos + v2Pos_Template;
double dDiff = imInterp[v2Pos_Image] -
(mParams.dGain * mimTemplate[ir] + mParams.dMean);
dSum += fabs(dDiff);
Vector<6> v6Jac;
// Jac for center pos: Minus sign because +pos equates to sliding template -
v6Jac.slice<0, 2>() = -1.0 * mParams.dGain * mimGradients[ir];
// Jac for angles: dPos/dAngle needs finishing by multiplying by pos..
v6Jac[2] = mimAngleJacs[ir][0] * mParams.dGain;
v6Jac[3] = mimAngleJacs[ir][1] * mParams.dGain;
// Jac for mean:
v6Jac[4] = 1.0;
// Jac for gain:
v6Jac[5] = mimTemplate[ir];
m6JTJ += v6Jac.as_col() * v6Jac.as_row();
v6JTD += dDiff * v6Jac;
} while (ir.next(mimTemplate.size()));
Cholesky<6> chol(m6JTJ);
Vector<6> v6Update = 0.7 * chol.backsub(v6JTD);
mParams.v2Pos += v6Update.slice<0, 2>();
mParams.v2Angles += v6Update.slice<2, 2>();
mParams.dMean += v6Update[4];
mParams.dGain += v6Update[5];
mdLastError = dSum / mimTemplate.size().area();
return sqrt(v6Update.slice<0, 2>() * v6Update.slice<0, 2>());
}
示例11: DocRangeOps
DocRangeOps() {
black = rgba(0, 0, 0, 0);
white = rgba(255, 255, 255, 255);
doc.reset(static_cast<app::Document*>(ctx.documents().add(4, 4)));
sprite = doc->sprite();
layer1 = dynamic_cast<LayerImage*>(sprite->folder()->getFirstLayer());
layer2 = new LayerImage(sprite);
layer3 = new LayerImage(sprite);
layer4 = new LayerImage(sprite);
sprite->folder()->addLayer(layer2);
sprite->folder()->addLayer(layer3);
sprite->folder()->addLayer(layer4);
EXPECT_LAYER_ORDER(layer1, layer2, layer3, layer4);
layer1->setName("layer1");
layer2->setName("layer2");
layer3->setName("layer3");
layer4->setName("layer4");
sprite->setTotalFrames(frame_t(4));
sprite->setFrameDuration(frame_t(0), 1); // These durations can be used to identify
sprite->setFrameDuration(frame_t(1), 2); // frames after a move operation
sprite->setFrameDuration(frame_t(2), 3);
sprite->setFrameDuration(frame_t(3), 4);
for (int i=0; i<4; i++) {
LayerImage* layer = static_cast<LayerImage*>(sprite->indexToLayer(LayerIndex(i)));
for (int j=0; j<4; j++) {
Cel* cel = layer->cel(frame_t(j));
ImageRef image;
if (cel)
image = cel->imageRef();
else {
image.reset(Image::create(IMAGE_RGB, 4, 4));
cel = new Cel(frame_t(j), image);
layer->addCel(cel);
}
clear_image(image.get(), black);
put_pixel(image.get(), i, j, white);
}
}
}
示例12: makefromImg
void PadTracker::makefromImg(Image<CVD::byte> &img)
{
mirSize = img.size();
mimSmall.resize(mirSize);
mimTemplate.resize(mirSize);
mimSmall = img;
ImageRef ir;
unsigned int nSum = 0;
do
nSum += mimSmall[ir];
while(ir.next(mirSize));
float fMean = ((float) nSum) / mirSize.area();
ir.home();
do
mimTemplate[ir] = mimSmall[ir] - fMean;
while(ir.next(mirSize));
}
示例13: raytrace
void Scene::raytrace(CameraRef camera, Rect rect, RenderOption option, ImageRef image)
{
ASSERT(image->width() == rect.size.width && image->height() == rect.size.height);
for (unsigned int y = 0; y < rect.size.height; y++) {
for (unsigned int x = 0; x < rect.size.width; x++) {
float xPos = (float)(x + rect.origin.x) / (float) camera->width() - 0.5f;
float yPos = (float)(y + rect.origin.y) / (float) camera->height() - 0.5f;
Ray viewRay = camera->viewRay(xPos, yPos);
HitInfo hitInfo;
Color color;
if (traceRay(viewRay, option, 1.0f, 0, &color, &hitInfo)) {
image->setPixelColor(x, y, color);
} else {
// set Background ccolor
//image->setPixelColor(x, y, hitInfo.material->color());
}
}
}
}
示例14: getCurrentBrush
void BrushPreview::generateBoundaries()
{
Brush* brush = getCurrentBrush();
if (m_brushBoundaries &&
m_brushGen == brush->gen())
return;
bool isFloodfill = m_editor->getCurrentEditorTool()->getPointShape(0)->isFloodFill();
Image* brushImage = brush->image();
int w = (isFloodfill ? 1: brushImage->width());
int h = (isFloodfill ? 1: brushImage->height());
m_brushGen = brush->gen();
m_brushWidth = w;
m_brushHeight = h;
ImageRef mask;
if (isFloodfill) {
mask.reset(Image::create(IMAGE_BITMAP, w, w));
mask->putPixel(0, 0, (color_t)1);
}
else if (brushImage->pixelFormat() != IMAGE_BITMAP) {
mask.reset(Image::create(IMAGE_BITMAP, w, h));
LockImageBits<BitmapTraits> bits(mask.get());
auto pos = bits.begin();
for (int v=0; v<h; ++v) {
for (int u=0; u<w; ++u) {
*pos = get_pixel(brushImage, u, v);
++pos;
}
}
}
m_brushBoundaries.reset(
new MaskBoundaries(
(mask ? mask.get(): brushImage)));
}
示例15: gvnCornerPatchSize
bool CalibImage::MakeFromImage(Image<byte>& im) {
static gvar3<int> gvnCornerPatchSize("CameraCalibrator.CornerPatchPixelSize",
20, SILENT);
mvCorners.clear();
mvGridCorners.clear();
mim = im;
mim.make_unique();
// Find potential corners..
// This works better on a blurred image, so make a blurred copy
// and run the corner finding on that.
{
Image<byte> imBlurred = mim;
imBlurred.make_unique();
convolveGaussian(imBlurred,
GV2.GetDouble("CameraCalibrator.BlurSigma", 1.0, SILENT));
ImageRef irTopLeft(5, 5);
ImageRef irBotRight = mim.size() - irTopLeft;
ImageRef ir = irTopLeft;
glPointSize(1);
glColor3f(1, 0, 1);
glBegin(GL_POINTS);
int nGate = GV2.GetInt("CameraCalibrator.MeanGate", 10, SILENT);
do
if (IsCorner(imBlurred, ir, nGate)) {
mvCorners.push_back(ir);
glVertex(ir);
}
while (ir.next(irTopLeft, irBotRight));
glEnd();
}
// If there's not enough corners, i.e. camera pointing somewhere random,
// abort.
if ((int)mvCorners.size() <
GV2.GetInt("CameraCalibrator.MinCornersForGrabbedImage", 20, SILENT))
return false;
// Pick a central corner point...
ImageRef irCenterOfImage = mim.size() / 2;
ImageRef irBestCenterPos;
unsigned int nBestDistSquared = 99999999;
for (unsigned int i = 0; i < mvCorners.size(); i++) {
unsigned int nDist = (mvCorners[i] - irCenterOfImage).mag_squared();
if (nDist < nBestDistSquared) {
nBestDistSquared = nDist;
irBestCenterPos = mvCorners[i];
}
}
// ... and try to fit a corner-patch to that.
CalibCornerPatch Patch(*gvnCornerPatchSize);
CalibCornerPatch::Params Params;
Params.v2Pos = vec(irBestCenterPos);
Params.v2Angles = GuessInitialAngles(mim, irBestCenterPos);
Params.dGain = 80.0;
Params.dMean = 120.0;
if (!Patch.IterateOnImageWithDrawing(Params, mim))
return false;
// The first found corner patch becomes the origin of the detected grid.
CalibGridCorner cFirst;
cFirst.Params = Params;
mvGridCorners.push_back(cFirst);
cFirst.Draw();
// Next, go in two compass directions from the origin patch, and see if
// neighbors can be found.
if (!(ExpandByAngle(0, 0) || ExpandByAngle(0, 2)))
return false;
if (!(ExpandByAngle(0, 1) || ExpandByAngle(0, 3)))
return false;
mvGridCorners[1].mInheritedSteps = mvGridCorners[2].mInheritedSteps =
mvGridCorners[0].GetSteps(mvGridCorners);
// The three initial grid elements are enough to find the rest of the grid.
int nNext;
int nSanityCounter = 0; // Stop it getting stuck in an infinite loop...
const int nSanityCounterLimit = 500;
while ((nNext = NextToExpand()) >= 0 &&
nSanityCounter < nSanityCounterLimit) {
ExpandByStep(nNext);
nSanityCounter++;
}
if (nSanityCounter == nSanityCounterLimit)
return false;
DrawImageGrid();
return true;
}