/*
* CINELERRA
* Copyright (C) 1997-2012 Adam Williams <broadcast at earthling dot net>
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
+ *
*/
int FindObjectConfig::equivalent(FindObjectConfig &that)
{
- int result =
+ int result =
global_range_w == that.global_range_w &&
global_range_h == that.global_range_h &&
draw_keypoints == that.draw_keypoints &&
blend = that.blend;
}
-void FindObjectConfig::interpolate(FindObjectConfig &prev,
- FindObjectConfig &next,
- int64_t prev_frame,
- int64_t next_frame,
+void FindObjectConfig::interpolate(FindObjectConfig &prev,
+ FindObjectConfig &next,
+ int64_t prev_frame,
+ int64_t next_frame,
int64_t current_frame)
{
copy_from(prev);
delete affine;
delete temp;
delete overlayer;
-
+
if(blob_param.pBT) cvReleaseBlobTracker(&blob_param.pBT);
if(blob_param.pBD) cvReleaseBlobDetector(&blob_param.pBD);
if(blob_param.pBTGen) cvReleaseBlobTrackGen(&blob_param.pBTGen);
if(blob_param.pBTA) cvReleaseBlobTrackAnalysis(&blob_param.pBTA);
if(blob_param.pFG) cvReleaseFGDetector(&blob_param.pFG);
if(blob_pTracker) cvReleaseBlobTrackerAuto(&blob_pTracker);
-
+
}
const char* FindObjectMain::plugin_title() { return _("Find Object"); }
if(load_configuration())
{
thread->window->lock_window("FindObjectMain::update_gui");
-
+
char string[BCTEXTLEN];
((FindObjectWindow*)thread->window)->global_range_w->update(config.global_range_w);
((FindObjectWindow*)thread->window)->flush();
thread->window->unlock_window();
}
-// printf("FindObjectMain::update_gui %d %d %d %d\n",
-// __LINE__,
+// printf("FindObjectMain::update_gui %d %d %d %d\n",
+// __LINE__,
// config.mode1,
// config.mode2,
// config.mode3);
// Convert to greyscale & crop
-void FindObjectMain::grey_crop(unsigned char *dst,
- VFrame *src,
- int x1,
+void FindObjectMain::grey_crop(unsigned char *dst,
+ VFrame *src,
+ int x1,
int y1,
int x2,
int y2,
if(!object_image)
{
// Only does greyscale
- object_image = cvCreateImage(
- cvSize(object_image_w, object_image_h),
- 8,
+ object_image = cvCreateImage(
+ cvSize(object_image_w, object_image_h),
+ 8,
1);
}
if(!scene_image)
{
// Only does greyscale
- scene_image = cvCreateImage(
- cvSize(scene_image_w, scene_image_h),
- 8,
+ scene_image = cvCreateImage(
+ cvSize(scene_image_w, scene_image_h),
+ 8,
1);
}
if(!prev_object) prev_object = new unsigned char[object_image_w * object_image_h];
memcpy(prev_object, object_image->imageData, object_image_w * object_image_h);
- grey_crop((unsigned char*)scene_image->imageData,
- get_input(scene_layer),
- scene_x1,
- scene_y1,
- scene_x2,
+ grey_crop((unsigned char*)scene_image->imageData,
+ get_input(scene_layer),
+ scene_x1,
+ scene_y1,
+ scene_x2,
scene_y2,
scene_image_w,
scene_image_h);
- grey_crop((unsigned char*)object_image->imageData,
- get_input(object_layer),
- object_x1,
- object_y1,
- object_x2,
+ grey_crop((unsigned char*)object_image->imageData,
+ get_input(object_layer),
+ object_x1,
+ object_y1,
+ object_x2,
object_y2,
object_image_w,
object_image_h);
{
if(object_keypoints) cvClearSeq(object_keypoints);
if(object_descriptors) cvClearSeq(object_descriptors);
- cvExtractSURF(object_image,
- 0,
- &object_keypoints,
- &object_descriptors,
- storage,
+ cvExtractSURF(object_image,
+ 0,
+ &object_keypoints,
+ &object_descriptors,
+ storage,
params,
0);
}
// {
// CvSURFPoint* r1 = (CvSURFPoint*)cvGetSeqElem( object_keypoints, i );
// int size = r1->size / 4;
-// draw_rect(frame[object_layer],
-// r1->pt.x + object_x1 - size,
-// r1->pt.y + object_y1 - size,
-// r1->pt.x + object_x1 + size,
+// draw_rect(frame[object_layer],
+// r1->pt.x + object_x1 - size,
+// r1->pt.y + object_y1 - size,
+// r1->pt.x + object_x1 + size,
// r1->pt.y + object_y1 + size);
// }
// TODO: make the surf data persistent & check for image changes instead
if(scene_keypoints) cvClearSeq(scene_keypoints);
if(scene_descriptors) cvClearSeq(scene_descriptors);
- cvExtractSURF(scene_image,
- 0,
- &scene_keypoints,
- &scene_descriptors,
- storage,
+ cvExtractSURF(scene_image,
+ 0,
+ &scene_keypoints,
+ &scene_descriptors,
+ storage,
params,
0);
// {
// CvSURFPoint* r1 = (CvSURFPoint*)cvGetSeqElem( scene_keypoints, i );
// int size = r1->size / 4;
-// draw_rect(frame[scene_layer],
-// r1->pt.x + scene_x1 - size,
-// r1->pt.y + scene_y1 - size,
-// r1->pt.x + scene_x1 + size,
+// draw_rect(frame[scene_layer],
+// r1->pt.x + scene_x1 - size,
+// r1->pt.y + scene_y1 - size,
+// r1->pt.x + scene_x1 + size,
// r1->pt.y + scene_y1 + size);
// }
-// printf("FindObjectMain::process_surf %d %d %d scene keypoints=%d\n",
-// __LINE__,
+// printf("FindObjectMain::process_surf %d %d %d scene keypoints=%d\n",
+// __LINE__,
// scene_w,
// scene_h,
// scene_keypoints->total);
int *point_pairs = 0;
int total_pairs = 0;
- CvPoint src_corners[4] =
+ CvPoint src_corners[4] =
{
- { 0, 0 },
- { object_w, 0 },
- { object_w, object_h },
+ { 0, 0 },
+ { object_w, 0 },
+ { object_w, object_h },
{ 0, object_h }
};
- CvPoint dst_corners[4] =
+ CvPoint dst_corners[4] =
{
{ 0, 0 },
{ 0, 0 },
//printf("FindObjectMain::process_surf %d\n", __LINE__);
if(scene_keypoints->total &&
object_keypoints->total &&
- locatePlanarObject(object_keypoints,
- object_descriptors,
- scene_keypoints,
- scene_descriptors,
- src_corners,
+ locatePlanarObject(object_keypoints,
+ object_descriptors,
+ scene_keypoints,
+ scene_descriptors,
+ src_corners,
dst_corners,
&point_pairs,
&total_pairs))
int size = r2->size * 1.2 / 9 * 2;
- draw_rect(get_input(scene_layer),
- r2->pt.x + scene_x1 - size,
- r2->pt.y + scene_y1 - size,
- r2->pt.x + scene_x1 + size,
+ draw_rect(get_input(scene_layer),
+ r2->pt.x + scene_x1 - size,
+ r2->pt.y + scene_y1 - size,
+ r2->pt.x + scene_x1 + size,
r2->pt.y + scene_y1 + size);
- draw_rect(get_input(object_layer),
- r1->pt.x + object_x1 - size,
- r1->pt.y + object_y1 - size,
- r1->pt.x + object_x1 + size,
+ draw_rect(get_input(object_layer),
+ r1->pt.x + object_x1 - size,
+ r1->pt.y + object_y1 - size,
+ r1->pt.x + object_x1 + size,
r1->pt.y + object_y1 + size);
}
}
//printf("FindObjectMain::process_surf %d\n", __LINE__);
-
+
}
//printf("FindObjectMain::process_surf %d\n", __LINE__);
// Create aligned, RGB images
if(!object_image)
{
- object_image = cvCreateImage(
- cvSize(object_image_w, object_image_h),
- 8,
+ object_image = cvCreateImage(
+ cvSize(object_image_w, object_image_h),
+ 8,
3);
}
if(!scene_image)
{
- scene_image = cvCreateImage(
- cvSize(scene_image_w, scene_image_h),
- 8,
+ scene_image = cvCreateImage(
+ cvSize(scene_image_w, scene_image_h),
+ 8,
3);
}
delete [] scene_rows;
// from camshiftdemo.cpp
-// Compute new object
- if(memcmp(prev_object,
- object_image->imageData,
+// Compute new object
+ if(memcmp(prev_object,
+ object_image->imageData,
object_image_w * object_image_h * 3) ||
!hist.dims)
{
int _vmin = vmin, _vmax = vmax;
//printf("FindObjectMain::process_camshift %d\n", __LINE__);
- inRange(hsv,
+ inRange(hsv,
Scalar(0, smin, MIN(_vmin,_vmax)),
- Scalar(180, 256, MAX(_vmin, _vmax)),
+ Scalar(180, 256, MAX(_vmin, _vmax)),
mask);
int ch[] = { 0, 0 };
hue.create(hsv.size(), hsv.depth());
cvtColor(image, hsv, CV_RGB2HSV);
int _vmin = vmin, _vmax = vmax;
- inRange(hsv,
+ inRange(hsv,
Scalar(0, smin, MIN(_vmin,_vmax)),
- Scalar(180, 256, MAX(_vmin, _vmax)),
+ Scalar(180, 256, MAX(_vmin, _vmax)),
mask);
int ch[] = {0, 0};
hue.create(hsv.size(), hsv.depth());
mixChannels(&hsv, 1, &hue, 1, ch, 1);
-
+
//printf("FindObjectMain::process_camshift %d %d %d\n", __LINE__, hist.dims, hist.size[1]);
RotatedRect trackBox = RotatedRect(
- Point2f((object_x1 + object_x2) / 2, (object_y1 + object_y2) / 2),
- Size2f(object_w, object_h),
+ Point2f((object_x1 + object_x2) / 2, (object_y1 + object_y2) / 2),
+ Size2f(object_w, object_h),
0);
- trackWindow = Rect(0,
+ trackWindow = Rect(0,
0,
- scene_w,
+ scene_w,
scene_h);
if(hist.dims > 0)
{
-
+
calcBackProject(&hue, 1, 0, hist, backproj, &phranges);
backproj &= mask;
// trackWindow.height = object_h;
// }
- trackBox = CamShift(backproj,
+ trackBox = CamShift(backproj,
trackWindow,
TermCriteria( CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1 ));
//printf("FindObjectMain::process_camshift %d\n", __LINE__);
// Rect(0, 0, cols, rows);
// }
}
-// printf("FindObjectMain::process_camshift %d %d %d %d %d\n",
+// printf("FindObjectMain::process_camshift %d %d %d %d %d\n",
// __LINE__,
// trackWindow.x,
// trackWindow.y,
}
// Get object outline in the scene layer
-// printf("FindObjectMain::process_camshift %d %d %d %d %d %d\n",
+// printf("FindObjectMain::process_camshift %d %d %d %d %d %d\n",
// __LINE__,
// (int)trackBox.center.x,
// (int)trackBox.center.y,
if(!blob_initialized)
{
blob_initialized = 1;
-
+
blob_param.FGTrainFrames = 5;
blob_param.pBT = cvCreateBlobTrackerCCMSPF();
/* Create whole pipline: */
blob_pTracker = cvCreateBlobTrackerAuto1(&blob_param);
-
+
}
// Create aligned, RGB images
if(!scene_image)
{
- scene_image = cvCreateImage(
- cvSize(scene_image_w, scene_image_h),
- 8,
+ scene_image = cvCreateImage(
+ cvSize(scene_image_w, scene_image_h),
+ 8,
3);
}
{
IplImage* pFG = blob_pTracker->GetFGMask();
printf("FindObjectMain::process_blob %d %ld\n", __LINE__, get_source_position());
-
+
// Temporary row pointers
unsigned char **mask_rows = new unsigned char*[scene_image_h];
for(int i = 0; i < scene_image_h; i++)
delete [] mask_rows;
-
+
}
#endif
-
+
}
scene_layer = MIN(scene_layer, PluginClient::get_total_buffers() - 1);
replace_layer = MIN(replace_layer, PluginClient::get_total_buffers() - 1);
-// printf("FindObjectMain::process_buffer %d %d %d %d %d %d\n",
+// printf("FindObjectMain::process_buffer %d %d %d %d %d %d\n",
// __LINE__,
// PluginClient::get_total_buffers(),
// config.object_layer,
// config.scene_layer,
// object_layer,
// scene_layer);
-//
+//
// Create cropped images
// TODO: use oblique corners & affine transform
object_w = (int)(config.global_block_w * w / 100);
if(scene_w % QUANTIZE) scene_image_w += QUANTIZE - (scene_w % QUANTIZE);
if(scene_h % QUANTIZE) scene_image_h += QUANTIZE - (scene_h % QUANTIZE);
- if(object_image &&
+ if(object_image &&
(object_image_w != this->object_image_w ||
object_image_h != this->object_image_h ||
prev_algorithm != config.algorithm))
this->object_image_w = object_image_w;
this->object_image_h = object_image_h;
- if(scene_image &&
+ if(scene_image &&
(scene_image_w != this->scene_image_w ||
scene_image_h != this->scene_image_h ||
prev_algorithm != config.algorithm))
// Read in the input frames
for(int i = 0; i < PluginClient::get_total_buffers(); i++)
{
- read_frame(frame[i],
- i,
- start_position,
+ read_frame(frame[i],
+ i,
+ start_position,
frame_rate);
}
process_surf();
break;
#endif
-
+
case ALGORITHM_CAMSHIFT:
process_camshift();
break;
-
+
case ALGORITHM_BLOB:
process_blob();
break;
}
else
{
- border_x1_accum = (float)border_x1 * config.blend / 100 +
+ border_x1_accum = (float)border_x1 * config.blend / 100 +
border_x1_accum * (100 - config.blend) / 100;
- border_y1_accum = (float)border_y1 * config.blend / 100 +
+ border_y1_accum = (float)border_y1 * config.blend / 100 +
border_y1_accum * (100 - config.blend) / 100;
- border_x2_accum = (float)border_x2 * config.blend / 100 +
+ border_x2_accum = (float)border_x2 * config.blend / 100 +
border_x2_accum * (100 - config.blend) / 100;
- border_y2_accum = (float)border_y2 * config.blend / 100 +
+ border_y2_accum = (float)border_y2 * config.blend / 100 +
border_y2_accum * (100 - config.blend) / 100;
- border_x3_accum = (float)border_x3 * config.blend / 100 +
+ border_x3_accum = (float)border_x3 * config.blend / 100 +
border_x3_accum * (100 - config.blend) / 100;
- border_y3_accum = (float)border_y3 * config.blend / 100 +
+ border_y3_accum = (float)border_y3 * config.blend / 100 +
border_y3_accum * (100 - config.blend) / 100;
- border_x4_accum = (float)border_x4 * config.blend / 100 +
+ border_x4_accum = (float)border_x4 * config.blend / 100 +
border_x4_accum * (100 - config.blend) / 100;
- border_y4_accum = (float)border_y4 * config.blend / 100 +
+ border_y4_accum = (float)border_y4 * config.blend / 100 +
border_y4_accum * (100 - config.blend) / 100;
}
//printf("FindObjectMain::process_surf %d replace_layer=%d\n", __LINE__, replace_layer);
if(!temp)
- temp = new VFrame(w,
- h,
+ temp = new VFrame(w,
+ h,
get_input(scene_layer)->get_color_model());
if(!overlayer)
overlayer = new OverlayFrame(get_project_smp() + 1);
temp->clear_frame();
affine->process(temp,
get_input(replace_layer),
- 0,
+ 0,
AffineEngine::PERSPECTIVE,
border_x1_accum * 100 / w,
border_y1_accum * 100 / h,
border_y4_accum * 100 / h,
1);
- overlayer->overlay(get_input(scene_layer),
- temp,
- 0,
- 0,
- w,
- h,
- 0,
- 0,
- w,
- h,
+ overlayer->overlay(get_input(scene_layer),
+ temp,
+ 0,
+ 0,
+ w,
+ h,
+ 0,
+ 0,
+ w,
+ h,
1, // 0 - 1
TRANSFER_NORMAL,
NEAREST_NEIGHBOR);
if(config.draw_border)
{
- draw_line(get_input(scene_layer),
- border_x1_accum,
- border_y1_accum,
- border_x2_accum,
+ draw_line(get_input(scene_layer),
+ border_x1_accum,
+ border_y1_accum,
+ border_x2_accum,
border_y2_accum);
- draw_line(get_input(scene_layer),
- border_x2_accum,
- border_y2_accum,
- border_x3_accum,
+ draw_line(get_input(scene_layer),
+ border_x2_accum,
+ border_y2_accum,
+ border_x3_accum,
border_y3_accum);
- draw_line(get_input(scene_layer),
- border_x3_accum,
- border_y3_accum,
- border_x4_accum,
+ draw_line(get_input(scene_layer),
+ border_x3_accum,
+ border_y3_accum,
+ border_x4_accum,
border_y4_accum);
- draw_line(get_input(scene_layer),
- border_x4_accum,
- border_y4_accum,
- border_x1_accum,
+ draw_line(get_input(scene_layer),
+ border_x4_accum,
+ border_y4_accum,
+ border_x1_accum,
border_y1_accum);
}