@@ -102,14 +102,13 @@ BaseSemanticSegmentation::generateFromFrame(
102102 // Always run inference without resize — rotate first, then resize.
103103 auto result = runInference (rotated, rotated.size (), classesOfInterest, false );
104104
105- const int w = result.outputWidth ;
106- const int h = result.outputHeight ;
105+ const cv::Size outputSize = modelInputSize ();
107106 // JS reads maskW=frame.height, maskH=frame.width (sensor-native swap).
108107 const cv::Size screenSize (frame.rows , frame.cols );
109108
110109 auto inverseAndResize = [&](std::shared_ptr<OwningArrayBuffer> &buf,
111- int cvType, int interpFlag) {
112- cv::Mat m (h, w , cvType, buf->data ());
110+ int32_t cvType, int32_t interpFlag) {
111+ cv::Mat m (outputSize , cvType, buf->data ());
113112 cv::Mat inv = utils::inverseRotateMat (m, orient);
114113 if (resize && inv.size () != screenSize) {
115114 cv::resize (inv, inv, screenSize, 0 , 0 , interpFlag);
@@ -119,13 +118,11 @@ BaseSemanticSegmentation::generateFromFrame(
119118 return inv;
120119 };
121120
122- if (result.argmax && w > 0 && h > 0 ) {
123- cv::Mat inv = inverseAndResize (result.argmax , CV_32SC1, cv::INTER_NEAREST);
124- result.outputWidth = inv.cols ;
125- result.outputHeight = inv.rows ;
121+ if (result.argmax && outputSize.area () > 0 ) {
122+ inverseAndResize (result.argmax , CV_32SC1, cv::INTER_NEAREST);
126123 }
127124
128- if (result.classBuffers && w > 0 && h > 0 ) {
125+ if (result.classBuffers && outputSize. area () > 0 ) {
129126 for (auto &[label, buf] : *result.classBuffers ) {
130127 inverseAndResize (buf, CV_32FC1, cv::INTER_LINEAR);
131128 }
@@ -244,17 +241,7 @@ BaseSemanticSegmentation::computeResult(
244241 }
245242 }
246243
247- SegmentationResult result;
248- result.argmax = argmax;
249- result.classBuffers = buffersToReturn;
250- if (resize) {
251- result.outputWidth = originalSize.width ;
252- result.outputHeight = originalSize.height ;
253- } else {
254- result.outputWidth = static_cast <int >(outputW);
255- result.outputHeight = static_cast <int >(outputH);
256- }
257- return result;
244+ return semantic_segmentation::SegmentationResult{argmax, buffersToReturn};
258245}
259246
260247} // namespace rnexecutorch::models::semantic_segmentation
0 commit comments