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); }
bool MaskChan::createMaskChanForLabel(int label, const QString& maskFullPath, const QString& channelFullPath, QReadWriteLock* mutex) { QList<long> pairCountList; // x=0, y=1, z=2 QList<MaskRay*> xRayList; QList<MaskRay*> yRayList; QList<MaskRay*> zRayList; QList<long> x0List; QList<long> x1List; QList<long> y0List; QList<long> y1List; QList<long> z0List; QList<long> z1List; for (int direction=0;direction<3;direction++) { QList<MaskRay*> * rayList; long pairCount=0L; long countCheck=0L; if (direction==0) { rayList=&xRayList; } else if (direction==1) { rayList=&yRayList; } else { rayList=&zRayList; } long x0,x1,y0,y1,z0,z1; axisTracer(direction, label, rayList, pairCount, countCheck, x0, x1, y0, y1, z0, z1); x0List.append(x0); x1List.append(x1); y0List.append(y0); y1List.append(y1); z0List.append(z0); z1List.append(z1); pairCountList.append(pairCount); pairCount=0L; if (countCheck!=labelIndex[label]) { qDebug() << "Count check failed : direction=" << direction << " countCheck=" << countCheck << " labelIndex=" << labelIndex[label]; return false; } else { //qDebug() << "Direction " << direction << " passed voxel count check"; } } // We have computed the ray set for each axis, we will save the one with the // smallest size. for (int s=0;s<pairCountList.size();s++) { //qDebug() << "pairCount " << s << " : " << pairCountList[s]; } unsigned char smallestSize=0; if (pairCountList[1]<pairCountList[smallestSize]) { smallestSize=1; } if (pairCountList[2]<pairCountList[smallestSize]) { smallestSize=2; } long x0=x0List[smallestSize]; long x1=x1List[smallestSize]; long y0=y0List[smallestSize]; long y1=y1List[smallestSize]; long z0=z0List[smallestSize]; long z1=z1List[smallestSize]; long totalVoxels=labelIndex[label]; // allocate space for data long unitsNeeded=totalVoxels*cdim; void* data=0L; if (sourceImage->getDatatype()==V3D_UINT8) { data=(void*) new v3d_uint8[unitsNeeded]; } else { data=(void*) new v3d_uint16[unitsNeeded]; } // re-run axis-tracer and populate channel intensity data QList<MaskRay*> * rayList; long pairCount=0L; long countCheck=0L; if (smallestSize==0) { rayList=&xRayList; } else if (smallestSize==1) { rayList=&yRayList; } else { rayList=&zRayList; } //qDebug() << "calling axisTracer 2nd pass data=" << data; rayList->clear(); // will get re-populated axisTracer(smallestSize, label, rayList, pairCount, countCheck, x0, x1, y0, y1, z0, z1, data, totalVoxels); if (countCheck!=totalVoxels) { qDebug() << "In second pass of axisTracer, countCheck=" << countCheck << " totalVoxels=" << totalVoxels; exit(1); } //qDebug() << "Using axis " << smallestSize; //qDebug() << "Writing to file and locking with QMutex" << maskFullPath; if (mutex!=0L) { QWriteLocker locker(mutex); // Will be deleted from stack } QFile maskFile(maskFullPath); //////////////////////////////////////////////////////////////////////// // FILE* fid = fopen(maskFullPath.toAscii().data(), "wb"); // if (!fid) { // qDebug() << "Could not open file " << maskFullPath << " to write"; // return false; // } maskFile.open( QIODevice::WriteOnly ); QDataStream maskOut(&maskFile); //qDebug() << "Writing xdim=" << xdim << " ydim=" << ydim << " zdim=" << zdim; maskOut.writeRawData( (const char*) &xdim, sizeof(long)); maskOut.writeRawData( (const char *)&ydim, sizeof(long)); maskOut.writeRawData( (const char *)&zdim, sizeof(long)); float xMicrons=0.0; float yMicrons=0.0; float zMicrons=0.0; maskOut.writeRawData( (const char *)&xMicrons, sizeof(float)); maskOut.writeRawData( (const char *)&yMicrons, sizeof(float)); maskOut.writeRawData( (const char *)&zMicrons, sizeof(float)); maskOut.writeRawData( (const char *)&x0, sizeof(long)); maskOut.writeRawData( (const char *)&x1, sizeof(long)); maskOut.writeRawData( (const char *)&y0, sizeof(long)); maskOut.writeRawData( (const char *)&y1, sizeof(long)); maskOut.writeRawData( (const char *)&z0, sizeof(long)); maskOut.writeRawData( (const char *)&z1, sizeof(long)); maskOut.writeRawData( (const char *)&totalVoxels, sizeof(long)); maskOut.writeRawData( (const char *)&smallestSize, sizeof(unsigned char)); if (smallestSize==0) { writeMaskList(maskOut, xRayList); } else if (smallestSize==1) { writeMaskList(maskOut, yRayList); } else { writeMaskList(maskOut, zRayList); } // fflush(fid); // fclose(fid); // fid=0L; maskFile.close(); qDebug() << "Wrote " << maskFullPath; // Write out the channel file // First, clear the previous masks for (int d=0;d<3;d++) { QList<MaskRay*> * rayList; if (d==0) { rayList=&xRayList; } else if (d==1) { rayList=&yRayList; } else { rayList=&zRayList; } for (int i=0;i<rayList->size();i++) { MaskRay* ray = (*rayList)[i]; delete ray; } rayList->clear(); } QFile channelFile(channelFullPath); channelFile.open( QIODevice::WriteOnly ); //qDebug() << "Writing to file " << channelFullPath; // fid = fopen(channelFullPath.toAscii().data(), "wb"); // if (!fid) { // qDebug() << "Could not open file " << channelFullPath << " to write"; // return false; // } QDataStream chanOut(&channelFile); chanOut.writeRawData( (const char *)&totalVoxels, sizeof(long)); unsigned char numChannels=sourceImage->getCDim(); chanOut.writeRawData( (const char *)&numChannels, sizeof(unsigned char)); unsigned char recRed=0; unsigned char recGreen=1; unsigned char recBlue=2; chanOut.writeRawData( (const char *)&recRed, sizeof(unsigned char)); chanOut.writeRawData( (const char *)&recGreen, sizeof(unsigned char)); chanOut.writeRawData( (const char *)&recBlue, sizeof(unsigned char)); unsigned char datatype=1; // 8-bit if (sourceImage->getDatatype()==V3D_UINT16) { datatype=2; // 16-bit } chanOut.writeRawData( (const char *)&datatype, sizeof(unsigned char)); chanOut.writeRawData( (const char *)data, totalVoxels*cdim*datatype); // fflush(fid); // fclose(fid); channelFile.close(); qDebug() << "Wrote " << channelFullPath; return true; }