from datetime import datetime
import cv2, os
cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
def main():
if cap == None:
return False
out = None
capture = False
while cap.isOpened():
# カメラから映像を読み込む
_, img = cap.read()
cv2.imshow("preview", img)
if capture:
if out != None:
out.write(img)
key = cv2.waitKey(1)
if key == ord('z'):
cv2.imwrite("test.png", img)
if key == ord('x'):
if not capture:
capture = True
out = cv2.VideoWriter('test.avi',fourcc, 20.0, (640,480))
else:
capture = False
out.release()
out = None
elif key < 255:
break
# 事後処理
cap.release()
if out != None:
out.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
main()
bool SampleScene::init()
{
//////////////////////////////
// 1. super init first
if ( !Scene::init() )
{
return false;
}
auto visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
// add "HelloWorld" splash screen"
auto sprite = Sprite::create("pipo-charachip001b.png");
if (sprite == nullptr)
{
problemLoading("'pipo-charachip001b.png'");
}
else
{
// position the sprite on the center of the screen
sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
// add the sprite as a child to this layer
this->addChild(sprite, 0);
}
return true;
}
// add "HelloWorld" splash screen"
auto sprite = Sprite::create("pipo-charachip001b.png", Rect(0,0,32,32));
if (sprite == nullptr)
{
problemLoading("'pipo-charachip001b.png'");
}
else
{
// position the sprite on the center of the screen
sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
// add the sprite as a child to this layer
this->addChild(sprite, 0);
}
auto sprite2 = Sprite::create("pipo-charachip001b.png", Rect(0,32,32,32));
if (sprite2 == nullptr)
{
problemLoading("'pipo-charachip001b.png'");
}
else
{
// position the sprite on the center of the screen
sprite2->setPosition(Vec2(visibleSize.width/2 + origin.x + sprite->getContentSize().width, visibleSize.height/2 + origin.y));
// add the sprite as a child to this layer
this->addChild(sprite2, 0);
}
return true;
じゃあ、これを使って、アニメーションさせます。
auto sprite = Sprite::create("pipo-charachip001b.png");
if (sprite == nullptr)
{
problemLoading("'pipo-charachip001b.png'");
}
else
{
// position the sprite on the center of the screen
sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
// add the sprite as a child to this layer
this->addChild(sprite, 0);
}
Vector<SpriteFrame*> animFrames;
animFrames.reserve(12);
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(0,0,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(32,0,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(64,0,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(0,32,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(32,32,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(64,32,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(0,64,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(32,64,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(64,64,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(0,96,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(32,96,32,32)));
animFrames.pushBack(SpriteFrame::create("pipo-charachip001b.png", Rect(64,96,32,32)));
Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.1f);
Animate* animate = Animate::create(animation);
sprite->runAction(RepeatForever::create(animate));
auto moveBy = MoveBy::create(2, Vec2(50, 0));
sprite->runAction(moveBy);
return true;