PageRenderTime 83ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/background.cpp

http://moya-kinect.googlecode.com/
C++ | 161 lines | 90 code | 53 blank | 18 comment | 9 complexity | 2f5f8ed5f743739fa1c32da0d98cb226 MD5 | raw file
  1. //
  2. // background.cpp
  3. // openni_skeleton
  4. //
  5. // Created by ??? ?? on 11/11/03.
  6. // Copyright 2011? __MyCompanyName__. All rights reserved.
  7. //
  8. #include <iostream>
  9. #include "background.h"
  10. bool transBackground( IplImage *initImage, IplImage *endImage, IplImage *dstImage, int startTime, int endTime, int currentTime){
  11. //int startTime = ;
  12. if( endTime < currentTime){
  13. return true;
  14. }
  15. cvAddWeighted(initImage, (double)(endTime - currentTime)/(double)(endTime - startTime), endImage, 1.0 - (double)(endTime - currentTime)/(double)TRANS_TIME, 0.0, dstImage);
  16. return false;
  17. }
  18. bool scrollBackground( IplImage *scrollImage, IplImage *dstImage, int startTime, int endTime, int currentTime){
  19. if( endTime < currentTime){
  20. return true;
  21. }
  22. cvSetImageROI( scrollImage, cvRect( (1.0 - (double)(endTime - currentTime)/(double)(endTime - startTime))*dstImage->width, 0, dstImage->width, dstImage->height));
  23. cvCopy( scrollImage, dstImage);
  24. cvResetImageROI( scrollImage);
  25. return false;
  26. }
  27. void initScrollBackground( IplImage* scrollImage, IplImage* bgImage, IplImage* endImage, int *backnum, bool *bScrollBackground, int *startCount, int *endCount, int count, string dir_path){
  28. initScrollBackground( scrollImage, bgImage, endImage, backnum, bScrollBackground, startCount, endCount, count, dir_path, SCROLL_TIME);
  29. }
  30. // ?????????????
  31. void initScrollBackground( IplImage* scrollImage, IplImage* bgImage, IplImage* endImage, int *backnum, bool *bScrollBackground, int *startCount, int *endCount, int count, string dir_path, int time){
  32. *bScrollBackground = 1;
  33. *endCount = count + time;
  34. *startCount = count;
  35. //endImage?????
  36. (*backnum)++;
  37. if (*backnum > BACK_MAX) {
  38. *backnum = 1;
  39. }
  40. char bgstr[1000];
  41. sprintf(bgstr, "%d", *backnum);
  42. string bgname = dir_path + BACK_DIR + bgstr + ".jpg";
  43. endImage = cvLoadImage( bgname.c_str() , CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
  44. cvSetImageROI( scrollImage, cvRect( 0, 0, endImage->width, endImage->height));
  45. cvCopy( bgImage, scrollImage);
  46. cvSetImageROI( scrollImage, cvRect( endImage->width, 0, endImage->width, endImage->height));
  47. cvCopy( endImage, scrollImage);
  48. cvResetImageROI(scrollImage);
  49. }
  50. // ??????????????
  51. void initTransBackground( IplImage* initImage, IplImage** endImage, IplImage* bImage, int *backnum, bool *bTransBackground, int *startCount, int *endCount, int count, string dir_path){
  52. initTransBackground( initImage, endImage, bImage, backnum, bTransBackground, startCount, endCount, count, dir_path, TRANS_TIME);
  53. }
  54. void initTransBackground( IplImage* initImage, IplImage** endImage, IplImage* bImage, int *backnum, bool *bTransBackground, int *startCount, int *endCount, int count, string dir_path, int time){
  55. *bTransBackground = 1;
  56. *endCount = count + time;
  57. *startCount = count;
  58. cvCopy(bImage, initImage);
  59. //endImage?????
  60. (*backnum)++;
  61. if (*backnum > BACK_MAX) {
  62. *backnum = 1;
  63. }
  64. char bgstr[1000];
  65. sprintf(bgstr, "%d", *backnum);
  66. string bgname = dir_path + BACK_DIR + bgstr + ".jpg";
  67. *endImage = cvLoadImage( bgname.c_str() , CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
  68. }
  69. //????????
  70. void changeBackground( IplImage** bgImage, int *backnum, string dir_path){
  71. (*backnum)++;
  72. if (*backnum > BACK_MAX) {
  73. *backnum = 1;
  74. }
  75. // ???????
  76. char bgstr[1000];
  77. sprintf(bgstr, "%d", *backnum);
  78. string bgname = dir_path + BACK_DIR + bgstr + ".jpg";
  79. *bgImage = cvLoadImage( bgname.c_str() , CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
  80. }
  81. void continueChangeBackground( std::vector<BgElement>* bgList, int *backnum, string dir_path){
  82. int fileCount = 5;
  83. int bgCount = 9;
  84. int changeTypeCount = 2;
  85. int timeArray[] = { 3, 5, 7, 10, 15 };
  86. //int fileNameArray[] = {1, 3, 5, 6, 7};
  87. for ( int i=0; i<fileCount; i++) {
  88. //????
  89. BgElement bg = { timeArray[rand()%fileCount], rand()%bgCount , 1 };
  90. bgList->push_back( bg);
  91. }
  92. }
  93. bool startChangeBackground( IplImage* scrollImage, IplImage* bgImage, IplImage* startImage, IplImage** endImage,
  94. int *backnum, bool *bTransBackground, bool *bScrollBackground, int *startCount, int *endCount, int count, string dir_path, std::vector<BgElement>* bgList){
  95. if(bgList->size() <= 0){
  96. return true;
  97. }
  98. *backnum = bgList->at(0).file_num;
  99. //change_type ?0????Trans
  100. if( bgList->at(0).change_type == 0){
  101. initTransBackground( startImage, endImage, bgImage, backnum, bTransBackground, startCount, endCount, count, dir_path);
  102. }else{
  103. //change_type ?1????Scroll
  104. initScrollBackground( scrollImage, bgImage, *endImage, backnum, bScrollBackground, startCount, endCount, count, dir_path, bgList->at(0).time);
  105. }
  106. bgList->erase( bgList->begin());
  107. return false;
  108. }