void PlayerCar::loadSpine() { try { ifstream atlasFile("spineboy.atlas"); atlas = new Atlas(atlasFile); SkeletonJson skeletonJson(atlas); skeletonJson.scale = 0.5; ifstream skeletonFile("spineboy-skeleton.json"); skeletonData = skeletonJson.readSkeletonData(skeletonFile); ifstream animationFile("spineboy-walk.json"); animation = skeletonJson.readAnimation(animationFile, skeletonData); skeleton = new Skeleton(skeletonData); skeleton->flipX = false; skeleton->flipY = false; skeleton->setToBindPose(); skeleton->getRootBone()->x = 200; skeleton->getRootBone()->y = 500; skeleton->updateWorldTransform(); } catch (exception &ex) { cout << ex.what() << endl << flush; } }
void DAI4REID_ParsedInstance::nextFrame(QHashDataFrames &output) { // Read Color File QString instancePath = m_info.parent().getPath() + "/" + m_info.getFileName(DataFrame::Color); cv::Mat color_mat = cv::imread(instancePath.toStdString()); cv::cvtColor(color_mat, color_mat, CV_BGR2RGB); ColorFrame srcColor(color_mat.cols, color_mat.rows, (RGBColor*) color_mat.data); shared_ptr<ColorFrame> dstColor = make_shared<ColorFrame>(); *dstColor = srcColor; // Copy output.insert(DataFrame::Color, dstColor); // Read Depth File instancePath = m_info.parent().getPath() + "/" + m_info.getFileName(DataFrame::Depth); QFile depthFile(instancePath); depthFile.open(QIODevice::ReadOnly); QByteArray buffer = depthFile.readAll(); depthFile.close(); shared_ptr<DepthFrame> depthFrame = make_shared<DepthFrame>(); depthFrame->loadData(buffer); depthFrame->setDistanceUnits(dai::DISTANCE_MILIMETERS); depthFrame->setCameraIntrinsics(594.21434211923247, 320.0, -591.04053696870778, 240.0); output.insert(DataFrame::Depth, depthFrame); // Set color frame offset based on the depth bin that may contain it. dstColor->setOffset(depthFrame->offset()); /*instancePath = m_info.parent().getPath() + "/" + m_info.getFileName(DataFrame::Depth); cv::Mat depth_mat = cv::imread(instancePath.toStdString()); //, CV_LOAD_IMAGE_GRAYSCALE); qDebug() << depth_mat.type() << depth_mat.depth() << depth_mat.channels(); DepthFrame srcDepth(depth_mat.cols, depth_mat.rows, (uint16_t*) depth_mat.data, depth_mat.step); shared_ptr<DepthFrame> depthFrame = make_shared<DepthFrame>(); *depthFrame = srcDepth; // Copy depthFrame->setDistanceUnits(dai::MILIMETERS); output.insert(DataFrame::Depth, depthFrame);*/ // Read Mask File instancePath = m_info.parent().getPath() + "/" + m_info.getFileName(DataFrame::Mask); QFile maskFile(instancePath); maskFile.open(QIODevice::ReadOnly); buffer = maskFile.readAll(); maskFile.close(); shared_ptr<MaskFrame> maskFrame = make_shared<MaskFrame>(); maskFrame->loadData(buffer); output.insert(DataFrame::Mask, maskFrame); // Read Skeleton File instancePath = m_info.parent().getPath() + "/" + m_info.getFileName(DataFrame::Skeleton); QFile skeletonFile(instancePath); skeletonFile.open(QIODevice::ReadOnly); buffer = skeletonFile.readAll(); skeletonFile.close(); shared_ptr<Skeleton> skeleton = Skeleton::fromBinary(buffer); skeleton->setCameraIntrinsics(594.21434211923247, 320.0, -591.04053696870778, 240.0); shared_ptr<SkeletonFrame> skeletonFrame = make_shared<SkeletonFrame>(); skeletonFrame->setSkeleton(1, skeleton); output.insert(DataFrame::Skeleton, skeletonFrame); }
void IASLAB_RGBD_ID_Instance::nextFrame(QHashDataFrames &output) { // Read Color File QString instancePath = m_info.parent().getPath() + "/" + m_info.getFileName(DataFrame::Color); cv::Mat color_mat = cv::imread(instancePath.toStdString()); cv::cvtColor(color_mat, color_mat, CV_BGR2RGB); ColorFrame srcColor(color_mat.cols, color_mat.rows, (RGBColor*) color_mat.data); shared_ptr<ColorFrame> dstColor = make_shared<ColorFrame>(); *dstColor = srcColor; // Copy output.insert(DataFrame::Color, dstColor); // Read Depth File instancePath = m_info.parent().getPath() + "/" + m_info.getFileName(DataFrame::Depth); QFile depthFile(instancePath); depthFile.open(QIODevice::ReadOnly); QByteArray buffer = depthFile.readAll(); depthFile.close(); shared_ptr<DepthFrame> depthFrame_tmp = make_shared<DepthFrame>(640, 480, (uint16_t*) (buffer.data() + 16)); shared_ptr<DepthFrame> depthFrame = shared_ptr<DepthFrame>(new DepthFrame(*depthFrame_tmp)); // Clone! depthFrame->setDistanceUnits(dai::DISTANCE_MILIMETERS); // Set Depth intrinsics of the camera that generated this frame depthFrame->setCameraIntrinsics(fx_d, cx_d, fy_d, cy_d); output.insert(DataFrame::Depth, depthFrame); // Read Mask File instancePath = m_info.parent().getPath() + "/" + m_info.getFileName(DataFrame::Mask); QFile maskFile(instancePath); maskFile.open(QIODevice::ReadOnly); buffer = maskFile.readAll(); maskFile.close(); shared_ptr<MaskFrame> maskFrame_tmp = make_shared<MaskFrame>(640, 480, (uint8_t*) (buffer.data() + 14)); shared_ptr<MaskFrame> maskFrame = shared_ptr<MaskFrame>(new MaskFrame(*maskFrame_tmp)); // Clone! output.insert(DataFrame::Mask, maskFrame); // Read Skeleton txt file (line by line) /*For every frame, a skeleton file is available. For every joint, a row with the following information is written to the skeleton file: [id]: person ID, [x3D], [y3D], [z3D]: joint 3D position, [x2D], [y2D]: joint 2D position, [TrackingState]: 0 (not tracked), 1 (inferred) or 2 (tracked), [QualityFlag]: not implemented by NiTE, thus it is always 0, [OrientationStartJoint], [OrientationEndJoint]: indices of the extreme joints of a link, [Qx], [Qy], [Qz], [Qw]: quaternion expressing the orientation of the link identified by [OrientationStartJoint] and [OrientationEndJoint]. NiTE provides 15 joints, but these are remapped to the 20 joints that Microsoft Kinect SDK estimates, in order to have the same format (the joint positions missing in NiTE (wrists, ankles) are copied from other joints (hands, feet)). For more information, please visit http://msdn.microsoft.com/en-us/library/hh973074.aspx. You can also visualize the data with the "visualize_IASLab_RGBDID_dataset.m" Matlab script we provided.*/ instancePath = m_info.parent().getPath() + "/" + m_info.getFileName(DataFrame::Skeleton); QFile skeletonFile(instancePath); skeletonFile.open(QIODevice::ReadOnly); QTextStream in(&skeletonFile); shared_ptr<Skeleton> skeleton = make_shared<Skeleton>(); QList<int> ignore_lines = {1, 7, 11, 15, 19}; int lineCount = 0; while (!in.atEnd()) { QStringList columns = in.readLine().split(","); if (ignore_lines.contains(lineCount)) { lineCount++; continue; } SkeletonJoint joint(Point3f(columns[1].toFloat()*1000.0f, columns[2].toFloat()*1000.0f*-1, columns[3].toFloat()*1000.0f), _staticMap[lineCount]); int trackingState = columns[6].toInt(); if (trackingState == 0) joint.setPositionConfidence(0.0f); joint.setOrientation(Quaternion(columns[13].toFloat(), columns[10].toFloat(), columns[11].toFloat(), columns[12].toFloat())); //joint.setOrientationConfidence(niteJoint.getOrientationConfiden skeleton->setJoint(_staticMap[lineCount], joint); lineCount++; } skeletonFile.close(); // Set intrinsics of the camera that generated this frame (depth camera in this case) skeleton->setCameraIntrinsics(fx_d, cx_d, fy_d, cy_d); shared_ptr<SkeletonFrame> skeletonFrame = make_shared<SkeletonFrame>(); skeletonFrame->setSkeleton(1, skeleton); output.insert(DataFrame::Skeleton, skeletonFrame); // Register depth to color depth2color(depthFrame, maskFrame, skeleton); }
Player::Player(ObjectLayer* layer, b2Vec2 position, uint16_t location) : layer(location), Collider(Collider::Player), inPortal(false), portalDirection(Portal::Up){ chdir("assets/player"); this->map = layer->map; b2BodyDef bodyDef; bodyDef.type = b2_dynamicBody; bodyDef.position = position; bodyDef.fixedRotation = true; body = layer->world.CreateBody(&bodyDef); body->SetUserData((Collider*)this); b2PolygonShape dynamicBox; dynamicBox.SetAsBox(0.47f, 0.75f, b2Vec2(0.5, 0.75), 0); b2FixtureDef fixtureDef; fixtureDef.shape = &dynamicBox; fixtureDef.density = 0.1f; fixtureDef.friction = 0; fixtureDef.userData = (b2ContactListener*)this; body->CreateFixture(&fixtureDef); b2CircleShape circle; circle.m_p.Set(0.5f, 1.5f); circle.m_radius = 0.49f; fixtureDef.shape = &circle; fixtureDef.density = 0.1f; fixtureDef.friction = 0.f; fixtureDef.userData = (b2ContactListener*)this; body->CreateFixture(&fixtureDef); b2CircleShape circlef; circlef.m_p.Set(0.5f, 1.9f); circlef.m_radius = 0.1; fixtureDef.shape = &circlef; fixtureDef.density = 0.1f; fixtureDef.friction = 2.f; fixtureDef.userData = (b2ContactListener*)this; body->CreateFixture(&fixtureDef); b2PolygonShape sensorBox; sensorBox.SetAsBox(0.45f, 0.1f, b2Vec2(0.5f, 2.f), 0); fixtureDef.shape = &sensorBox; fixtureDef.isSensor = true; fixtureDef.userData = (b2ContactListener*)this; body->CreateFixture(&fixtureDef); state = PlayerStanding; impulse = ImpulseNone; direction = Right; time = 0; jumpStart = 0; grounded = 0; std::ifstream atlasFile("pack.atlas"); atlas.reset(new spine::Atlas(atlasFile)); spine::SkeletonJson skeletonJson(atlas.get()); std::ifstream skeletonFile("skeleton.json"); skeletonData.reset(skeletonJson.readSkeletonData(skeletonFile)); std::ifstream animationFile("skeleton-run3.json"); run.reset(skeletonJson.readAnimation(animationFile, skeletonData.get())); skeleton.reset(new spine::Skeleton(skeletonData.get())); skeleton->flipX = false; skeleton->flipY = false; skeleton->setToBindPose(); skeleton->getRootBone()->x = X_OFFSET; skeleton->getRootBone()->y = Y_OFFSET; skeleton->updateWorldTransform(); sync(); chdir("../.."); }