/background.cpp
C++ | 161 lines | 90 code | 53 blank | 18 comment | 9 complexity | 2f5f8ed5f743739fa1c32da0d98cb226 MD5 | raw file
- //
- // background.cpp
- // openni_skeleton
- //
- // Created by ??? ?? on 11/11/03.
- // Copyright 2011? __MyCompanyName__. All rights reserved.
- //
- #include <iostream>
- #include "background.h"
- bool transBackground( IplImage *initImage, IplImage *endImage, IplImage *dstImage, int startTime, int endTime, int currentTime){
- //int startTime = ;
-
- if( endTime < currentTime){
- return true;
- }
-
- cvAddWeighted(initImage, (double)(endTime - currentTime)/(double)(endTime - startTime), endImage, 1.0 - (double)(endTime - currentTime)/(double)TRANS_TIME, 0.0, dstImage);
-
- return false;
- }
- bool scrollBackground( IplImage *scrollImage, IplImage *dstImage, int startTime, int endTime, int currentTime){
-
- if( endTime < currentTime){
- return true;
- }
-
- cvSetImageROI( scrollImage, cvRect( (1.0 - (double)(endTime - currentTime)/(double)(endTime - startTime))*dstImage->width, 0, dstImage->width, dstImage->height));
- cvCopy( scrollImage, dstImage);
-
- cvResetImageROI( scrollImage);
- return false;
-
- }
- void initScrollBackground( IplImage* scrollImage, IplImage* bgImage, IplImage* endImage, int *backnum, bool *bScrollBackground, int *startCount, int *endCount, int count, string dir_path){
- initScrollBackground( scrollImage, bgImage, endImage, backnum, bScrollBackground, startCount, endCount, count, dir_path, SCROLL_TIME);
- }
- // ?????????????
- void initScrollBackground( IplImage* scrollImage, IplImage* bgImage, IplImage* endImage, int *backnum, bool *bScrollBackground, int *startCount, int *endCount, int count, string dir_path, int time){
- *bScrollBackground = 1;
- *endCount = count + time;
- *startCount = count;
-
- //endImage?????
- (*backnum)++;
- if (*backnum > BACK_MAX) {
- *backnum = 1;
- }
-
- char bgstr[1000];
- sprintf(bgstr, "%d", *backnum);
- string bgname = dir_path + BACK_DIR + bgstr + ".jpg";
-
- endImage = cvLoadImage( bgname.c_str() , CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
-
-
- cvSetImageROI( scrollImage, cvRect( 0, 0, endImage->width, endImage->height));
- cvCopy( bgImage, scrollImage);
-
- cvSetImageROI( scrollImage, cvRect( endImage->width, 0, endImage->width, endImage->height));
- cvCopy( endImage, scrollImage);
-
- cvResetImageROI(scrollImage);
- }
- // ??????????????
- void initTransBackground( IplImage* initImage, IplImage** endImage, IplImage* bImage, int *backnum, bool *bTransBackground, int *startCount, int *endCount, int count, string dir_path){
- initTransBackground( initImage, endImage, bImage, backnum, bTransBackground, startCount, endCount, count, dir_path, TRANS_TIME);
- }
- void initTransBackground( IplImage* initImage, IplImage** endImage, IplImage* bImage, int *backnum, bool *bTransBackground, int *startCount, int *endCount, int count, string dir_path, int time){
- *bTransBackground = 1;
- *endCount = count + time;
- *startCount = count;
-
- cvCopy(bImage, initImage);
-
- //endImage?????
- (*backnum)++;
- if (*backnum > BACK_MAX) {
- *backnum = 1;
- }
-
- char bgstr[1000];
- sprintf(bgstr, "%d", *backnum);
- string bgname = dir_path + BACK_DIR + bgstr + ".jpg";
-
- *endImage = cvLoadImage( bgname.c_str() , CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
- }
- //????????
- void changeBackground( IplImage** bgImage, int *backnum, string dir_path){
-
- (*backnum)++;
- if (*backnum > BACK_MAX) {
- *backnum = 1;
- }
-
- // ???????
- char bgstr[1000];
- sprintf(bgstr, "%d", *backnum);
- string bgname = dir_path + BACK_DIR + bgstr + ".jpg";
-
- *bgImage = cvLoadImage( bgname.c_str() , CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
-
- }
- void continueChangeBackground( std::vector<BgElement>* bgList, int *backnum, string dir_path){
-
-
- int fileCount = 5;
- int bgCount = 9;
- int changeTypeCount = 2;
-
- int timeArray[] = { 3, 5, 7, 10, 15 };
- //int fileNameArray[] = {1, 3, 5, 6, 7};
-
-
- for ( int i=0; i<fileCount; i++) {
- //????
-
- BgElement bg = { timeArray[rand()%fileCount], rand()%bgCount , 1 };
- bgList->push_back( bg);
-
- }
-
- }
- bool startChangeBackground( IplImage* scrollImage, IplImage* bgImage, IplImage* startImage, IplImage** endImage,
- int *backnum, bool *bTransBackground, bool *bScrollBackground, int *startCount, int *endCount, int count, string dir_path, std::vector<BgElement>* bgList){
-
- if(bgList->size() <= 0){
- return true;
- }
-
- *backnum = bgList->at(0).file_num;
-
- //change_type ?0????Trans
- if( bgList->at(0).change_type == 0){
- initTransBackground( startImage, endImage, bgImage, backnum, bTransBackground, startCount, endCount, count, dir_path);
- }else{
- //change_type ?1????Scroll
- initScrollBackground( scrollImage, bgImage, *endImage, backnum, bScrollBackground, startCount, endCount, count, dir_path, bgList->at(0).time);
- }
- bgList->erase( bgList->begin());
- return false;
- }