@@ -1151,6 +1151,77 @@ json MultilevelController::paint(json data) {
1151
1151
return res;
1152
1152
}
1153
1153
1154
+ json MultilevelController::drawmask (json data) {
1155
+ json contours_json = data[" from" ][" marks" ][0 ][" contours" ];
1156
+ vector< vector<Point > > contours;
1157
+ contours.resize (contours_json.size ());
1158
+ for (int i=0 ; i<(int )contours.size (); i++) {
1159
+ json tmp = contours_json[i];
1160
+ if (tmp.size () && tmp[0 ].has_member (" d" )) {
1161
+ Point pp (tmp[tmp.size ()-1 ][" x" ].as <double >(), tmp[tmp.size ()-1 ][" y" ].as <double >());
1162
+ for (int j=0 ; j<(int )tmp.size (); j++) {
1163
+ Point p (tmp[j][" x" ].as <double >(),tmp[j][" y" ].as <double >());
1164
+ contours[i].push_back (p);
1165
+ }
1166
+ } else {
1167
+ for (int j=0 ; j<(int )tmp.size (); j++)
1168
+ contours[i].push_back (Point (tmp[j][" x" ].as <double >(),tmp[j][" y" ].as <double >()));
1169
+ }
1170
+ }
1171
+ QPainterPath cutSelectPath = QPainterPath ();
1172
+ for (int i = 0 ; i < (int )contours.size (); i++) {
1173
+ cutSelectPath.moveTo (QPoint (contours[i][0 ].x , contours[i][0 ].y ));
1174
+ for (vector<Point >::iterator it = contours[i].begin (); it != contours[i].end (); it++)
1175
+ cutSelectPath.lineTo (QPoint ((*it).x , (*it).y ));
1176
+ cutSelectPath.lineTo (QPoint (contours[i][0 ].x , contours[i][0 ].y ));
1177
+ }
1178
+ QImage qStrokeMask = QImage (image.w , image.h , QImage::Format_RGB32);
1179
+ qStrokeMask.fill (0 );
1180
+ QPainter pt;
1181
+ pt.begin (&qStrokeMask);
1182
+ pt.setBrush (Qt::white);
1183
+ pt.setPen (Qt::NoPen);
1184
+ pt.drawPath (cutSelectPath);
1185
+ qStrokeMask.save ((data[" tmpdir" ].as <string>()+" /2.png" ).c_str ());
1186
+ cerr << " Write mask to : " << (data[" tmpdir" ].as <string>()+" /2.png" ) << endl;
1187
+
1188
+ json res = json::object ();
1189
+ return res;
1190
+ }
1191
+ json MultilevelController::loadmask (json data) {
1192
+ string img_name = data[" tmpdir" ].as <string>()+" /3.png" ;
1193
+ cerr << " Load mask from : " << img_name << endl;
1194
+ QImage mask (img_name.c_str ());
1195
+ MyImage image (mask.width (), mask.height ());
1196
+ for (int y=0 ; y<image.h ; y++) {
1197
+ QRgb* scanelineStrokeMask = (QRgb*)mask.scanLine (y);
1198
+ for (int x=0 ; x<image.w ; x++) {
1199
+ int grayValue = qGray (scanelineStrokeMask[x]);
1200
+ image.get (x,y) = 0 ;
1201
+ if (grayValue>100 ) {
1202
+ image.get (x,y) = 255 ;
1203
+ }
1204
+ }
1205
+ }
1206
+ vector<vector<pair<int ,int >>> contours;
1207
+ findContours (image, contours, true );
1208
+ json arr1 = json::array ();
1209
+ for (int i=0 ; i<(int )contours.size (); i++) {
1210
+ json arr2 = json::array ();
1211
+ for (int j=0 ; j<(int )contours[i].size (); j++) {
1212
+ json point;
1213
+ pair<int ,int > p = contours[i][j];
1214
+ point[" x" ] = p.first ;
1215
+ point[" y" ] = p.second ;
1216
+ arr2.add (point);
1217
+ }
1218
+ arr1.add (arr2);
1219
+ }
1220
+ json res = json::object ();
1221
+ res.set (" contours" , arr1);
1222
+ return res;
1223
+ }
1224
+
1154
1225
json MultilevelController::load_region (json data) {
1155
1226
lock_guard<mutex> lg (selection_lock);
1156
1227
{
0 commit comments