()
| 146 | } |
| 147 | |
| 148 | async next(): Promise<IteratorResult<Tensor3D>> { |
| 149 | if (this.isClosed) { |
| 150 | return {value: null, done: true}; |
| 151 | } |
| 152 | |
| 153 | let img; |
| 154 | try { |
| 155 | img = browser.fromPixels(this.webcamVideoElement); |
| 156 | } catch (e) { |
| 157 | throw new Error( |
| 158 | `Error thrown converting video to pixels: ${JSON.stringify(e)}`); |
| 159 | } |
| 160 | if (this.resize) { |
| 161 | try { |
| 162 | return {value: this.cropAndResizeFrame(img), done: false}; |
| 163 | } catch (e) { |
| 164 | throw new Error(`Error thrown cropping the video: ${e.message}`); |
| 165 | } finally { |
| 166 | img.dispose(); |
| 167 | } |
| 168 | } else { |
| 169 | return {value: img, done: false}; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | private needToResize() { |
| 174 | // If resizeWidth and resizeHeight are provided, and different from the |
no test coverage detected