Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * $Id$ | |
3 * | |
4 * ***** BEGIN GPL LICENSE BLOCK ***** | 2 * ***** BEGIN GPL LICENSE BLOCK ***** |
5 * | 3 * |
6 * This program is free software; you can redistribute it and/or | 4 * This program is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU General Public License | 5 * modify it under the terms of the GNU General Public License |
8 * as published by the Free Software Foundation; either version 2 | 6 * as published by the Free Software Foundation; either version 2 |
9 * of the License, or (at your option) any later version. | 7 * of the License, or (at your option) any later version. |
10 * | 8 * |
11 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
(...skipping 16 matching lines...) Expand all Loading... | |
30 * \ingroup bke | 28 * \ingroup bke |
31 */ | 29 */ |
32 | 30 |
33 #include <stddef.h> | 31 #include <stddef.h> |
34 #include <limits.h> | 32 #include <limits.h> |
35 #include <math.h> | 33 #include <math.h> |
36 #include <memory.h> | 34 #include <memory.h> |
37 | 35 |
38 #include "MEM_guardedalloc.h" | 36 #include "MEM_guardedalloc.h" |
39 | 37 |
38 #include "DNA_gpencil_types.h" | |
40 #include "DNA_movieclip_types.h" | 39 #include "DNA_movieclip_types.h" |
41 #include "DNA_object_types.h" /* SELECT */ | 40 #include "DNA_object_types.h" /* SELECT */ |
42 #include "DNA_scene_types.h" | 41 #include "DNA_scene_types.h" |
43 | 42 |
44 #include "BLI_utildefines.h" | 43 #include "BLI_utildefines.h" |
45 #include "BLI_math.h" | 44 #include "BLI_math.h" |
46 #include "BLI_listbase.h" | 45 #include "BLI_listbase.h" |
47 #include "BLI_ghash.h" | 46 #include "BLI_ghash.h" |
47 #include "BLI_path_util.h" | |
48 | 48 |
49 #include "BKE_global.h" | 49 #include "BKE_global.h" |
50 #include "BKE_tracking.h" | 50 #include "BKE_tracking.h" |
51 #include "BKE_movieclip.h" | 51 #include "BKE_movieclip.h" |
52 #include "BKE_object.h" | 52 #include "BKE_object.h" |
53 #include "BKE_scene.h" | 53 #include "BKE_scene.h" |
54 | 54 |
55 #include "IMB_imbuf_types.h" | 55 #include "IMB_imbuf_types.h" |
56 #include "IMB_imbuf.h" | 56 #include "IMB_imbuf.h" |
57 | 57 |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 if((marker->flag&MARKER_DISABLED)==0) | 529 if((marker->flag&MARKER_DISABLED)==0) |
530 context->num_tracks++; | 530 context->num_tracks++; |
531 } | 531 } |
532 | 532 |
533 track= track->next; | 533 track= track->next; |
534 } | 534 } |
535 | 535 |
536 if(context->num_tracks) { | 536 if(context->num_tracks) { |
537 int width, height; | 537 int width, height; |
538 | 538 |
539 » » BKE_movieclip_acquire_size(clip, user, &width, &height); | 539 » » BKE_movieclip_get_size(clip, user, &width, &height); |
540 | 540 |
541 /* create tracking data */ | 541 /* create tracking data */ |
542 context->track_context= MEM_callocN(sizeof(TrackContext)*context ->num_tracks, "tracking track_context"); | 542 context->track_context= MEM_callocN(sizeof(TrackContext)*context ->num_tracks, "tracking track_context"); |
543 | 543 |
544 track_context= context->track_context; | 544 track_context= context->track_context; |
545 track= tracking->tracks.first; | 545 track= tracking->tracks.first; |
546 while(track) { | 546 while(track) { |
547 if(TRACK_SELECTED(track) && (track->flag&TRACK_LOCKED)== 0) { | 547 if(TRACK_SELECTED(track) && (track->flag&TRACK_LOCKED)== 0) { |
548 MovieTrackingMarker *marker= BKE_tracking_get_ma rker(track, user->framenr); | 548 MovieTrackingMarker *marker= BKE_tracking_get_ma rker(track, user->framenr); |
549 | 549 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
640 char *rrgb= (char*)ibuf->rect + pixel*4; | 640 char *rrgb= (char*)ibuf->rect + pixel*4; |
641 | 641 |
642 if(track->flag&TRACK_DISABLE_RED) rrgb[0]= 0; | 642 if(track->flag&TRACK_DISABLE_RED) rrgb[0]= 0; |
643 if(track->flag&TRACK_DISABLE_GREEN) rrgb[1]= 0; | 643 if(track->flag&TRACK_DISABLE_GREEN) rrgb[1]= 0; |
644 if(track->flag&TRACK_DISABLE_BLUE) rrgb[2]= 0; | 644 if(track->flag&TRACK_DISABLE_BLUE) rrgb[2]= 0; |
645 } | 645 } |
646 } | 646 } |
647 } | 647 } |
648 } | 648 } |
649 | 649 |
650 static ImBuf *acquire_area_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTr ackingMarker *marker, | 650 static ImBuf *get_area_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTracki ngMarker *marker, |
651 float min[2], float max[2], int margin, int anchored, fl oat pos[2], int origin[2]) | 651 float min[2], float max[2], int margin, int anchored, fl oat pos[2], int origin[2]) |
652 { | 652 { |
653 ImBuf *tmpibuf; | 653 ImBuf *tmpibuf; |
654 int x, y; | 654 int x, y; |
655 int x1, y1, x2, y2, w, h; | 655 int x1, y1, x2, y2, w, h; |
656 float mpos[2]; | 656 float mpos[2]; |
657 | 657 |
658 copy_v2_v2(mpos, marker->pos); | 658 copy_v2_v2(mpos, marker->pos); |
659 if(anchored) | 659 if(anchored) |
660 add_v2_v2(mpos, track->offset); | 660 add_v2_v2(mpos, track->offset); |
(...skipping 24 matching lines...) Expand all Loading... | |
685 if(origin != NULL) { | 685 if(origin != NULL) { |
686 origin[0]= x1-margin; | 686 origin[0]= x1-margin; |
687 origin[1]= y1-margin; | 687 origin[1]= y1-margin; |
688 } | 688 } |
689 | 689 |
690 disable_imbuf_channels(tmpibuf, track); | 690 disable_imbuf_channels(tmpibuf, track); |
691 | 691 |
692 return tmpibuf; | 692 return tmpibuf; |
693 } | 693 } |
694 | 694 |
695 ImBuf *BKE_tracking_acquire_pattern_imbuf(ImBuf *ibuf, MovieTrackingTrack *track , MovieTrackingMarker *marker, | 695 ImBuf *BKE_tracking_get_pattern_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, Mo vieTrackingMarker *marker, |
696 int margin, int anchored, float pos[2], int origin[2]) | 696 int margin, int anchored, float pos[2], int origin[2]) |
697 { | 697 { |
698 » return acquire_area_imbuf(ibuf, track, marker, track->pat_min, track->pa t_max, margin, anchored, pos, origin); | 698 » return get_area_imbuf(ibuf, track, marker, track->pat_min, track->pat_ma x, margin, anchored, pos, origin); |
699 } | 699 } |
700 | 700 |
701 ImBuf *BKE_tracking_acquire_search_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker, | 701 ImBuf *BKE_tracking_get_search_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, Mov ieTrackingMarker *marker, |
702 int margin, int anchored, float pos[2], int origin[2]) | 702 int margin, int anchored, float pos[2], int origin[2]) |
703 { | 703 { |
704 » return acquire_area_imbuf(ibuf, track, marker, track->search_min, track- >search_max, margin, anchored, pos, origin); | 704 » return get_area_imbuf(ibuf, track, marker, track->search_min, track->sea rch_max, margin, anchored, pos, origin); |
705 } | 705 } |
706 | 706 |
707 #ifdef WITH_LIBMV | 707 #ifdef WITH_LIBMV |
708 static float *acquire_search_floatbuf(ImBuf *ibuf, MovieTrackingTrack *track, Mo vieTrackingMarker *marker, | 708 static float *get_search_floatbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieT rackingMarker *marker, |
709 int *width_r, int *height_r, float pos[2], int origin[2] ) | 709 int *width_r, int *height_r, float pos[2], int origin[2] ) |
710 { | 710 { |
711 ImBuf *tmpibuf; | 711 ImBuf *tmpibuf; |
712 float *pixels, *fp; | 712 float *pixels, *fp; |
713 int x, y, width, height; | 713 int x, y, width, height; |
714 | 714 |
715 width= (track->search_max[0]-track->search_min[0])*ibuf->x; | 715 width= (track->search_max[0]-track->search_min[0])*ibuf->x; |
716 height= (track->search_max[1]-track->search_min[1])*ibuf->y; | 716 height= (track->search_max[1]-track->search_min[1])*ibuf->y; |
717 | 717 |
718 » tmpibuf= BKE_tracking_acquire_search_imbuf(ibuf, track, marker, 0, 0, po s, origin); | 718 » tmpibuf= BKE_tracking_get_search_imbuf(ibuf, track, marker, 0, 0, pos, o rigin); |
719 disable_imbuf_channels(tmpibuf, track); | 719 disable_imbuf_channels(tmpibuf, track); |
720 | 720 |
721 *width_r= width; | 721 *width_r= width; |
722 *height_r= height; | 722 *height_r= height; |
723 | 723 |
724 fp= pixels= MEM_callocN(width*height*sizeof(float), "tracking floatBuf") ; | 724 fp= pixels= MEM_callocN(width*height*sizeof(float), "tracking floatBuf") ; |
725 for(y= 0; y<(int)height; y++) { | 725 for(y= 0; y<(int)height; y++) { |
726 for (x= 0; x<(int)width; x++) { | 726 for (x= 0; x<(int)width; x++) { |
727 int pixel= tmpibuf->x*y + x; | 727 int pixel= tmpibuf->x*y + x; |
728 | 728 |
729 if(tmpibuf->rect_float) { | 729 if(tmpibuf->rect_float) { |
730 float *rrgbf= ibuf->rect_float + pixel*4; | 730 float *rrgbf= ibuf->rect_float + pixel*4; |
brechtvl
2011/10/25 16:01:36
tmpibuf => ibuf
| |
731 | 731 |
732 *fp= (0.2126*rrgbf[0] + 0.7152*rrgbf[1] + 0.0722 *rrgbf[2])/255; | 732 *fp= (0.2126*rrgbf[0] + 0.7152*rrgbf[1] + 0.0722 *rrgbf[2])/255; |
brechtvl
2011/10/25 16:01:36
This division by 255 seems wrong.
| |
733 } else { | 733 } else { |
734 char *rrgb= (char*)tmpibuf->rect + pixel*4; | 734 char *rrgb= (char*)tmpibuf->rect + pixel*4; |
735 | 735 |
736 *fp= (0.2126*rrgb[0] + 0.7152*rrgb[1] + 0.0722*r rgb[2])/255; | 736 *fp= (0.2126*rrgb[0] + 0.7152*rrgb[1] + 0.0722*r rgb[2])/255; |
737 } | 737 } |
738 | 738 |
739 fp++; | 739 fp++; |
740 } | 740 } |
741 } | 741 } |
742 | 742 |
743 IMB_freeImBuf(tmpibuf); | 743 IMB_freeImBuf(tmpibuf); |
744 | 744 |
745 return pixels; | 745 return pixels; |
746 } | 746 } |
747 | 747 |
748 static unsigned char *acquire_search_bytebuf(ImBuf *ibuf, MovieTrackingTrack *tr ack, MovieTrackingMarker *marker, | 748 static unsigned char *get_search_bytebuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker, |
749 int *width_r, int *height_r, float pos[2], int origin[2] ) | 749 int *width_r, int *height_r, float pos[2], int origin[2] ) |
750 { | 750 { |
751 ImBuf *tmpibuf; | 751 ImBuf *tmpibuf; |
752 unsigned char *pixels, *fp; | 752 unsigned char *pixels, *fp; |
brechtvl
2011/10/25 16:01:36
Small nitpick, fp is usually used for floats, cp f
| |
753 int x, y, width, height; | 753 int x, y, width, height; |
754 | 754 |
755 width= (track->search_max[0]-track->search_min[0])*ibuf->x; | 755 width= (track->search_max[0]-track->search_min[0])*ibuf->x; |
756 height= (track->search_max[1]-track->search_min[1])*ibuf->y; | 756 height= (track->search_max[1]-track->search_min[1])*ibuf->y; |
757 | 757 |
758 » tmpibuf= BKE_tracking_acquire_search_imbuf(ibuf, track, marker, 0, 0, po s, origin); | 758 » tmpibuf= BKE_tracking_get_search_imbuf(ibuf, track, marker, 0, 0, pos, o rigin); |
759 disable_imbuf_channels(tmpibuf, track); | 759 disable_imbuf_channels(tmpibuf, track); |
760 | 760 |
761 *width_r= width; | 761 *width_r= width; |
762 *height_r= height; | 762 *height_r= height; |
763 | 763 |
764 fp= pixels= MEM_callocN(width*height*sizeof(unsigned char), "tracking by teBuf"); | 764 fp= pixels= MEM_callocN(width*height*sizeof(unsigned char), "tracking by teBuf"); |
765 for(y= 0; y<(int)height; y++) { | 765 for(y= 0; y<(int)height; y++) { |
766 for (x= 0; x<(int)width; x++) { | 766 for (x= 0; x<(int)width; x++) { |
767 int pixel= tmpibuf->x*y + x; | 767 int pixel= tmpibuf->x*y + x; |
768 | 768 |
769 if(tmpibuf->rect_float) { | 769 if(tmpibuf->rect_float) { |
770 float *rrgbf= ibuf->rect_float + pixel*4; | 770 float *rrgbf= ibuf->rect_float + pixel*4; |
brechtvl
2011/10/25 16:01:36
ibuf => tmpibuf
| |
771 | 771 |
772 *fp= (0.2126*rrgbf[0] + 0.7152*rrgbf[1] + 0.0722 *rrgbf[2]); | 772 *fp= (0.2126*rrgbf[0] + 0.7152*rrgbf[1] + 0.0722 *rrgbf[2]); |
brechtvl
2011/10/25 16:01:36
Missing scaling here, use FTOCHAR() here.
nazgul
2011/10/25 19:04:58
Right. Strange that still nobody noticed this. Doe
| |
773 } else { | 773 } else { |
774 char *rrgb= (char*)tmpibuf->rect + pixel*4; | 774 char *rrgb= (char*)tmpibuf->rect + pixel*4; |
775 | 775 |
776 *fp= (0.2126*rrgb[0] + 0.7152*rrgb[1] + 0.0722*r rgb[2]); | 776 *fp= (0.2126*rrgb[0] + 0.7152*rrgb[1] + 0.0722*r rgb[2]); |
777 } | 777 } |
778 | 778 |
779 fp++; | 779 fp++; |
780 } | 780 } |
781 } | 781 } |
782 | 782 |
783 IMB_freeImBuf(tmpibuf); | 783 IMB_freeImBuf(tmpibuf); |
784 | 784 |
785 return pixels; | 785 return pixels; |
786 } | 786 } |
787 | 787 |
788 static ImBuf *acquire_frame_ibuf(MovieTrackingContext *context, int framenr) | 788 static ImBuf *get_frame_ibuf(MovieTrackingContext *context, int framenr) |
789 { | 789 { |
790 ImBuf *ibuf; | 790 ImBuf *ibuf; |
791 int framenr_old= context->user.framenr; | 791 int framenr_old= context->user.framenr; |
792 | 792 |
793 context->user.framenr= framenr; | 793 context->user.framenr= framenr; |
794 | 794 |
795 » ibuf= BKE_movieclip_acquire_ibuf_flag(context->clip, &context->user, 0); | 795 » ibuf= BKE_movieclip_get_ibuf_flag(context->clip, &context->user, 0); |
796 | 796 |
797 context->user.framenr= framenr_old; | 797 context->user.framenr= framenr_old; |
798 | 798 |
799 return ibuf; | 799 return ibuf; |
800 } | 800 } |
801 | 801 |
802 static ImBuf *acquire_keyframed_ibuf(MovieTrackingContext *context, MovieTrackin gTrack *track, | 802 static ImBuf *get_keyframed_ibuf(MovieTrackingContext *context, MovieTrackingTra ck *track, |
803 MovieTrackingMarker *marker, MovieTrackingMarker **marke r_keyed) | 803 MovieTrackingMarker *marker, MovieTrackingMarker **marke r_keyed) |
804 { | 804 { |
805 int framenr= marker->framenr; | 805 int framenr= marker->framenr; |
806 int a= marker-track->markers; | 806 int a= marker-track->markers; |
807 | 807 |
808 *marker_keyed= marker; | 808 *marker_keyed= marker; |
809 | 809 |
810 while(a>=0 && a<track->markersnr) { | 810 while(a>=0 && a<track->markersnr) { |
811 if((track->markers[a].flag&MARKER_TRACKED)==0) { | 811 if((track->markers[a].flag&MARKER_TRACKED)==0) { |
812 framenr= track->markers[a].framenr; | 812 framenr= track->markers[a].framenr; |
813 *marker_keyed= &track->markers[a]; | 813 *marker_keyed= &track->markers[a]; |
814 break; | 814 break; |
815 } | 815 } |
816 | 816 |
817 if(context->backwards) a++; | 817 if(context->backwards) a++; |
818 else a--; | 818 else a--; |
819 } | 819 } |
820 | 820 |
821 » return acquire_frame_ibuf(context, framenr); | 821 » return get_frame_ibuf(context, framenr); |
822 } | 822 } |
823 | 823 |
824 static ImBuf *acquire_adjust_ibuf(MovieTrackingContext *context, MovieTrackingTr ack *track, MovieTrackingMarker *marker, | 824 static ImBuf *get_adjust_ibuf(MovieTrackingContext *context, MovieTrackingTrack *track, MovieTrackingMarker *marker, |
825 int curfra, MovieTrackingMarker **marker_keyed) | 825 int curfra, MovieTrackingMarker **marker_keyed) |
826 { | 826 { |
827 ImBuf *ibuf= NULL; | 827 ImBuf *ibuf= NULL; |
828 | 828 |
829 if(context->settings.adjframes == 0) { | 829 if(context->settings.adjframes == 0) { |
830 » » ibuf= acquire_keyframed_ibuf(context, track, marker, marker_keye d); | 830 » » ibuf= get_keyframed_ibuf(context, track, marker, marker_keyed); |
831 } else { | 831 } else { |
832 » » ibuf= acquire_frame_ibuf(context, curfra); | 832 » » ibuf= get_frame_ibuf(context, curfra); |
833 | 833 |
834 /* use current marker as keyframed position */ | 834 /* use current marker as keyframed position */ |
835 *marker_keyed= marker; | 835 *marker_keyed= marker; |
836 } | 836 } |
837 | 837 |
838 return ibuf; | 838 return ibuf; |
839 } | 839 } |
840 | 840 |
841 static void acquire_warped(TrackContext *track_context, int x, int y, int width, unsigned char *image) | 841 static void get_warped(TrackContext *track_context, int x, int y, int width, uns igned char *image) |
842 { | 842 { |
843 int i, j; | 843 int i, j; |
844 | 844 |
845 for(i=0; i<track_context->patsize; i++) { | 845 for(i=0; i<track_context->patsize; i++) { |
846 for(j=0; j<track_context->patsize; j++) { | 846 for(j=0; j<track_context->patsize; j++) { |
847 track_context->warped[i*track_context->patsize+j]= | 847 track_context->warped[i*track_context->patsize+j]= |
848 image[(y+i-track_context->patsize/2)*wid th+x+j-track_context->patsize/2]; | 848 image[(y+i-track_context->patsize/2)*wid th+x+j-track_context->patsize/2]; |
849 } | 849 } |
850 } | 850 } |
851 } | 851 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
952 int curfra= context->user.framenr; | 952 int curfra= context->user.framenr; |
953 int a, ok= 0; | 953 int a, ok= 0; |
954 | 954 |
955 /* nothing to track, avoid unneeded frames reading to save time and memo ry */ | 955 /* nothing to track, avoid unneeded frames reading to save time and memo ry */ |
956 if(!context->num_tracks) | 956 if(!context->num_tracks) |
957 return 0; | 957 return 0; |
958 | 958 |
959 if(context->backwards) context->user.framenr--; | 959 if(context->backwards) context->user.framenr--; |
960 else context->user.framenr++; | 960 else context->user.framenr++; |
961 | 961 |
962 » ibuf_new= BKE_movieclip_acquire_ibuf_flag(context->clip, &context->user, 0); | 962 » ibuf_new= BKE_movieclip_get_ibuf_flag(context->clip, &context->user, 0); |
963 if(!ibuf_new) | 963 if(!ibuf_new) |
964 return 0; | 964 return 0; |
965 | 965 |
966 #pragma omp parallel for private(a) shared(ibuf_new, ok) if(context->num _tracks>1) | 966 #pragma omp parallel for private(a) shared(ibuf_new, ok) if(context->num _tracks>1) |
967 for(a= 0; a<context->num_tracks; a++) { | 967 for(a= 0; a<context->num_tracks; a++) { |
968 TrackContext *track_context= &context->track_context[a]; | 968 TrackContext *track_context= &context->track_context[a]; |
969 MovieTrackingTrack *track= track_context->track; | 969 MovieTrackingTrack *track= track_context->track; |
970 MovieTrackingMarker *marker= BKE_tracking_get_marker(track, curf ra); | 970 MovieTrackingMarker *marker= BKE_tracking_get_marker(track, curf ra); |
971 | 971 |
972 if(marker && (marker->flag&MARKER_DISABLED)==0 && marker->framen r==curfra) { | 972 if(marker && (marker->flag&MARKER_DISABLED)==0 && marker->framen r==curfra) { |
(...skipping 18 matching lines...) Expand all Loading... | |
991 if(marker->pos[0]<margin[0] || marker->pos[0]>1.f-margin [0] || | 991 if(marker->pos[0]<margin[0] || marker->pos[0]>1.f-margin [0] || |
992 marker->pos[1]<margin[1] || marker->pos[1]>1.f-margin [1]) { | 992 marker->pos[1]<margin[1] || marker->pos[1]>1.f-margin [1]) { |
993 onbound= 1; | 993 onbound= 1; |
994 } | 994 } |
995 else if(context->settings.tracker==TRACKER_KLT) { | 995 else if(context->settings.tracker==TRACKER_KLT) { |
996 int wndx, wndy; | 996 int wndx, wndy; |
997 float *patch_new; | 997 float *patch_new; |
998 | 998 |
999 if(need_readjust) { | 999 if(need_readjust) { |
1000 /* calculate patch for keyframed positio n */ | 1000 /* calculate patch for keyframed positio n */ |
1001 » » » » » ibuf= acquire_adjust_ibuf(context, track , marker, curfra, &marker_keyed); | 1001 » » » » » ibuf= get_adjust_ibuf(context, track, ma rker, curfra, &marker_keyed); |
1002 | 1002 |
1003 if(track_context->patch) | 1003 if(track_context->patch) |
1004 MEM_freeN(track_context->patch); | 1004 MEM_freeN(track_context->patch); |
1005 | 1005 |
1006 » » » » » track_context->patch= acquire_search_flo atbuf(ibuf, track, marker_keyed, &width, &height, pos, origin); | 1006 » » » » » track_context->patch= get_search_floatbu f(ibuf, track, marker_keyed, &width, &height, pos, origin); |
1007 | 1007 |
1008 IMB_freeImBuf(ibuf); | 1008 IMB_freeImBuf(ibuf); |
1009 } | 1009 } |
1010 | 1010 |
1011 » » » » patch_new= acquire_search_floatbuf(ibuf_new, tra ck, marker, &width, &height, pos, origin); | 1011 » » » » patch_new= get_search_floatbuf(ibuf_new, track, marker, &width, &height, pos, origin); |
1012 | 1012 |
1013 x1= pos[0]; | 1013 x1= pos[0]; |
1014 y1= pos[1]; | 1014 y1= pos[1]; |
1015 | 1015 |
1016 x2= x1; | 1016 x2= x1; |
1017 y2= y1; | 1017 y2= y1; |
1018 | 1018 |
1019 wndx= (int)((track->pat_max[0]-track->pat_min[0] )*ibuf_new->x)/2; | 1019 wndx= (int)((track->pat_max[0]-track->pat_min[0] )*ibuf_new->x)/2; |
1020 wndy= (int)((track->pat_max[1]-track->pat_min[1] )*ibuf_new->y)/2; | 1020 wndy= (int)((track->pat_max[1]-track->pat_min[1] )*ibuf_new->y)/2; |
1021 | 1021 |
1022 tracked= libmv_regionTrackerTrack(track_context- >region_tracker, track_context->patch, patch_new, | 1022 tracked= libmv_regionTrackerTrack(track_context- >region_tracker, track_context->patch, patch_new, |
1023 width, height, MAX2(wndx , wndy), x1, y1, &x2, &y2); | 1023 width, height, MAX2(wndx , wndy), x1, y1, &x2, &y2); |
1024 | 1024 |
1025 MEM_freeN(patch_new); | 1025 MEM_freeN(patch_new); |
1026 } | 1026 } |
1027 else if(context->settings.tracker==TRACKER_SAD) { | 1027 else if(context->settings.tracker==TRACKER_SAD) { |
1028 unsigned char *image_new; | 1028 unsigned char *image_new; |
1029 float corr; | 1029 float corr; |
1030 float warp[3][2]={{0}}; | 1030 float warp[3][2]={{0}}; |
1031 | 1031 |
1032 if(need_readjust) { | 1032 if(need_readjust) { |
1033 unsigned char *image; | 1033 unsigned char *image; |
1034 | 1034 |
1035 /* calculate pattern for keyframed posit ion */ | 1035 /* calculate pattern for keyframed posit ion */ |
1036 » » » » » ibuf= acquire_adjust_ibuf(context, track , marker, curfra, &marker_keyed); | 1036 » » » » » ibuf= get_adjust_ibuf(context, track, ma rker, curfra, &marker_keyed); |
1037 | 1037 |
1038 » » » » » image= acquire_search_bytebuf(ibuf, trac k, marker_keyed, &width, &height, pos, origin); | 1038 » » » » » image= get_search_bytebuf(ibuf, track, m arker_keyed, &width, &height, pos, origin); |
1039 | 1039 |
1040 memset(warp, 0, sizeof(warp)); | 1040 memset(warp, 0, sizeof(warp)); |
1041 warp[0][0]= 1; | 1041 warp[0][0]= 1; |
1042 warp[1][1]= 1; | 1042 warp[1][1]= 1; |
1043 warp[2][0]= pos[0]; | 1043 warp[2][0]= pos[0]; |
1044 warp[2][1]= pos[1]; | 1044 warp[2][1]= pos[1]; |
1045 | 1045 |
1046 /* pattern size is hardcoded to 16x16px in libmv */ | 1046 /* pattern size is hardcoded to 16x16px in libmv */ |
1047 track_context->patsize= 16; | 1047 track_context->patsize= 16; |
1048 | 1048 |
1049 if(!track_context->pattern) | 1049 if(!track_context->pattern) |
1050 track_context->pattern= MEM_call ocN(sizeof(unsigned char)*track_context->patsize*track_context->patsize, "trackk ing pattern"); | 1050 track_context->pattern= MEM_call ocN(sizeof(unsigned char)*track_context->patsize*track_context->patsize, "trackk ing pattern"); |
1051 | 1051 |
1052 libmv_SADSamplePattern(image, width, war p, track_context->pattern); | 1052 libmv_SADSamplePattern(image, width, war p, track_context->pattern); |
1053 | 1053 |
1054 MEM_freeN(image); | 1054 MEM_freeN(image); |
1055 IMB_freeImBuf(ibuf); | 1055 IMB_freeImBuf(ibuf); |
1056 } | 1056 } |
1057 | 1057 |
1058 » » » » image_new= acquire_search_bytebuf(ibuf_new, trac k, marker, &width, &height, pos, origin); | 1058 » » » » image_new= get_search_bytebuf(ibuf_new, track, m arker, &width, &height, pos, origin); |
1059 | 1059 |
1060 if(track_context->warped==NULL) { | 1060 if(track_context->warped==NULL) { |
1061 unsigned char *image_old; | 1061 unsigned char *image_old; |
1062 | 1062 |
1063 » » » » » ibuf= acquire_frame_ibuf(context, curfra ); | 1063 » » » » » ibuf= get_frame_ibuf(context, curfra); |
1064 | 1064 |
1065 if(track_context->warped==NULL) | 1065 if(track_context->warped==NULL) |
1066 track_context->warped= MEM_callo cN(sizeof(unsigned char)*track_context->patsize*track_context->patsize, "trackki ng warped"); | 1066 track_context->warped= MEM_callo cN(sizeof(unsigned char)*track_context->patsize*track_context->patsize, "trackki ng warped"); |
1067 | 1067 |
1068 » » » » » image_old= acquire_search_bytebuf(ibuf, track, marker, &width, &height, pos, origin); | 1068 » » » » » image_old= get_search_bytebuf(ibuf, trac k, marker, &width, &height, pos, origin); |
1069 » » » » » acquire_warped(track_context, pos[0], po s[1], width, image_old); | 1069 » » » » » get_warped(track_context, pos[0], pos[1] , width, image_old); |
1070 IMB_freeImBuf(ibuf); | 1070 IMB_freeImBuf(ibuf); |
1071 MEM_freeN(image_old); | 1071 MEM_freeN(image_old); |
1072 } | 1072 } |
1073 | 1073 |
1074 memset(warp, 0, sizeof(warp)); | 1074 memset(warp, 0, sizeof(warp)); |
1075 warp[0][0]= 1; | 1075 warp[0][0]= 1; |
1076 warp[1][1]= 1; | 1076 warp[1][1]= 1; |
1077 warp[2][0]= pos[0]; | 1077 warp[2][0]= pos[0]; |
1078 warp[2][1]= pos[1]; | 1078 warp[2][1]= pos[1]; |
1079 | 1079 |
1080 corr= libmv_SADTrackerTrack(track_context->patte rn, track_context->warped, image_new, width, width, height, warp); | 1080 corr= libmv_SADTrackerTrack(track_context->patte rn, track_context->warped, image_new, width, width, height, warp); |
1081 | 1081 |
1082 x2= warp[2][0]; | 1082 x2= warp[2][0]; |
1083 y2= warp[2][1]; | 1083 y2= warp[2][1]; |
1084 | 1084 |
1085 tracked= corr>=context->settings.corr; | 1085 tracked= corr>=context->settings.corr; |
1086 | 1086 |
1087 if(tracked) | 1087 if(tracked) |
1088 » » » » » acquire_warped(track_context, x2, y2, wi dth, image_new); | 1088 » » » » » get_warped(track_context, x2, y2, width, image_new); |
1089 | 1089 |
1090 MEM_freeN(image_new); | 1090 MEM_freeN(image_new); |
1091 } | 1091 } |
1092 | 1092 |
1093 if(tracked || !context->disable_failed) { | 1093 if(tracked || !context->disable_failed) { |
1094 if(context->first_time) { | 1094 if(context->first_time) { |
1095 int prevframe; | 1095 int prevframe; |
1096 | 1096 |
1097 if(context->backwards) prevframe= curfra +1; | 1097 if(context->backwards) prevframe= curfra +1; |
1098 else prevframe= curfra-1; | 1098 else prevframe= curfra-1; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1177 marker->pos[0]*width, ma rker->pos[1]*height); | 1177 marker->pos[0]*width, ma rker->pos[1]*height); |
1178 } | 1178 } |
1179 | 1179 |
1180 track= track->next; | 1180 track= track->next; |
1181 tracknr++; | 1181 tracknr++; |
1182 } | 1182 } |
1183 | 1183 |
1184 return tracks; | 1184 return tracks; |
1185 } | 1185 } |
1186 | 1186 |
1187 static int retrive_libmv_reconstruct(MovieTracking *tracking, struct libmv_Recon struction *libmv_reconstruction) | 1187 static int retrive_libmv_reconstruct(MovieTracking *tracking, struct libmv_Recon struction *libmv_reconstruction) |
brechtvl
2011/10/25 20:03:01
retrive => retrieve
nazgul
2011/10/26 07:47:48
Always typing this work incorrectly =\
| |
1188 { | 1188 { |
1189 int tracknr= 0; | 1189 int tracknr= 0; |
1190 int sfra= INT_MAX, efra= INT_MIN, a, origin_set= 0; | 1190 int sfra= INT_MAX, efra= INT_MIN, a, origin_set= 0; |
1191 MovieTrackingTrack *track; | 1191 MovieTrackingTrack *track; |
1192 MovieTrackingReconstruction *reconstruction= &tracking->reconstruction; | 1192 MovieTrackingReconstruction *reconstruction= &tracking->reconstruction; |
1193 MovieReconstructedCamera *reconstructed; | 1193 MovieReconstructedCamera *reconstructed; |
1194 float origin[3]= {0.0f, 0.f, 0.0f}; | 1194 float origin[3]= {0.0f, 0.f, 0.0f}; |
1195 int ok= 1; | 1195 int ok= 1; |
1196 | 1196 |
1197 track= tracking->tracks.first; | 1197 track= tracking->tracks.first; |
(...skipping 29 matching lines...) Expand all Loading... | |
1227 reconstruction->camnr= 0; | 1227 reconstruction->camnr= 0; |
1228 reconstruction->cameras= NULL; | 1228 reconstruction->cameras= NULL; |
1229 reconstructed= MEM_callocN((efra-sfra+1)*sizeof(MovieReconstructedCamera ), "temp reconstructed camera"); | 1229 reconstructed= MEM_callocN((efra-sfra+1)*sizeof(MovieReconstructedCamera ), "temp reconstructed camera"); |
1230 | 1230 |
1231 for(a= sfra; a<=efra; a++) { | 1231 for(a= sfra; a<=efra; a++) { |
1232 double matd[4][4]; | 1232 double matd[4][4]; |
1233 | 1233 |
1234 if(libmv_reporojectionCameraForImage(libmv_reconstruction, a, ma td)) { | 1234 if(libmv_reporojectionCameraForImage(libmv_reconstruction, a, ma td)) { |
1235 int i, j; | 1235 int i, j; |
1236 float mat[4][4]; | 1236 float mat[4][4]; |
1237 float error= libmv_reporojectionErrorForImage(libmv_reco nstruction, a); | |
1237 | 1238 |
1238 for(i=0; i<4; i++) | 1239 for(i=0; i<4; i++) |
1239 for(j= 0; j<4; j++) | 1240 for(j= 0; j<4; j++) |
1240 mat[i][j]= matd[i][j]; | 1241 mat[i][j]= matd[i][j]; |
1241 | 1242 |
1242 if(!origin_set) { | 1243 if(!origin_set) { |
1243 copy_v3_v3(origin, mat[3]); | 1244 copy_v3_v3(origin, mat[3]); |
1244 origin_set= 1; | 1245 origin_set= 1; |
1245 } | 1246 } |
1246 | 1247 |
1247 if(origin_set) | 1248 if(origin_set) |
1248 sub_v3_v3(mat[3], origin); | 1249 sub_v3_v3(mat[3], origin); |
1249 | 1250 |
1250 copy_m4_m4(reconstructed[reconstruction->camnr].mat, mat ); | 1251 copy_m4_m4(reconstructed[reconstruction->camnr].mat, mat ); |
1251 reconstructed[reconstruction->camnr].framenr= a; | 1252 reconstructed[reconstruction->camnr].framenr= a; |
1253 reconstructed[reconstruction->camnr].error= error; | |
1252 reconstruction->camnr++; | 1254 reconstruction->camnr++; |
1253 } else { | 1255 } else { |
1254 ok= 0; | 1256 ok= 0; |
1255 printf("No camera for frame %d\n", a); | 1257 printf("No camera for frame %d\n", a); |
1256 } | 1258 } |
1257 } | 1259 } |
1258 | 1260 |
1259 if(reconstruction->camnr) { | 1261 if(reconstruction->camnr) { |
1260 reconstruction->cameras= MEM_callocN(reconstruction->camnr*sizeo f(MovieReconstructedCamera), "reconstructed camera"); | 1262 reconstruction->cameras= MEM_callocN(reconstruction->camnr*sizeo f(MovieReconstructedCamera), "reconstructed camera"); |
1261 memcpy(reconstruction->cameras, reconstructed, reconstruction->c amnr*sizeof(MovieReconstructedCamera)); | 1263 memcpy(reconstruction->cameras, reconstructed, reconstruction->c amnr*sizeof(MovieReconstructedCamera)); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1488 | 1490 |
1489 libmv_InvertIntrinsics(camera->focal, camera->principal[0], camera->prin cipal[1] * aspy, | 1491 libmv_InvertIntrinsics(camera->focal, camera->principal[0], camera->prin cipal[1] * aspy, |
1490 camera->k1, camera->k2, camera->k3, x, y, &x, &y ); | 1492 camera->k1, camera->k2, camera->k3, x, y, &x, &y ); |
1491 | 1493 |
1492 nco[0]= x * camera->focal + camera->principal[0]; | 1494 nco[0]= x * camera->focal + camera->principal[0]; |
1493 nco[1]= y * camera->focal + camera->principal[1] * aspy; | 1495 nco[1]= y * camera->focal + camera->principal[1] * aspy; |
1494 #endif | 1496 #endif |
1495 } | 1497 } |
1496 | 1498 |
1497 #ifdef WITH_LIBMV | 1499 #ifdef WITH_LIBMV |
1498 /* flips upside-down */ | 1500 static unsigned char *get_ucharbuf(ImBuf *ibuf) |
brechtvl
2011/10/25 16:01:36
The code here and in get_search_bytebuf could be d
nazgul
2011/10/25 19:04:58
Right.
| |
1499 static unsigned char *acquire_ucharbuf(ImBuf *ibuf) | |
1500 { | 1501 { |
1501 int x, y; | 1502 int x, y; |
1502 unsigned char *pixels, *fp; | 1503 unsigned char *pixels, *fp; |
1503 | 1504 |
1504 fp= pixels= MEM_callocN(ibuf->x*ibuf->y*sizeof(unsigned char), "tracking ucharBuf"); | 1505 fp= pixels= MEM_callocN(ibuf->x*ibuf->y*sizeof(unsigned char), "tracking ucharBuf"); |
1505 for(y= 0; y<ibuf->y; y++) { | 1506 for(y= 0; y<ibuf->y; y++) { |
1506 for (x= 0; x<ibuf->x; x++) { | 1507 for (x= 0; x<ibuf->x; x++) { |
1507 » » » int pixel= ibuf->x*(ibuf->y-y-1) + x; | 1508 » » » int pixel= ibuf->x*y + x; |
1508 | 1509 |
1509 if(ibuf->rect_float) { | 1510 if(ibuf->rect_float) { |
1510 float *rrgbf= ibuf->rect_float + pixel*4; | 1511 float *rrgbf= ibuf->rect_float + pixel*4; |
1511 | 1512 |
1512 » » » » //*fp= 0.2126f*rrgbf[0] + 0.7152f*rrgbf[1] + 0.0 722f*rrgbf[2]; | 1513 » » » » *fp= 0.2126f*rrgbf[0] + 0.7152f*rrgbf[1] + 0.072 2f*rrgbf[2]; |
1513 » » » » *fp= (11*rrgbf[0]+16*rrgbf[1]+5*rrgbf[2])/32; | |
1514 } else { | 1514 } else { |
1515 char *rrgb= (char*)ibuf->rect + pixel*4; | 1515 char *rrgb= (char*)ibuf->rect + pixel*4; |
1516 | 1516 |
1517 » » » » //*fp= 0.2126f*rrgb[0] + 0.7152f*rrgb[1] + 0.072 2f*rrgb[2]; | 1517 » » » » *fp= 0.2126f*rrgb[0] + 0.7152f*rrgb[1] + 0.0722f *rrgb[2]; |
1518 » » » » *fp= (11*rrgb[0]+16*rrgb[1]+5*rrgb[2])/32; | |
1519 } | 1518 } |
1520 | 1519 |
1521 fp++; | 1520 fp++; |
1522 } | 1521 } |
1523 } | 1522 } |
1524 | 1523 |
1525 return pixels; | 1524 return pixels; |
1526 } | 1525 } |
1527 #endif | 1526 #endif |
1528 | 1527 |
1529 void BKE_tracking_detect(MovieTracking *tracking, ImBuf *ibuf, int framenr, int margin, int min_trackness, int count, int min_distance, int fast) | 1528 static int point_in_stroke(bGPDstroke *stroke, float x, float y) |
1529 { | |
1530 » int i, prev; | |
1531 » int count= 0; | |
1532 » bGPDspoint *points= stroke->points; | |
1533 | |
1534 » prev= stroke->totpoints-1; | |
1535 | |
1536 » for(i= 0; i<stroke->totpoints; i++) { | |
1537 » » if((points[i].y<y && points[prev].y>=y) || (points[prev].y<y && points[i].y>=y)) { | |
1538 » » » float fac= (y-points[i].y)/(points[prev].y-points[i].y); | |
1539 | |
1540 » » » if (points[i].x+fac*(points[prev].x-points[i].x)<x) | |
1541 » » » » count++; | |
1542 » » } | |
1543 | |
1544 » » prev= i; | |
1545 » } | |
1546 | |
1547 » return count%2; | |
1548 } | |
1549 | |
1550 static int point_in_layer(bGPDlayer *layer, float x, float y) | |
1551 { | |
1552 » bGPDframe *frame= layer->frames.first; | |
1553 | |
1554 » while(frame) { | |
1555 » » bGPDstroke *stroke= frame->strokes.first; | |
1556 » » while(stroke) { | |
1557 » » » if(point_in_stroke(stroke, x, y)) | |
1558 » » » » return 1; | |
1559 | |
1560 » » » stroke= stroke->next; | |
1561 » » } | |
1562 » » frame= frame->next; | |
1563 » } | |
1564 | |
1565 » return 0; | |
1566 } | |
1567 | |
1568 static void retrive_libmv_features(MovieTracking *tracking, struct libmv_Feature s *features, | |
brechtvl
2011/10/25 20:03:01
retrive => retrieve
| |
1569 » » » int framenr, int width, int height, bGPDlayer *layer) | |
1530 { | 1570 { |
1531 #ifdef WITH_LIBMV | 1571 #ifdef WITH_LIBMV |
1532 struct libmv_Features *features; | |
1533 unsigned char *pixels= acquire_ucharbuf(ibuf); | |
1534 int a; | 1572 int a; |
1535 | |
1536 if(fast)· | |
1537 features= libmv_detectFeaturesFAST(pixels, ibuf->x, ibuf->y, ibu f->x, margin, min_trackness, min_distance); | |
1538 else | |
1539 features= libmv_detectFeaturesMORAVEC(pixels, ibuf->x, ibuf->y, ibuf->x, margin, count, min_distance); | |
1540 | |
1541 MEM_freeN(pixels); | |
1542 | 1573 |
1543 a= libmv_countFeatures(features); | 1574 a= libmv_countFeatures(features); |
1544 while(a--) { | 1575 while(a--) { |
1545 MovieTrackingTrack *track; | 1576 MovieTrackingTrack *track; |
1546 double x, y, size, score; | 1577 double x, y, size, score; |
1578 int ok= 1; | |
1579 float xu, yu; | |
1547 | 1580 |
1548 libmv_getFeature(features, a, &x, &y, &score, &size); | 1581 libmv_getFeature(features, a, &x, &y, &score, &size); |
1549 | 1582 |
1550 » » track= BKE_tracking_add_track(tracking, x/ibuf->x, 1.0f-(y/ibuf- >y), framenr, ibuf->x, ibuf->y); | 1583 » » xu= x/width; |
1551 » » track->flag|= SELECT; | 1584 » » yu= y/height; |
1552 » » track->pat_flag|= SELECT; | 1585 |
1553 » » track->search_flag|= SELECT; | 1586 » » if(layer) |
1554 » } | 1587 » » » ok= point_in_layer(layer, xu, yu); |
1588 | |
1589 » » if(ok) { | |
1590 » » » track= BKE_tracking_add_track(tracking, xu, yu, framenr, width, height); | |
1591 » » » track->flag|= SELECT; | |
1592 » » » track->pat_flag|= SELECT; | |
1593 » » » track->search_flag|= SELECT; | |
1594 » » } | |
1595 » } | |
1596 #endif | |
1597 } | |
1598 | |
1599 void BKE_tracking_detect_fast(MovieTracking *tracking, ImBuf *ibuf, | |
1600 » » » int framenr, int margin, int min_trackness, int min_dist ance, bGPDlayer *layer) | |
1601 { | |
1602 #ifdef WITH_LIBMV | |
1603 » struct libmv_Features *features; | |
1604 » unsigned char *pixels= get_ucharbuf(ibuf); | |
1605 | |
1606 » features= libmv_detectFeaturesFAST(pixels, ibuf->x, ibuf->y, ibuf->x, ma rgin, min_trackness, min_distance); | |
1607 | |
1608 » MEM_freeN(pixels); | |
1609 | |
1610 » retrive_libmv_features(tracking, features, framenr, ibuf->x, ibuf->y, la yer); | |
1611 | |
1612 » libmv_destroyFeatures(features); | |
1613 #endif | |
1614 } | |
1615 | |
1616 void BKE_tracking_detect_moravec(MovieTracking *tracking, ImBuf *ibuf, | |
1617 » » » int framenr, int margin, int count, int min_distance, bG PDlayer *layer) | |
1618 { | |
1619 #ifdef WITH_LIBMV | |
1620 » struct libmv_Features *features; | |
1621 » unsigned char *pixels= get_ucharbuf(ibuf); | |
1622 | |
1623 » features= libmv_detectFeaturesMORAVEC(pixels, ibuf->x, ibuf->y, ibuf->x, margin, count, min_distance); | |
1624 | |
1625 » MEM_freeN(pixels); | |
1626 | |
1627 » retrive_libmv_features(tracking, features, framenr, ibuf->x, ibuf->y, la yer); | |
1555 | 1628 |
1556 libmv_destroyFeatures(features); | 1629 libmv_destroyFeatures(features); |
1557 #endif | 1630 #endif |
1558 } | 1631 } |
1559 | 1632 |
1560 MovieTrackingTrack *BKE_tracking_indexed_bundle(MovieTracking *tracking, int bun dlenr) | 1633 MovieTrackingTrack *BKE_tracking_indexed_bundle(MovieTracking *tracking, int bun dlenr) |
1561 { | 1634 { |
1562 MovieTrackingTrack *track= tracking->tracks.first; | 1635 MovieTrackingTrack *track= tracking->tracks.first; |
1563 int cur= 1; | 1636 int cur= 1; |
1564 | 1637 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1606 static void calculate_stabdata(MovieTracking *tracking, int framenr, float width , float height, | 1679 static void calculate_stabdata(MovieTracking *tracking, int framenr, float width , float height, |
1607 float firstmedian[2], float median[2], float loc[2], flo at *scale, float *angle) | 1680 float firstmedian[2], float median[2], float loc[2], flo at *scale, float *angle) |
1608 { | 1681 { |
1609 MovieTrackingStabilization *stab= &tracking->stabilization; | 1682 MovieTrackingStabilization *stab= &tracking->stabilization; |
1610 | 1683 |
1611 *scale= (stab->scale-1.f)*stab->scaleinf+1.f; | 1684 *scale= (stab->scale-1.f)*stab->scaleinf+1.f; |
1612 *angle= 0.f; | 1685 *angle= 0.f; |
1613 | 1686 |
1614 loc[0]= (firstmedian[0]-median[0])*width*(*scale); | 1687 loc[0]= (firstmedian[0]-median[0])*width*(*scale); |
1615 loc[1]= (firstmedian[1]-median[1])*height*(*scale); | 1688 loc[1]= (firstmedian[1]-median[1])*height*(*scale); |
1616 | |
1617 loc[0]-= (firstmedian[0]*(*scale)-firstmedian[0])*width; | |
1618 loc[1]-= (firstmedian[1]*(*scale)-firstmedian[1])*height; | |
1619 | 1689 |
1620 mul_v2_fl(loc, stab->locinf); | 1690 mul_v2_fl(loc, stab->locinf); |
1621 | 1691 |
1622 if(stab->rot_track && stab->rotinf) { | 1692 if(stab->rot_track && stab->rotinf) { |
1623 MovieTrackingMarker *marker; | 1693 MovieTrackingMarker *marker; |
1624 float a[2], b[2]; | 1694 float a[2], b[2]; |
1625 float x0= (float)width/2.f, y0= (float)height/2.f; | 1695 float x0= (float)width/2.f, y0= (float)height/2.f; |
1626 float x= median[0]*width, y= median[1]*height; | 1696 float x= median[0]*width, y= median[1]*height; |
1627 | 1697 |
1628 marker= BKE_tracking_get_marker(stab->rot_track, 1); | 1698 marker= BKE_tracking_get_marker(stab->rot_track, 1); |
1629 sub_v2_v2v2(a, marker->pos, firstmedian); | 1699 sub_v2_v2v2(a, marker->pos, firstmedian); |
1630 a[0]*= width; | 1700 a[0]*= width; |
1631 a[1]*= height; | 1701 a[1]*= height; |
1632 | 1702 |
1633 marker= BKE_tracking_get_marker(stab->rot_track, framenr); | 1703 marker= BKE_tracking_get_marker(stab->rot_track, framenr); |
1634 sub_v2_v2v2(b, marker->pos, median); | 1704 sub_v2_v2v2(b, marker->pos, median); |
1635 b[0]*= width; | 1705 b[0]*= width; |
1636 b[1]*= height; | 1706 b[1]*= height; |
1637 | 1707 |
1638 *angle= -atan2(a[0]*b[1]-a[1]*b[0], a[0]*b[0]+a[1]*b[1]); | 1708 *angle= -atan2(a[0]*b[1]-a[1]*b[0], a[0]*b[0]+a[1]*b[1]); |
1639 *angle*= stab->rotinf; | 1709 *angle*= stab->rotinf; |
1640 | 1710 |
1641 /* convert to rotation around image center */ | 1711 /* convert to rotation around image center */ |
1642 » » loc[0]-= (x0 + (x-x0)*cos(*angle)-(y-y0)*sin(*angle) - x); | 1712 » » loc[0]-= (x0 + (x-x0)*cos(*angle)-(y-y0)*sin(*angle) - x)*(*scal e); |
1643 » » loc[1]-= (y0 + (x-x0)*sin(*angle)+(y-y0)*cos(*angle) - y); | 1713 » » loc[1]-= (y0 + (x-x0)*sin(*angle)+(y-y0)*cos(*angle) - y)*(*scal e); |
1644 } | 1714 } |
1645 } | 1715 } |
1646 | 1716 |
1647 static float stabilization_auto_scale_factor(MovieTracking *tracking, int width, int height) | 1717 static float stabilization_auto_scale_factor(MovieTracking *tracking, int width, int height) |
1648 { | 1718 { |
1649 float firstmedian[2]; | 1719 float firstmedian[2]; |
1650 MovieTrackingStabilization *stab= &tracking->stabilization; | 1720 MovieTrackingStabilization *stab= &tracking->stabilization; |
1651 | 1721 |
1652 if(stab->ok) | 1722 if(stab->ok) |
1653 return stab->scale; | 1723 return stab->scale; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1825 return ibuf; | 1895 return ibuf; |
1826 } | 1896 } |
1827 | 1897 |
1828 BKE_tracking_stabilization_data(tracking, framenr, width, height, tloc, &tscale, &tangle); | 1898 BKE_tracking_stabilization_data(tracking, framenr, width, height, tloc, &tscale, &tangle); |
1829 | 1899 |
1830 tmpibuf= stabilize_alloc_ibuf(NULL, ibuf, 1); | 1900 tmpibuf= stabilize_alloc_ibuf(NULL, ibuf, 1); |
1831 | 1901 |
1832 /* scale would be handled by matrix transformation when angle is non-zer o */ | 1902 /* scale would be handled by matrix transformation when angle is non-zer o */ |
1833 if(tscale!=1.f && tangle==0.f) { | 1903 if(tscale!=1.f && tangle==0.f) { |
1834 ImBuf *scaleibuf; | 1904 ImBuf *scaleibuf; |
1835 float scale= (stab->scale-1.f)*stab->scaleinf+1.f; | |
1836 | 1905 |
1837 stabilization_auto_scale_factor(tracking, width, height); | 1906 stabilization_auto_scale_factor(tracking, width, height); |
1838 | 1907 |
1839 scaleibuf= stabilize_alloc_ibuf(stab->scaleibuf, ibuf, 0); | 1908 scaleibuf= stabilize_alloc_ibuf(stab->scaleibuf, ibuf, 0); |
1840 stab->scaleibuf= scaleibuf; | 1909 stab->scaleibuf= scaleibuf; |
1841 | 1910 |
1842 IMB_rectcpy(scaleibuf, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y); | 1911 IMB_rectcpy(scaleibuf, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y); |
1843 » » IMB_scalefastImBuf(scaleibuf, ibuf->x*scale, ibuf->y*scale); | 1912 » » IMB_scalefastImBuf(scaleibuf, ibuf->x*tscale, ibuf->y*tscale); |
1844 | 1913 |
1845 ibuf= scaleibuf; | 1914 ibuf= scaleibuf; |
1846 } | 1915 } |
1847 | 1916 |
1848 if(tangle==0.f) { | 1917 if(tangle==0.f) { |
1849 /* if angle is zero, then it's much faster to use rect copy | 1918 /* if angle is zero, then it's much faster to use rect copy |
1850 but could be issues with subpixel precisions */ | 1919 but could be issues with subpixel precisions */ |
1851 » » IMB_rectcpy(tmpibuf, ibuf, tloc[0], tloc[1], 0, 0, ibuf->x, ibuf ->y); | 1920 » » IMB_rectcpy(tmpibuf, ibuf, tloc[0]-(tscale-1.0f)*width/2.0f, tlo c[1]-(tscale-1.0f)*height/2.0f, 0, 0, ibuf->x, ibuf->y); |
1852 } else { | 1921 } else { |
1853 float mat[4][4]; | 1922 float mat[4][4]; |
1854 int i, j; | 1923 int i, j; |
1855 | 1924 |
1856 BKE_tracking_stabdata_to_mat4(ibuf->x, ibuf->y, tloc, tscale, ta ngle, mat); | 1925 BKE_tracking_stabdata_to_mat4(ibuf->x, ibuf->y, tloc, tscale, ta ngle, mat); |
1857 invert_m4(mat); | 1926 invert_m4(mat); |
1858 | 1927 |
1859 for(j=0; j<tmpibuf->y; j++) { | 1928 for(j=0; j<tmpibuf->y; j++) { |
1860 for(i=0; i<tmpibuf->x;i++) { | 1929 for(i=0; i<tmpibuf->x;i++) { |
1861 float vec[3]= {i, j, 0}; | 1930 float vec[3]= {i, j, 0}; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1893 /* image center as rotation center */ | 1962 /* image center as rotation center */ |
1894 cmat[3][0]= (float)width/2.f; | 1963 cmat[3][0]= (float)width/2.f; |
1895 cmat[3][1]= (float)height/2.f; | 1964 cmat[3][1]= (float)height/2.f; |
1896 invert_m4_m4(icmat, cmat); | 1965 invert_m4_m4(icmat, cmat); |
1897 | 1966 |
1898 size_to_mat4(smat, svec); /* scale matrix */ | 1967 size_to_mat4(smat, svec); /* scale matrix */ |
1899 add_v2_v2(lmat[3], loc); /* tranlation matrix */ | 1968 add_v2_v2(lmat[3], loc); /* tranlation matrix */ |
1900 rotate_m4(rmat, 'Z', angle); /* rotation matrix */ | 1969 rotate_m4(rmat, 'Z', angle); /* rotation matrix */ |
1901 | 1970 |
1902 /* compose transformation matrix */ | 1971 /* compose transformation matrix */ |
1903 » mul_serie_m4(mat, lmat, smat, cmat, rmat, icmat, NULL, NULL, NULL); | 1972 » mul_serie_m4(mat, lmat, cmat, rmat, smat, icmat, NULL, NULL, NULL); |
1904 } | 1973 } |
1905 | 1974 |
1906 MovieDistortion *BKE_tracking_distortion_create(void) | 1975 MovieDistortion *BKE_tracking_distortion_create(void) |
1907 { | 1976 { |
1908 MovieDistortion *distortion; | 1977 MovieDistortion *distortion; |
1909 | 1978 |
1910 distortion= MEM_callocN(sizeof(MovieDistortion), "BKE_tracking_distortio n_create"); | 1979 distortion= MEM_callocN(sizeof(MovieDistortion), "BKE_tracking_distortio n_create"); |
1911 | 1980 |
1912 return distortion; | 1981 return distortion; |
1913 } | 1982 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2004 | 2073 |
2005 ImBuf *BKE_tracking_distort(MovieTracking *tracking, ImBuf *ibuf, int width, int height, float overscan) | 2074 ImBuf *BKE_tracking_distort(MovieTracking *tracking, ImBuf *ibuf, int width, int height, float overscan) |
2006 { | 2075 { |
2007 MovieTrackingCamera *camera= &tracking->camera; | 2076 MovieTrackingCamera *camera= &tracking->camera; |
2008 | 2077 |
2009 if(camera->intrinsics == NULL) | 2078 if(camera->intrinsics == NULL) |
2010 camera->intrinsics= BKE_tracking_distortion_create(); | 2079 camera->intrinsics= BKE_tracking_distortion_create(); |
2011 | 2080 |
2012 return BKE_tracking_distortion_exec(camera->intrinsics, tracking, ibuf, width, height, overscan, 0); | 2081 return BKE_tracking_distortion_exec(camera->intrinsics, tracking, ibuf, width, height, overscan, 0); |
2013 } | 2082 } |
LEFT | RIGHT |