# include <Siv3D.hpp>
voidMain()
{
Image image(640, 480, Palette::White);
DynamicTexture texture(image);
while (System::Update())
{
if (Input::MouseL.pressed)
{
auto pos = Input::MouseL.clicked ? Mouse::Pos(): Mouse::PreviousPos();
Line(pos, Mouse::Pos()).write(image, 8, Palette::Blue);
texture.fill(image);
}
texture.draw();
}
}
6.
# include <Siv3D.hpp>
voidMain()
{
Image image(640, 480, Palette::White);
DynamicTexture texture(image);
while (System::Update())
{
if (Input::MouseL.pressed)
{
auto pos = Input::MouseL.clicked ? Mouse::Pos(): Mouse::PreviousPos();
Line(pos, Mouse::Pos()).write(image, 8, Palette::Blue);
texture.fill(image);
}
texture.draw();
}
}
7.
# include <Siv3D.hpp>
voidMain()
{
KinectV2::Start();
DynamicTexture depthTexture;
std::array<Optional<KinectV2Body>, 6> bodies;
while (System::Update())
{
if (KinectV2::HasNewDepthFrame())
KinectV2::GetDepthFrame(depthTexture);
if (KinectV2::HasNewBodyFrame())
KinectV2::GetBodyFrame(bodies);
depthTexture.draw(0, 0);
for (const auto& body : bodies)
if (body)
for (const auto& joint : body->joints)
Circle(joint.depthSpacePos,15).drawFrame(6,0,Palette::Red);
}
}
8.
# include <Siv3D.hpp>
voidMain()
{
KinectV2::Start();
DynamicTexture depthTexture;
std::array<Optional<KinectV2Body>, 6> bodies;
while (System::Update())
{
if (KinectV2::HasNewDepthFrame())
KinectV2::GetDepthFrame(depthTexture);
if (KinectV2::HasNewBodyFrame())
KinectV2::GetBodyFrame(bodies);
depthTexture.draw(0, 0);
for (const auto& body : bodies)
if (body)
for (const auto& joint : body->joints)
Circle(joint.depthSpacePos,15).drawFrame(6,0,Palette::Red);
}
}
9.
# include <Siv3D.hpp>
voidMain() {
const Size blockSize(40, 20);
const double speed = 8.0;
Rect wall(60, 10);
Circle ball(320, 400, 8);
Vec2 ballSpeed(0, -speed);
Array<Rect> blocks;
for (auto p : step({ Window::Width() / blockSize.x, 5 }))
blocks.emplace_back((p*blockSize).moveBy(0, 60), blockSize);
while (System::Update()) {
ball.moveBy(ballSpeed);
wall.setCenter(Mouse::Pos().x, 420);
for (auto it = blocks.begin(); it != blocks.end(); ++it)
if (it->intersects(ball)) {
(it->bottom.intersects(ball) || it->top.intersects(ball) ? ballSpeed.y : ballSpeed.x) *= -1;
blocks.erase(it);
break;
}
for (const auto& block : blocks)
block.stretched(-1).draw(HSV(block.y - 40));
if (ball.y<0 && ballSpeed.y<0)
ballSpeed.y *= -1;
if ((ball.x < 0 && ballSpeed.x < 0) || (Window::Width() < ball.x && ballSpeed.x > 0))
ballSpeed.x *= -1;
if (ballSpeed.y>0 && wall.intersects(ball))
ballSpeed = Vec2((ball.x - wall.center.x) / 8, -ballSpeed.y).normalized()*speed;
ball.draw();
wall.draw();
}
}
10.
# include <Siv3D.hpp>
voidMain() {
const Size blockSize(40, 20);
const double speed = 8.0;
Rect wall(60, 10);
Circle ball(320, 400, 8);
Vec2 ballSpeed(0, -speed);
Array<Rect> blocks;
for (auto p : step({ Window::Width() / blockSize.x, 5 }))
blocks.emplace_back((p*blockSize).moveBy(0, 60), blockSize);
while (System::Update()) {
ball.moveBy(ballSpeed);
wall.setCenter(Mouse::Pos().x, 420);
for (auto it = blocks.begin(); it != blocks.end(); ++it)
if (it->intersects(ball)) {
(it->bottom.intersects(ball) || it->top.intersects(ball) ? ballSpeed.y : ballSpeed.x) *= -1;
blocks.erase(it);
break;
}
for (const auto& block : blocks)
block.stretched(-1).draw(HSV(block.y - 40));
if (ball.y<0 && ballSpeed.y<0)
ballSpeed.y *= -1;
if ((ball.x < 0 && ballSpeed.x < 0) || (Window::Width() < ball.x && ballSpeed.x > 0))
ballSpeed.x *= -1;
if (ballSpeed.y>0 && wall.intersects(ball))
ballSpeed = Vec2((ball.x - wall.center.x) / 8, -ballSpeed.y).normalized()*speed;
ball.draw();
wall.draw();
}
}
CGと画像処理 [3/3]
AR マーカー/ QR コード検出
カメラの映像から AR マーカーや
QR コードの情報を取得できる
顔の検出
写真やカメラの映像、イラストから
人間の顔を検出できる
画像に厚みを持たせて 3D モデル生成
画像に形状を描けば、それに厚みを持たせて
3D モデルを生成できる