@@ -56,6 +56,15 @@ namespace Eloquent {
5656 return from ((uint16_t *) frame.data , frame.width , frame.height );
5757 }
5858
59+ /* *
60+ * Set src image
61+ * @param frame
62+ * @return
63+ */
64+ Crop& from (camera_fb_t *frame) {
65+ return from ((uint16_t *) frame->buf , frame->width , frame->height );
66+ }
67+
5968 /* *
6069 *
6170 */
@@ -96,12 +105,8 @@ namespace Eloquent {
96105 _src.x2 = _src.width ;
97106 _src.y1 = 0 ;
98107 _src.y2 = _src.height ;
99- _out.x1 = 0 ;
100- _out.x2 = _out.width ;
101- _out.y1 = 0 ;
102- _out.y2 = _out.height ;
103108
104- return * this ;
109+ return offset ( 0 , 0 ) ;
105110 }
106111
107112 /* *
@@ -116,10 +121,8 @@ namespace Eloquent {
116121 _src.y1 = dy;
117122 _src.x2 = _src.width - dx;
118123 _src.y2 = _src.height - dy;
119- _out.x1 = 0 ;
120- _out.y1 = 0 ;
121- _out.x2 = _out.width ;
122- _out.y2 = _out.height ;
124+
125+ return offset (0 , 0 );
123126 }
124127 else if (_out.width > _src.width ) {
125128 uint16_t dx = (_out.width - _src.width ) / 2 ;
@@ -138,6 +141,24 @@ namespace Eloquent {
138141 return *this ;
139142 }
140143
144+ /* *
145+ * Manually set crop area origin
146+ * @param x
147+ * @param y
148+ * @return
149+ */
150+ Crop& offset (int16_t x, int16_t y) {
151+ if (x < 0 ) x += _src.width ;
152+ if (y < 0 ) y += _src.height ;
153+
154+ _src.x1 = x;
155+ _src.x2 = x + _out.width ;
156+ _src.y1 = y;
157+ _src.y2 = y + _out.height ;
158+
159+ return *this ;
160+ }
161+
141162 /* *
142163 * No interpolation
143164 */
@@ -150,7 +171,7 @@ namespace Eloquent {
150171 /* *
151172 * Use mean interpolation
152173 */
153- Crop& mean () {
174+ Crop& linear () {
154175 _algo = IMAGE_RESIZE_MEAN;
155176
156177 return *this ;
@@ -184,9 +205,9 @@ namespace Eloquent {
184205 if (_out.channels != 1 && _out.channels != 3 )
185206 return exception.set (" Output channels must be 1 (gray) or 3 (rgb)" );
186207
187- ESP_LOGI (" Crop" , " _src : w=%d, h=%d, y1=%d, y2=%d, x1=%d, x2=%d" , _src.width , _src.height , _src.y1 , _src.y2 , _src.x1 , _src.x2 );
188- ESP_LOGI (" Crop" , " _out : w=%d, h=%d, y1=%d, y2=%d, x1=%d, x2=%d" , _out.width , _out.height , _out.y1 , _out.y2 , _out.x1 , _out.x2 );
189-
208+ ESP_LOGD (" Crop" , " src : w=%d, h=%d, y1=%d, y2=%d, x1=%d, x2=%d" , _src.width , _src.height , _src.y1 , _src.y2 , _src.x1 , _src.x2 );
209+ ESP_LOGD (" Crop" , " out : w=%d, h=%d, y1=%d, y2=%d, x1=%d, x2=%d" , _out.width , _out.height , _out.y1 , _out.y2 , _out.x1 , _out.x2 );
210+
190211 crop_and_resize (
191212 out,
192213 _out.height ,
0 commit comments