void data_welcome() { myprintf(F("** MOON PHASE TABLE\n")); myprintf(F(" JH table size : %d\n"), n_djh); MyTime t = MyTime(yy_ref, mm_ref, dd_ref, hr_ref, 0, 0); t.print(F(" First New Moon :")); myprintln(); }
void data_setup() { n_djh = sizeof(_djh); MyTime t = MyTime(yy_ref, mm_ref, dd_ref, hr_ref, 0, 0); jh_index = 0; jh_prev = t.getJH(); jh_next = jh_prev + get_djh(); }
// Saves list items to file bool FileHandler::saveRegister(list<Movie*> pMediaRegister, const char* fileName) { try { if (pMediaRegister.empty()) { _errorMessage = "Cannot save. List is empty!"; throw _errorMessage; return false; } _outfile.open(fileName); // If file cannot be red if (!_outfile.is_open()) { throw "Error occured when reading file"; return false; } int i = 0; MyTime runTime; char* genre; // Stepping through all list items. Extracts data from them. // Putting data in the register file according to format specification // (one row for one item and one ¤ between every data member for (_it = pMediaRegister.begin(); _it != pMediaRegister.end(); _it++) { _outfile << (*_it)->getID() << "¤"; genre = (*_it)->getGenre(); _outfile << genre << "¤"; _outfile << (*_it)->getTitle() << "¤"; _outfile << (*_it)->getYear() << "¤"; runTime = (*_it)->getRunTime(); _outfile << runTime.getHours() << "," << runTime.getMinutes() << "¤"; _outfile << (*_it)->getDescription() << "¤"; // Specific data for genres if (strcmp(genre, "Sci-Fi") == 0) { _outfile << (*_it)->getSubgenre() << "¤"; _outfile << (*_it)->getSciFiPeriod() << "¤"; } else if (strcmp(genre, "Historic") == 0) { _outfile << (*_it)->getSubgenre() << "¤"; _outfile << (*_it)->getHistoricFigure() << "¤"; _outfile << (*_it)->getTimePeriod() << "¤"; } _outfile << endl; } } catch (char* error) { throw error; } catch (...) { throw 0; } _outfile.close(); return true; }
int main() { int hour, minute, second; MyTime myTime; while (cout<<"Enter Time in the given format ie. Hour:Minute:second ") { cin>>hour>>minute>>second; try{ myTime.setTime(hour, minute, second);//time is set here if exception occurs than catch will handle it. break;//if everything is correct then the loop gets break and continues with other operation. } catch(RangeErrorException &RangeErrorException)//if exception occurs, then it will display the error message and the user have to input the value within the range. { cout<<"Exception error: "<<RangeErrorException.what()<<endl;//if exception occurs then it will perform the task in specified function. } } myTime.nextSecond(); cout<<"Time on next Second :: "<<myTime.toString()<<endl; myTime.nextMinute(); cout<<"Time on next Minute :: "<<myTime.toString()<<endl; myTime.nextHour(); cout<<"Time on next hour :: "<<myTime.toString()<<endl; }
void ui_prompt() { MyTime t = MyTime(); ui_printError(); t.printJD(F("\n")); myprintf(F(" Vcc = %ld mV \n"),ui_readVcc()); myprintln(); if (!RUNNING) myprintf(F("*!* SYSTEM IS NOT RUNNING *!*\n")); if (PHASE_BROKEN) myprintf(F("*!* PHASE SYSTEM BROKEN FLAG IS SET *!*\n")); if (TILT_BROKEN) myprintf(F("*!* TILT SYSTEM BROKEN FLAG IS SET *!*\n")); if (mytime_speed != 0 ) myprintf(F("*!* CLOCK SPEED SET %4d mins/sec *!*\n"), mytime_speed); myprintf(">"); }
void _ui_printState() { MyTime t = MyTime(); moon_updateState(t); float phaseAng = phase_read(); myprintf(F("** PHASE DRIVE SYSTEM\n")); myprintf(F(" phaseOffset : %d\n"), phase_Offset); myprintf(F(" Sensors range : %d->%d %d->%d\n"), sensor1_min, sensor1_max, sensor2_min, sensor2_max); myprintf(F(" Sensor state : ang=%s v1=%d v2=%d \n"), myf2str(phaseAng), phase_sense1, phase_sense2); myprintf(F("** TILT DRIVE SYSTEM\n")); myprintf(F(" servo state : %d->%d->%d parity: %d\n"), tilt_servoDownLimit, servo_pos, tilt_servoUpLimit,tilt_parity); myprintf(F("** LUNAR \n")); myprintf(F(" JH index : %d\n"), data_index()); MyTime tp = MyTime(data_jh_prev(), 0, 0); MyTime tn = MyTime(data_jh_next(), 0, 0); if (data_isWaxing()) { tp.print(F(" Prev New:")); tn.print(F("\n Next Full:")); myprintln(); } else { tp.print(F(" Prev Full: ")); tn.print(F("\n Next New: ")); myprintln(); } myprintf(F(" moon tilt : %s \n"), myf2str(moon_tilt)); myprintf(F(" moon alt : %s \n"), myf2str(moon_alt)); myprintf(F(" moon phase : %s \n"), myf2str(moon_phase)); myprintf(F(" season ang : %s \n"), myf2str(season_ang)); ui_printError(); }
void MyKinect::ProcessDepth(const UINT16* pBuffer, int nWidth, int nHeight, USHORT nMinDepth, USHORT nMaxDepth) {//处理深度,并修复,产生掩码 #ifdef DEBUG MyTime mt; mt.Reset(); mt.Start(); #endif // Make sure we've received valid data if (m_pDepthRGBX && pBuffer && (nWidth == cDepthWidth) && (nHeight == cDepthHeight)) { depthFrames++; cout << "depthFrames第" << depthFrames << "帧" << endl; RGBQUAD* pRGBX = m_pDepthRGBX; const UINT16* pBufferEnd = pBuffer + (nWidth * nHeight); int k1 = 0, k2 = 0; int k3 = 0, k4 = 0; Mat inpaintResult;//修图结果 Mat inpaintMask;//掩码 Mat badMask;//错误点的掩码 badMask = Mat::zeros(Size(nWidth, nHeight), CV_8U); inpaintMask = Mat::zeros(Size(nWidth, nHeight), CV_8U); /*uchar * inpaintDataMask = inpaintMask.data; uchar * badMaskData = badMask.data;//标记当前帧 错误点掩码 uchar * depthMat_LastData= m_pDepthMat_Last.data; uchar * depthMat_LastDataMask = m_pDepthMat_LastMask.data;//前景的掩码 */ /* int a = m_pDepthMat_Last.channels(); int b = m_pDepthMat_LastMask.channels(); int c = badMask.channels(); int d = inpaintMask.channels(); cout << a << " " << b << " " << c << " " << d << endl; */ //考虑到mat字节对齐,改为for for (int i = 0; i < nHeight;i++) { uchar * inpaintDataMask = inpaintMask.ptr<uchar>(i); uchar * badMaskData = badMask.ptr<uchar>(i);//标记当前帧 错误点掩码 uchar * depthMat_LastData = m_pDepthMat_Last.ptr<uchar>(i); uchar * depthMat_LastDataMask = m_pDepthMat_LastMask.ptr<uchar>(i);//前景的掩码 for (int j = 0; j < nWidth;j++) { USHORT depth = *pBuffer; bool maskOfPixel = 0; if (depth <= 0)//must error pixels { depth = 0; badMaskData[j] = (uchar)255; maskOfPixel = 1; k1++; } if (depth > 4500) k2++; depth = depth >> 4;//如何最好的将 450 -- 5500映射到 0 -255里面 //有大量=0的点,2W多 , if (depth >= 255) {//掩码赋值 depth = 255; } BYTE intensity = static_cast<BYTE>(depth); //用上一帧修正 if (maskOfPixel) {//深度有误 k3++; //上一帧的修复只能对背景用,不能对运动的用 //if ((depthMat_LastDataMask[j]) == 0)//是背景 //重要的地方就是 人运动的边缘,而这都是前景区域了。 {//这两个是8u3c的 intensity = (depthMat_LastData[j*3]);//采用上一帧 } if (intensity == 0)// || intensity == 255))//结果表明 摄像头固定,有的点会一直错误 {//上一帧也是错误点,且没修复,接着修复 inpaintDataMask[j] = (uchar)255; k4++; } } pRGBX->rgbRed = intensity; pRGBX->rgbGreen = intensity; pRGBX->rgbBlue = intensity; ++pRGBX; ++pBuffer; } } // std::cout << setw(5)<< k1 << setw(5) << k2 <<"为0点:"<<setw(5)<<k3<<" 修正:"<<setw(5)<<k4<<" "<<" "<<std::endl ; //复制上一帧 // memcpy( m_pDepthRGBX_Last,m_pDepthRGBX, sizeof(RGBQUAD)*cDepthHeight*cDepthWidth); // Draw the data with OpenCV Mat DepthImage(nHeight, nWidth, CV_8UC4, m_pDepthRGBX); //imshow("orignal", DepthImage); //cvMoveWindow("orignal",0,0); Mat depthImageRGB; cvtColor(DepthImage,depthImageRGB,CV_RGBA2RGB); cv::inpaint(depthImageRGB, inpaintMask, inpaintResult, 3, CV_INPAINT_TELEA);// CV_INPAINT_NS);//空洞太大了效果不好 //使用了inpaint后,就是第一帧会修复,其他的都不会修复了。 // imshow("inpaint", inpaintResult); // cvMoveWindow("inpaint", 500, 0); //cvSmooth(&inpaintResult, &m_pDepthMat_Last);这是c格式的支持cvmat的,下面的才是c++的 // Mat blurMat; // blur(inpaintResult, blurMat, Size(3, 3), Point(-1, -1)); //Size( w,h ): // imshow("blur", blurMat); //cvMoveWindow("blur",500,500); //2015-5-10 晚 ,修改为缩小版 cv::resize(m_pDepthMat_Last, m_pDepthMat_Last_Resize, cv::Size(cDepthWidth_RESIZE, cDepthHeight_RESIZE)); //对 fuliye版本 调整位置 cv::GaussianBlur(inpaintResult, m_pDepthMat_Last, Size(3, 3), 0,0); //Size( w,h ): // m_pDepthMat_Last = inpaintResult.clone();//保存上一帧 // imshow("gaussianBlur", m_pDepthMat_Last); //cvMoveWindow("gaussianBlur",0,500); // cvMoveWindow("gaussianBlur", 0, 0); // cvWaitKey(1); // cout << "m_pDepthMat_Last :" << m_pDepthMat_Last.channels(); Mat foreMat;//提取前景 //m_pDepthBackProcess.process_Mog2(m_pDepthMat_Last, foreMat); // m_pDepthBackProcess.depthProcessBackGround(m_pDepthMat_Last, m_pDepthMat_LastMask); // m_pDepthBackProcess.testManyMethod(m_pDepthMat_Last, foreMat); m_pDepthBackProcess.depthProcessBackGround(m_pDepthMat_Last_Resize, m_pDepthMat_LastMask_Resize); /* 测试分割 ImageSegment iseg; m_pTempshow=iseg.regiongrowthIndepth3(m_pDepthMat_Last, m_pDepthMat_LastMask); */ /* if( (foreMat.rows !=0 )&& (foreMat.cols !=0)) { m_pDepthMat_LastMask = foreMat.clone();//保存前景的掩码 }*/ // cout <<"通道数目"<< inpaintResult.channels(); // BaseImageTools::SaveDepthImageToAVI(inpaintResult, nWidth, nHeight, depthWriter); // BaseImageTools::SaveDepthImageToAVI(inpaintResult, nWidth, nHeight, depthWriter2); //BaseImageTools::SaveDepthImageToAVI(DepthImage, nWidth, nHeight, depthWriter); /* Mat show = DepthImage.clone(); imshow("DepthImage2", show); */ }
int main() { int hour,minute,second; MyTime time; while(cout << "Enter time in format HH:MM:SS ") { cin>>hour>>minute>>second; try { time.setTime(hour,minute,second); break; } catch (OutOfRangeException &OutOfRangeException){ cout << "Exception Occured !!! " << OutOfRangeException.what() << endl; } } time.nextSecond(); cout << "After one second, time is -> " << time.toString() << endl; time.nextMinute(); cout << "After one minute, time is -> " << time.toString() << endl; time.nextHour(); cout << "After one hour, time is -> " << time.toString() << endl; time.previousSecond(); cout << "Before one second, time was -> " << time.toString() << endl; time.previousMinute(); cout << "Before one minute, time was -> " << time.toString() << endl; time.previousHour(); cout << "Before one hour, time was -> " << time.toString() << endl; }
bool MyTime::operator >=(const MyTime t) const { return (this->toMinutes() >= t.toMinutes()); }
bool MyTime::operator ==(const MyTime t) const { return ((this->days() == t.days()) && (this->hours() == t.hours()) && (this->minutes() == t.minutes())); }
MyTime MyTime::operator -(const MyTime t) const { return MyTime(this->days() - t.days(), this->hours() - t.hours(), this->minutes() - t.minutes()); }
// +, += (Addition - takes a MyTime) MyTime MyTime::operator+ (const MyTime & aMyTime) const { MyTime current; current.AddTicks(this->_ticks); current.AddTime(aMyTime); return current; }
// Process a line. static void ui_command(char *cmd) { char *tok; MyTime tm = MyTime(); int n = 1, incHr = 1; int phaseOff, d, u, tmp; myflush(); myprintln(); switch (cmd[0]) { case 'M': tok = strtok(cmd, " :"); tok = strtok(NULL, " "); if (tok == NULL) { n = 10; } else { n = in_range(1, 200, atoi(tok)); } moon_halfTable(n); break; case 'C': phase_calibrate(); break; case '!': error_mess = NULL; PHASE_BROKEN = false; TILT_BROKEN =false; BREAK = false; servo_retry_count = 0; break; case 'H': phase_halt(); RUNNING = false; break; case 'T': // tilt override. tok = strtok(cmd, " :"); tok = strtok(NULL, " "); if (tok == NULL) goto INVALID; ui_tilt = in_range(-80, 80, atoi(tok)); if (RUNNING) myprintf(F("*!* Halt system to take effect \n")); break; case 'D': { MyTime t1; if (t1.parseStr(&cmd[2])) { t1.writeRTC(); delay(1500); MyTime t2 = MyTime(); t2.print(F("\n check me : ")); myprintln(); } else { myprintf(F(" Error in date time input \n")); } } break; case 'P': // phase tok = strtok(cmd, " :"); tok = strtok(NULL, " "); if (tok == NULL) goto INVALID; ui_phase = in_range(-180, 180, atoi(tok)); if (RUNNING) myprintf(F("*!* Halt system to take effect \n")); else phase_set(ui_phase); break; case 'O': // phase offset tok = strtok(cmd, " :"); tok = strtok(NULL, " "); if (tok == NULL) goto INVALID; phaseOff = in_range(-360, 360, atoi(tok)); phase_setOffset(phaseOff); if (!RUNNING) phase_set(ui_phase); break; case 't': tok = strtok(cmd, " :"); tok = strtok(NULL, " "); if (tok == NULL) goto INVALID; d = in_range(SERVO_MIN, SERVO_MID, atoi(tok)); tok = strtok(NULL, " "); if (tok == NULL) goto INVALID; u = in_range(SERVO_MID, SERVO_MAX, atoi(tok)); tilt_setLimits(d, u); break; case 'p': tok = strtok(cmd, " :"); tok = strtok(NULL, " "); if (tok == NULL) goto INVALID; tilt_parity = atoi(tok) ; break; case 'S': tok = strtok(cmd, " :"); tok = strtok(NULL, " "); if (tok == NULL) goto INVALID; mytime_setSpeed(in_range(-100, 100, atoi(tok))); RUNNING=true; break; case 'W': eeprom_write(); break; case 'R': BREAK = false; RUNNING = true; error_mess = NULL; mytime_setSpeed(0); break; case '?': ui_welcome(); break; case 'L': { int Minute = tm.getMinute(); int Second = tm.getSecond(); int Year = tm.getYear(); int Month = tm.getMonth(); int Day = tm.getDay(); int Hour = tm.getHour(); tok = strtok(cmd, " :"); tok = strtok(NULL, " "); if (tok == NULL) goto OK2; n = in_range(1, 200, atoi(tok)); tok = strtok(NULL, " "); if (tok == NULL) goto OK2; incHr = in_range(1, 366 * 24, atoi(tok)); tok = strtok(NULL, " "); if (tok == NULL) goto OK2; Year = in_range(2016, 2200, atoi(tok)); tok = strtok(NULL, " "); if (tok == NULL) goto OK2; Month = in_range(1, 12, atoi(tok)); tok = strtok(NULL, " "); if (tok == NULL) goto OK2; Day = in_range(1, mytime_daysInMonth(Month, Year), atoi(tok)); tok = strtok(NULL, " "); if (tok == NULL) goto OK2; Hour = in_range(0, 23, atoi(tok)); tok = strtok(NULL, " "); if (tok == NULL) goto OK2; Minute = in_range(0, 59, atoi(tok)); tok = strtok(NULL, " "); if (tok == NULL) goto OK2; Second = in_range(0, 59, atoi(tok)); OK2: MyTime tt = MyTime(Year, Month, Day, Hour, Minute, Second); moon_printTable(tt, n, incHr); } break; } ui_prompt(); return; INVALID: myprintf(F("\n Command error \n>"), cmd); ui_prompt(); return; }