@@ -57,7 +57,7 @@ class BatchProducer {
57
57
}
58
58
private:
59
59
float batch_fps = 0 ; // constant FPS for batch
60
- const std::shared_ptr<bool >& drop_batch;
60
+ const std::shared_ptr<bool > drop_batch; // drop parameters of batch
61
61
std::vector<cv::Mat> batch; // pack of images for graph
62
62
size_t first_el = 0 ; // place of first image in batch
63
63
size_t images_in_batch_count = 0 ; // number of images in batch
@@ -68,8 +68,7 @@ class BatchProducer {
68
68
if (images_in_batch_count < batch_size) {
69
69
/* * case when batch isn't filled **/
70
70
return images_in_batch_count++;
71
- }
72
- else {
71
+ } else {
73
72
if (!is_filled) {
74
73
auto ptr = batch[batch.size () - 1 ].ptr <uint8_t >();
75
74
ptr[1 ] = 1 ;
@@ -94,10 +93,11 @@ class BatchProducer {
94
93
}
95
94
};
96
95
97
- void runBatchFill (const cv::Mat& frame,
98
- BatchProducer& producer,
99
- std::chrono::steady_clock::time_point& time) {
100
- while (!frame.empty ()) {
96
+ static void runBatchFill (const cv::Mat& frame,
97
+ BatchProducer& producer,
98
+ std::chrono::steady_clock::time_point& time,
99
+ bool & is_filling_possible) {
100
+ while (is_filling_possible) {
101
101
producer.fillBatch (frame, time);
102
102
}
103
103
}
@@ -127,14 +127,14 @@ class CustomCapSource : public cv::gapi::wip::IStreamSource {
127
127
if (!fast_frame.data ) {
128
128
GAPI_Assert (false && " Couldn't grab the frame" );
129
129
}
130
-
131
130
producer.fillFastFrame (fast_frame);
132
131
fast_frame.copyTo (thread_frame);
133
132
/* * Batch filling with constant time step **/
134
133
std::thread fill_bath_thr (runBatchFill,
135
134
std::cref (thread_frame),
136
135
std::ref (producer),
137
- std::ref (read_time));
136
+ std::ref (read_time),
137
+ std::ref (is_filling_possible));
138
138
fill_bath_thr.detach ();
139
139
first_batch = producer.getBatch ();
140
140
}
@@ -147,8 +147,9 @@ class CustomCapSource : public cv::gapi::wip::IStreamSource {
147
147
bool first_pulled = false ; // is first already pulled
148
148
std::vector<cv::Mat> first_batch; // batch from constructor
149
149
cv::Mat thread_frame; // frame for batch constant filling
150
- std::mutex thread_frame_lock;
150
+ std::mutex thread_frame_lock; // lock for shared frame
151
151
std::chrono::steady_clock::time_point read_time; // timepoint from cv::read()
152
+ bool is_filling_possible = true ; // access for batch filling
152
153
153
154
virtual bool pull (cv::gapi::wip::Data& data) override {
154
155
/* * Is first already pulled **/
@@ -165,6 +166,7 @@ class CustomCapSource : public cv::gapi::wip::IStreamSource {
165
166
cv::Mat fast_frame = cap->read ();
166
167
167
168
if (!fast_frame.data ) {
169
+ is_filling_possible = false ;
168
170
return false ;
169
171
}
170
172
0 commit comments