ImageLabeler.cpp 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470
  1. /*
  2. * ImageLabeler.cpp
  3. *
  4. * Created on: Oct 4, 2011
  5. * Author: Gapchich Vladislav
  6. */
  7. #include "ImageLabeler.h"
  8. #include "functions.h"
  9. #include <QApplication>
  10. #include <QFrame>
  11. #include <QMenuBar>
  12. #include <QMenu>
  13. #include <QAction>
  14. #include <QBoxLayout>
  15. #include <QGridLayout>
  16. #include <QPixmap>
  17. #include <QLabel>
  18. #include <QScrollArea>
  19. #include <QPushButton>
  20. #include <QButtonGroup>
  21. #include <QListWidget>
  22. #include <QListWidgetItem>
  23. #include <QDesktopWidget>
  24. #include <QFileDialog>
  25. #include <QColorDialog>
  26. #include <QDir>
  27. #include <QMessageBox>
  28. #include <QListIterator>
  29. #include <QDomDocument>
  30. #include <QFile>
  31. #include <QKeyEvent>
  32. #include <QDebug>
  33. ImageLabeler::ImageLabeler(QWidget *aParent) :
  34. QMainWindow(aParent)
  35. {
  36. /*
  37. * Variables
  38. */
  39. list_images_ = new QList< Image >;
  40. main_label_ = -1;
  41. pure_data_ = 0;
  42. //label_ID_ = -1;
  43. /* options */
  44. auto_color_generation_ = 0;
  45. /* flags */
  46. interrupt_search_ = 0;
  47. unsaved_data_ = 0;
  48. /*
  49. * menu bar part begins
  50. */
  51. menu_bar_ = new QMenuBar(this);
  52. setMenuBar(menu_bar_);
  53. menu_file_ = new QMenu(menu_bar_);
  54. menu_file_->setTitle(tr("&File"));
  55. menu_pascal_ = new QMenu(menu_bar_);
  56. menu_pascal_->setTitle(tr("&Pascal"));
  57. menu_view_ = new QMenu(menu_bar_);
  58. menu_view_->setTitle(tr("&View"));
  59. menu_edit_ = new QMenu(menu_bar_);
  60. menu_edit_->setTitle(tr("&Edit"));
  61. menu_help_ = new QMenu(menu_bar_);
  62. menu_help_->setTitle(tr("&Help"));
  63. /* menu file */
  64. action_open_image_ = new QAction(this);
  65. action_open_image_->setText(tr("&Load image"));
  66. action_open_images_ = new QAction(this);
  67. action_open_images_->setText(tr("&Load images(recursively)"));
  68. action_open_labeled_image_ = new QAction(this);
  69. action_open_labeled_image_->setText(tr("&Load labeled image"));
  70. action_load_legend_ = new QAction(this);
  71. action_load_legend_->setText(tr("&Load legend"));
  72. action_save_labels_ = new QAction(this);
  73. action_save_labels_->setText(tr("&Save all info"));
  74. action_save_labels_->setEnabled(false);
  75. action_save_segmented_ = new QAction(this);
  76. action_save_segmented_->setText(tr("Save segmented &picture"));
  77. action_save_segmented_->setEnabled(false);
  78. action_save_legend_ = new QAction(this);
  79. action_save_legend_->setText(tr("Save &legend"));
  80. action_save_legend_->setEnabled(false);
  81. action_quit_ = new QAction(this);
  82. action_quit_->setText(tr("&Quit"));
  83. /* menu pascal */
  84. action_load_pascal_file_ = new QAction(this);
  85. action_load_pascal_file_->setText(tr("&Load pascal file"));
  86. action_load_pascal_poly_ = new QAction(this);
  87. action_load_pascal_poly_->setText(tr("&Load poly info"));
  88. /* menu view */
  89. action_view_normal_ = new QAction(this);
  90. action_view_normal_->setText(tr("&Normal"));
  91. action_view_normal_->setEnabled(false);
  92. action_view_segmented_ = new QAction(this);
  93. action_view_segmented_->setText(tr("&Segmented"));
  94. action_view_segmented_->setEnabled(false);
  95. /* menu edit */
  96. action_undo_ = new QAction(this);
  97. action_undo_->setText(tr("&Undo"));
  98. action_undo_->setEnabled(false);
  99. action_redo_ = new QAction(this);
  100. action_redo_->setText(tr("&Redo"));
  101. action_redo_->setEnabled(false);
  102. action_bound_box_tool_ = new QAction(this);
  103. action_bound_box_tool_->setText(tr("Bounding box tool"));
  104. action_bound_box_tool_->setEnabled(false);
  105. action_polygon_tool_ = new QAction(this);
  106. action_polygon_tool_->setText(tr("&Polygon tool"));
  107. action_polygon_tool_->setEnabled(false);
  108. action_tagging_tool_ = new QAction(this);
  109. action_tagging_tool_->setText(tr("&Tagging tool"));
  110. action_tagging_tool_->setEnabled(false);
  111. action_add_description_ = new QAction(this);
  112. action_add_description_->setText(tr("&Add image description"));
  113. action_add_description_->setEnabled(false);
  114. action_options_ = new QAction(this);
  115. action_options_->setText(tr("&Options"));
  116. /* menu help */
  117. action_help_content_ = new QAction(this);
  118. action_help_content_->setText(tr("&Help content"));
  119. action_help_content_->setEnabled(false);
  120. action_about_ = new QAction(this);
  121. action_about_->setText(tr("&About"));
  122. action_about_->setEnabled(false);
  123. /* ------------------ */
  124. menu_file_->addAction(action_open_image_);
  125. menu_file_->addAction(action_open_images_);
  126. menu_file_->addAction(action_open_labeled_image_);
  127. menu_file_->addAction(action_load_legend_);
  128. menu_file_->addAction(menu_pascal_->menuAction());
  129. menu_file_->addSeparator();
  130. menu_file_->addAction(action_save_segmented_);
  131. menu_file_->addAction(action_save_legend_);
  132. menu_file_->addAction(action_save_labels_);
  133. menu_file_->addSeparator();
  134. menu_file_->addAction(action_quit_);
  135. menu_pascal_->addAction(action_load_pascal_file_);
  136. menu_pascal_->addAction(action_load_pascal_poly_);
  137. menu_view_->addAction(action_view_normal_);
  138. menu_view_->addAction(action_view_segmented_);
  139. menu_edit_->addAction(action_undo_);
  140. menu_edit_->addAction(action_redo_);
  141. menu_edit_->addSeparator();
  142. menu_edit_->addAction(action_bound_box_tool_);
  143. menu_edit_->addAction(action_polygon_tool_);
  144. menu_edit_->addAction(action_tagging_tool_);
  145. menu_edit_->addSeparator();
  146. menu_edit_->addAction(action_add_description_);
  147. menu_edit_->addAction(action_options_);
  148. menu_help_->addAction(action_help_content_);
  149. menu_help_->addAction(action_about_);
  150. menu_bar_->addAction(menu_file_->menuAction());
  151. menu_bar_->addAction(menu_view_->menuAction());
  152. menu_bar_->addAction(menu_edit_->menuAction());
  153. menu_bar_->addAction(menu_help_->menuAction());
  154. /*
  155. * popup menu part begins
  156. */
  157. popup_area_list_ = new QMenu;
  158. action_delete_area_ = new QAction(this);
  159. action_delete_area_->setText(tr("&Delete area"));
  160. action_edit_area_ = new QAction(this);
  161. action_edit_area_->setText(tr("&Change area"));
  162. popup_area_list_->addAction(action_delete_area_);
  163. popup_area_list_->addAction(action_edit_area_);
  164. popup_label_list_ = new QMenu;
  165. action_set_color_ = new QAction(this);
  166. action_set_color_->setText(tr("Set &color"));
  167. action_toggle_priority_ = new QAction(this);
  168. action_toggle_priority_->setText(tr("Toggle &priority"));
  169. action_delete_label_ = new QAction(this);
  170. action_delete_label_->setText(tr("&Delete"));
  171. popup_label_list_->addAction(action_set_color_);
  172. popup_label_list_->addAction(action_toggle_priority_);
  173. popup_label_list_->addAction(action_delete_label_);
  174. popup_images_list_ = new QMenu;
  175. action_remove_image_ = new QAction(this);
  176. action_remove_image_->setText(tr("&remove image"));
  177. popup_images_list_->addAction(action_remove_image_);
  178. /*
  179. * widgets part begins
  180. */
  181. central_widget_ = new QWidget(this);
  182. setCentralWidget(central_widget_);
  183. frame_toolbox_ = new QFrame(central_widget_);
  184. frame_toolbox_->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
  185. frame_toolbox_->setLineWidth(0);
  186. frame_toolbox_->setMidLineWidth(0);
  187. frame_center_ = new QFrame(central_widget_);
  188. //frame_image_->setFrameStyle(QFrame::Box | QFrame::Plain);
  189. //frame_image_->setLineWidth(1);
  190. frame_image_ = new QScrollArea(frame_center_);
  191. //frame_image_->setStyleSheet("QWidget {background: #888888;}");
  192. frame_image_->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
  193. frame_image_->setLineWidth(0);
  194. frame_image_->setMidLineWidth(0);
  195. frame_image_->setWidgetResizable(false);
  196. frame_image_->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
  197. frame_image_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  198. frame_labelbox_ = new QFrame(central_widget_);
  199. frame_labelbox_->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
  200. frame_labelbox_->setLineWidth(0);
  201. frame_labelbox_->setMidLineWidth(0);
  202. image_ = new QPixmap(500, 500);
  203. image_->fill(QColor(Qt::white));
  204. //image_holder_ = new ImageHolder(frame_image_);
  205. image_holder_ = new ImageHolder;//(frame_image_);
  206. image_holder_->setPixmap(*image_);
  207. //image_holder_->setStyleSheet("QLabel {background: #ffffff;}");
  208. image_holder_->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
  209. image_holder_->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
  210. image_holder_->setScaledContents(true);
  211. image_holder_->setFrameStyle(QFrame::Box | QFrame::Plain);
  212. image_holder_->setLineWidth(0);
  213. frame_image_->setWidget(image_holder_);
  214. list_label_ = new QListWidget(central_widget_);
  215. list_label_->setContextMenuPolicy(Qt::CustomContextMenu);
  216. list_areas_ = new QListWidget(central_widget_);
  217. list_areas_->setContextMenuPolicy(Qt::CustomContextMenu);
  218. list_images_widget_ = new QListWidget(central_widget_);
  219. list_images_widget_->setContextMenuPolicy(Qt::CustomContextMenu);
  220. // addLabel(0, false, "BACKGROUND");
  221. // list_label_->item(0)->setFlags(Qt::ItemIsSelectable);
  222. //QListWidgetItem *background = list_label_->item(0);
  223. //qDebug() << background;
  224. //background->setFlags(Qt::ItemIsSelectable);
  225. label_toolbox_ = new QLabel(tr("Tool box"), frame_toolbox_);
  226. label_list_areas_ = new QLabel(tr("Selected areas:"), central_widget_);
  227. label_list_images_ = new QLabel(tr("Loaded images:"), central_widget_);
  228. /* buttons */
  229. button_bound_box_tool_ = new QPushButton(frame_toolbox_);
  230. button_bound_box_tool_->setText(tr("bbox"));
  231. button_bound_box_tool_->setEnabled(false);
  232. button_bound_box_tool_->setCheckable(true);
  233. button_polygon_tool_ = new QPushButton(frame_toolbox_);
  234. button_polygon_tool_->setText(tr("poly tool"));
  235. button_polygon_tool_->setEnabled(false);
  236. button_polygon_tool_->setCheckable(true);
  237. button_tagging_tool_ = new QPushButton(frame_toolbox_);
  238. button_tagging_tool_->setText(tr("tagging"));
  239. button_tagging_tool_->setEnabled(false);
  240. button_clear_selection_tool_ = new QPushButton(frame_toolbox_);
  241. button_clear_selection_tool_->setText(tr("clear selection"));
  242. button_clear_selection_tool_->setEnabled(false);
  243. button_generate_colors_ = new QPushButton(frame_toolbox_);
  244. button_generate_colors_->setText(tr("generate label colors"));
  245. button_generate_colors_->setEnabled(false);
  246. button_delete_all_labels_ = new QPushButton(frame_toolbox_);
  247. button_delete_all_labels_->setText(tr("delete all labels"));
  248. button_delete_all_labels_->setEnabled(false);
  249. group_tools_ = new QButtonGroup;
  250. group_tools_->addButton(button_bound_box_tool_);
  251. group_tools_->addButton(button_polygon_tool_);
  252. button_confirm_selection_ = new QPushButton(central_widget_);
  253. button_confirm_selection_->setText(tr("Confirm selection"));
  254. button_confirm_selection_->setEnabled(false);
  255. button_add_label_ = new QPushButton(frame_labelbox_);
  256. button_add_label_->setText(tr("Add label"));
  257. button_add_label_->setEnabled(false);
  258. button_remove_label_ = new QPushButton(frame_labelbox_);
  259. button_remove_label_->setText(tr("Remove label"));
  260. button_remove_label_->setEnabled(false);
  261. button_prev_image_ = new QPushButton(central_widget_);
  262. button_prev_image_->setText("←");
  263. button_next_image_ = new QPushButton(central_widget_);
  264. button_next_image_->setText("→");
  265. /*
  266. * layouts part begins
  267. */
  268. layout_main_ = new QHBoxLayout(central_widget_);
  269. layout_left_ = new QVBoxLayout();
  270. layout_toolbox_ = new QVBoxLayout();
  271. layout_center_ = new QVBoxLayout();
  272. layout_frame_image_ = new QVBoxLayout();
  273. layout_image_widget_ = new QGridLayout();
  274. layout_center_buttons_ = new QHBoxLayout();
  275. layout_right_ = new QVBoxLayout();
  276. layout_labelbox_ = new QVBoxLayout();
  277. layout_labelbox_buttons_ = new QHBoxLayout();
  278. layout_main_->addLayout(layout_left_);
  279. layout_main_->addLayout(layout_center_);
  280. layout_main_->addLayout(layout_right_);
  281. /* making the center part stretchable */
  282. layout_main_->setStretch(1, 1);
  283. /* left part */
  284. layout_left_->addWidget(frame_toolbox_);
  285. frame_toolbox_->setLayout(layout_toolbox_);
  286. layout_toolbox_->addWidget(label_toolbox_);
  287. layout_toolbox_->addWidget(button_bound_box_tool_);
  288. layout_toolbox_->addWidget(button_polygon_tool_);
  289. layout_toolbox_->addSpacing(10);
  290. layout_toolbox_->addWidget(button_tagging_tool_);
  291. layout_toolbox_->addSpacing(10);
  292. layout_toolbox_->addWidget(button_clear_selection_tool_);
  293. layout_toolbox_->addWidget(button_delete_all_labels_);
  294. layout_toolbox_->addSpacing(10);
  295. layout_toolbox_->addWidget(button_generate_colors_);
  296. /* stretch is for making toolbox as small as it can be */
  297. layout_toolbox_->addSpacing(10);
  298. layout_left_->addWidget(label_list_images_);
  299. layout_left_->addWidget(list_images_widget_);
  300. list_images_widget_->setFixedWidth(200);
  301. layout_left_->addStretch(1);
  302. layout_left_->addWidget(button_confirm_selection_);
  303. /* central part */
  304. layout_center_->addWidget(frame_center_);
  305. frame_center_->setLayout(layout_frame_image_);
  306. //layout_frame_image_->addWidget(image_holder_);
  307. layout_frame_image_->setContentsMargins(0, 0, 0, 0);
  308. layout_frame_image_->addWidget(frame_image_);
  309. //frame_image_->setLayout(layout_image_widget_);
  310. // layout_image_widget_->setRowStretch(0, 1);
  311. // layout_image_widget_->setColumnStretch(0, 1);
  312. // layout_image_widget_->addWidget(image_holder_, 1, 1);
  313. // layout_image_widget_->setRowStretch(2, 1);
  314. // layout_image_widget_->setColumnStretch(2, 1);
  315. //layout_frame_image_->addStretch(1);
  316. layout_frame_image_->addLayout(layout_center_buttons_);
  317. layout_center_buttons_->addWidget(button_prev_image_);
  318. layout_center_buttons_->addWidget(button_next_image_);
  319. /* right part */
  320. layout_right_->addWidget(frame_labelbox_);
  321. frame_labelbox_->setFixedWidth(200);
  322. frame_labelbox_->setLayout(layout_labelbox_);
  323. layout_labelbox_->addLayout(layout_labelbox_buttons_);
  324. layout_labelbox_buttons_->addWidget(button_add_label_);
  325. layout_labelbox_buttons_->addWidget(button_remove_label_);
  326. layout_labelbox_->addWidget(list_label_);
  327. layout_labelbox_->addWidget(label_list_areas_);
  328. layout_labelbox_->addWidget(list_areas_);
  329. connect(
  330. action_quit_,
  331. SIGNAL(triggered()),
  332. this,
  333. SLOT(close())
  334. );
  335. connect(
  336. action_open_images_,
  337. SIGNAL(triggered()),
  338. this,
  339. SLOT(loadImages())
  340. );
  341. connect(
  342. action_open_image_,
  343. SIGNAL(triggered()),
  344. this,
  345. SLOT(loadImage())
  346. );
  347. connect(
  348. action_open_labeled_image_,
  349. SIGNAL(triggered()),
  350. this,
  351. SLOT(loadInfo())
  352. );
  353. connect(
  354. action_load_legend_,
  355. SIGNAL(triggered()),
  356. this,
  357. SLOT(loadLegendFromFile())
  358. );
  359. connect(
  360. action_load_pascal_file_,
  361. SIGNAL(triggered()),
  362. this,
  363. SLOT(loadPascalFile())
  364. );
  365. connect(
  366. action_load_pascal_poly_,
  367. SIGNAL(triggered()),
  368. this,
  369. SLOT(loadPascalPolys())
  370. );
  371. connect(
  372. action_save_legend_,
  373. SIGNAL(triggered()),
  374. this,
  375. SLOT(saveLegend())
  376. );
  377. connect(
  378. action_save_segmented_,
  379. SIGNAL(triggered()),
  380. this,
  381. SLOT(saveSegmentedPicture())
  382. );
  383. connect(
  384. action_save_labels_,
  385. SIGNAL(triggered()),
  386. this,
  387. SLOT(saveAllInfo())
  388. );
  389. connect(
  390. action_view_normal_,
  391. SIGNAL(triggered()),
  392. this,
  393. SLOT(viewNormal())
  394. );
  395. connect(
  396. action_view_segmented_,
  397. SIGNAL(triggered()),
  398. this,
  399. SLOT(viewSegmented())
  400. );
  401. connect(
  402. action_undo_,
  403. SIGNAL(triggered()),
  404. image_holder_,
  405. SLOT(undo())
  406. );
  407. connect(
  408. action_redo_,
  409. SIGNAL(triggered()),
  410. image_holder_,
  411. SLOT(redo())
  412. );
  413. connect(
  414. action_add_description_,
  415. SIGNAL(triggered()),
  416. &line_edit_form_,
  417. SLOT(setDescription())
  418. );
  419. connect(
  420. action_options_,
  421. SIGNAL(triggered()),
  422. &options_form_,
  423. SLOT(show())
  424. );
  425. connect(
  426. button_add_label_,
  427. SIGNAL(clicked()),
  428. this,
  429. SLOT(addLabel())
  430. );
  431. connect(
  432. button_remove_label_,
  433. SIGNAL(clicked()),
  434. this, SLOT(removeLabel())
  435. );
  436. connect(
  437. button_next_image_,
  438. SIGNAL(clicked()),
  439. this,
  440. SLOT(nextImage())
  441. );
  442. connect(
  443. button_prev_image_,
  444. SIGNAL(clicked()),
  445. this,
  446. SLOT(prevImage())
  447. );
  448. connect(
  449. button_bound_box_tool_,
  450. SIGNAL(toggled(bool)),
  451. this,
  452. SLOT(setBoundingBoxTool(bool))
  453. );
  454. connect(
  455. button_polygon_tool_,
  456. SIGNAL(toggled(bool)),
  457. this,
  458. SLOT(setPolygonTool(bool))
  459. );
  460. connect(
  461. button_tagging_tool_,
  462. SIGNAL(clicked()),
  463. &line_edit_form_,
  464. SLOT(setTags())
  465. );
  466. connect(
  467. button_clear_selection_tool_,
  468. SIGNAL(clicked()),
  469. this,
  470. SLOT(clearAllTool())
  471. );
  472. connect(
  473. button_generate_colors_,
  474. SIGNAL(clicked()),
  475. this,
  476. SLOT(generateColors())
  477. );
  478. connect(
  479. button_delete_all_labels_,
  480. SIGNAL(clicked()),
  481. this,
  482. SLOT(clearLabelList())
  483. );
  484. connect(
  485. button_confirm_selection_,
  486. SIGNAL(clicked()),
  487. this,
  488. SLOT(confirmSelection())
  489. );
  490. connect(
  491. list_label_,
  492. SIGNAL(itemChanged(QListWidgetItem *)),
  493. this,
  494. SLOT(editLabel(QListWidgetItem *))
  495. );
  496. connect(
  497. list_label_,
  498. SIGNAL(itemClicked(QListWidgetItem *)),
  499. this,
  500. SLOT(setLabelID(QListWidgetItem *))
  501. );
  502. connect(
  503. list_areas_,
  504. SIGNAL(itemDoubleClicked(QListWidgetItem *)),
  505. image_holder_,
  506. SLOT(focusOnArea(QListWidgetItem *))
  507. );
  508. connect(
  509. list_areas_,
  510. SIGNAL(customContextMenuRequested(const QPoint &)),
  511. this,
  512. SLOT(areaListPopupMenu(const QPoint &))
  513. );
  514. connect(
  515. list_areas_,
  516. SIGNAL(itemChanged(QListWidgetItem *)),
  517. this,
  518. SLOT(onAreaItemChange(QListWidgetItem *))
  519. );
  520. connect(
  521. list_label_,
  522. SIGNAL(customContextMenuRequested(const QPoint &)),
  523. this,
  524. SLOT(labelListPopupMenu(const QPoint &))
  525. );
  526. connect(
  527. list_images_widget_,
  528. SIGNAL(itemDoubleClicked(QListWidgetItem *)),
  529. this,
  530. SLOT(selectImage(QListWidgetItem *))
  531. );
  532. connect(
  533. list_images_widget_,
  534. SIGNAL(customContextMenuRequested(const QPoint &)),
  535. this,
  536. SLOT(imageListPopupMenu(const QPoint &))
  537. );
  538. connect(
  539. action_delete_area_,
  540. SIGNAL(triggered()),
  541. this,
  542. SLOT(deleteArea())
  543. );
  544. connect(
  545. action_edit_area_,
  546. SIGNAL(triggered()),
  547. this,
  548. SLOT(editArea())
  549. );
  550. connect(
  551. action_set_color_,
  552. SIGNAL(triggered()),
  553. this,
  554. SLOT(setLabelColor())
  555. );
  556. connect(
  557. action_toggle_priority_,
  558. SIGNAL(triggered()),
  559. this,
  560. SLOT(toggleLabelPriority())
  561. );
  562. connect(
  563. action_delete_label_,
  564. SIGNAL(triggered()),
  565. this,
  566. SLOT(removeLabel())
  567. );
  568. connect(
  569. action_remove_image_,
  570. SIGNAL(triggered()),
  571. this,
  572. SLOT(removeImage())
  573. );
  574. connect(
  575. image_holder_,
  576. SIGNAL(selectionStarted()),
  577. this,
  578. SLOT(onSelectionStarted())
  579. );
  580. connect(
  581. &line_edit_form_,
  582. SIGNAL(dataSet(QString)),
  583. this,
  584. SLOT(setDataFromForm(QString))
  585. );
  586. connect(
  587. image_holder_,
  588. SIGNAL(imageScaled()),
  589. this,
  590. SLOT(onImageScaled())
  591. );
  592. connect(
  593. image_holder_,
  594. SIGNAL(areaEdited()),
  595. this,
  596. SLOT(onAreaEdit())
  597. );
  598. connect(
  599. &options_form_,
  600. SIGNAL(optionsSet()),
  601. this,
  602. SLOT(onOptionsSet())
  603. );
  604. image_holder_->setBoundingBoxList(&list_bounding_box_);
  605. image_holder_->setPolygonList(&list_polygon_);
  606. image_holder_->setLabelColorList(&list_label_colors_);
  607. image_holder_->setMainLabelNum(&main_label_);
  608. image_holder_->setImage(image_);
  609. }
  610. ImageLabeler::~ImageLabeler()
  611. {
  612. delete action_quit_;
  613. delete action_open_labeled_image_;
  614. delete action_open_image_;
  615. delete action_open_images_;
  616. delete action_load_legend_;
  617. delete action_load_pascal_file_;
  618. delete action_load_pascal_poly_;
  619. delete action_save_legend_;
  620. delete action_save_segmented_;
  621. delete action_save_labels_;
  622. delete action_view_normal_;
  623. delete action_view_segmented_;
  624. delete action_undo_;
  625. delete action_redo_;
  626. delete action_bound_box_tool_;
  627. delete action_polygon_tool_;
  628. delete action_tagging_tool_;
  629. delete action_add_description_;
  630. delete action_options_;
  631. delete action_about_;
  632. delete action_help_content_;
  633. delete menu_pascal_;
  634. delete menu_file_;
  635. delete menu_view_;
  636. delete menu_edit_;
  637. delete menu_help_;
  638. delete menu_bar_;
  639. delete action_delete_area_;
  640. delete action_edit_area_;
  641. delete popup_area_list_;
  642. delete action_toggle_priority_;
  643. delete action_set_color_;
  644. delete action_delete_label_;
  645. delete popup_label_list_;
  646. delete action_remove_image_;
  647. delete popup_images_list_;
  648. delete image_;
  649. delete image_holder_;
  650. delete button_add_label_;
  651. delete button_remove_label_;
  652. delete button_bound_box_tool_;
  653. delete button_polygon_tool_;
  654. delete button_tagging_tool_;
  655. delete button_clear_selection_tool_;
  656. delete button_generate_colors_;
  657. delete button_delete_all_labels_;
  658. delete button_next_image_;
  659. delete button_prev_image_;
  660. delete button_confirm_selection_;
  661. delete label_list_areas_;
  662. delete label_toolbox_;
  663. delete label_list_images_;
  664. delete list_areas_;
  665. delete list_label_;
  666. delete list_images_widget_;
  667. delete layout_toolbox_;
  668. delete layout_right_;
  669. delete layout_center_buttons_;
  670. delete layout_frame_image_;
  671. delete layout_center_;
  672. delete layout_labelbox_buttons_;
  673. delete layout_labelbox_;
  674. delete layout_left_;
  675. delete layout_main_;
  676. delete frame_labelbox_;
  677. delete frame_toolbox_;
  678. delete frame_image_;
  679. delete frame_center_;
  680. delete central_widget_;
  681. //delete current_image_;
  682. if (pure_data_) {
  683. delete[] *pure_data_;
  684. delete pure_data_;
  685. }
  686. delete list_images_;
  687. }
  688. void
  689. ImageLabeler::addImage(Image *anImage)
  690. {
  691. QListWidgetItem *newItem = new QListWidgetItem;
  692. QString itemText = QString("%1: %2").
  693. arg(list_images_widget_->count()).
  694. arg(getFilenameFromPath(&(anImage->image_)));
  695. if (anImage->labeled_)
  696. itemText.append(" #labeled");
  697. if (anImage->pas_)
  698. itemText.append(" #pas");
  699. newItem->setText(itemText);
  700. list_images_widget_->addItem(newItem);
  701. list_images_->append(*anImage);
  702. }
  703. void
  704. ImageLabeler::addLabel()
  705. {
  706. QListWidgetItem *newItem = new QListWidgetItem;
  707. QString label;
  708. int itemNum = list_label_->count();
  709. label.append(QString("%1: ").arg(itemNum));
  710. if (itemNum) {
  711. newItem->setFlags(newItem->flags() | Qt::ItemIsEditable);
  712. label.append("New label");
  713. }
  714. else {
  715. newItem->setFlags(
  716. Qt::ItemIsUserCheckable | Qt::ItemIsSelectable |
  717. Qt::ItemIsEnabled
  718. );
  719. label.append("BACKGROUND");
  720. }
  721. newItem->setText(label);
  722. QPixmap iconPix = QPixmap(20, 20);
  723. QColor color;
  724. if (0 != itemNum)
  725. color = Qt::white;
  726. else
  727. color = Qt::black;
  728. iconPix.fill(color);
  729. QIcon icon(iconPix);
  730. list_label_colors_.append(color.rgb());
  731. newItem->setIcon(icon);
  732. list_label_->addItem(newItem);
  733. list_label_->setItemSelected(newItem, true);
  734. label_ID_ = list_label_->count() - 1;
  735. unsaved_data_ = 1;
  736. }
  737. void
  738. ImageLabeler::addLabel(
  739. int aLabelID,
  740. bool isMain,
  741. QString aLabel
  742. )
  743. {
  744. QListWidgetItem *newItem = new QListWidgetItem;
  745. if (0 == aLabelID) {
  746. aLabel = QString("BACKGROUND");
  747. newItem->setFlags(
  748. Qt::ItemIsUserCheckable | Qt::ItemIsSelectable |
  749. Qt::ItemIsEnabled
  750. );
  751. }
  752. QString label;
  753. label.append(QString("%1: %2").
  754. arg(aLabelID).
  755. arg(aLabel)
  756. );
  757. /* TODO: check if there is another main label and make it common */
  758. if (isMain) {
  759. main_label_ = aLabelID;
  760. }
  761. QPixmap iconPix = QPixmap(20, 20);
  762. QColor color;
  763. if (0 != aLabelID)
  764. color = Qt::white;
  765. else
  766. color = Qt::black;
  767. iconPix.fill(color);
  768. QIcon icon(iconPix);
  769. list_label_colors_.append(color.rgb());
  770. newItem->setIcon(icon);
  771. newItem->setText(label);
  772. newItem->setFlags(newItem->flags() | Qt::ItemIsEditable);
  773. list_label_->addItem(newItem);
  774. list_label_->setItemSelected(newItem, true);
  775. unsaved_data_ = 1;
  776. }
  777. void
  778. ImageLabeler::editLabel(QListWidgetItem *anItem)
  779. {
  780. QString label = anItem->text();
  781. int itemRow = list_label_->row(anItem);
  782. QString prefix = QString("%1: ").arg(itemRow);
  783. if (-1 != label.indexOf(prefix)) {
  784. return;
  785. /* NOTREACHED */
  786. }
  787. label.prepend(QString("%1: ").arg(itemRow));
  788. if (main_label_ == itemRow) {
  789. label.append(" #main");
  790. }
  791. list_label_->blockSignals(true);
  792. anItem->setText(label);
  793. list_label_->blockSignals(false);
  794. unsaved_data_ = 1;
  795. }
  796. void
  797. ImageLabeler::removeLabel()
  798. {
  799. if (0 == list_label_->count()) {
  800. return;
  801. /* NOTREACHED */
  802. }
  803. //QListWidgetItem *current = list_label_->currentItem();
  804. /* we need to keep BACKGROUND category */
  805. if (label_ID_ < 1) {
  806. return;
  807. /* NOTREACHED */
  808. }
  809. if (list_label_->count() <= label_ID_ ||
  810. list_label_colors_.count() <= label_ID_) {
  811. return;
  812. /* NOTREACHED */
  813. }
  814. list_label_->takeItem(label_ID_);
  815. list_label_colors_.takeAt(label_ID_);
  816. unsaved_data_ = 1;
  817. }
  818. void
  819. ImageLabeler::setLabelID(
  820. QListWidgetItem *anItem
  821. )
  822. {
  823. Q_UNUSED(anItem)
  824. if (!list_label_->count()) {
  825. return;
  826. /* NOTREACHED */
  827. }
  828. label_ID_ = list_label_->row(anItem);
  829. }
  830. void
  831. ImageLabeler::addBBoxArea(
  832. int anID,
  833. BoundingBox aBBox,
  834. int itemID
  835. )
  836. {
  837. QListWidgetItem *newItem = new QListWidgetItem;
  838. if (-1 == itemID)
  839. itemID = list_areas_->count();
  840. QString label;
  841. label.append(QString("%1: ").arg(itemID));
  842. label.append(QString("BBox #%1; ").arg(anID));
  843. label.append(QString("LabelID: %1; ").arg(aBBox.label_ID_));
  844. label.append(
  845. QString("data:%1;%2;%3;%4; ").
  846. arg(aBBox.rect.topLeft().x()).
  847. arg(aBBox.rect.topLeft().y()).
  848. arg(aBBox.rect.width()).
  849. arg(aBBox.rect.height())
  850. );
  851. newItem->setText(label);
  852. //newItem->setFlags(newItem->flags() | Qt::ItemIsEditable);
  853. list_areas_->insertItem(itemID, newItem);
  854. list_areas_->setItemSelected(newItem, true);
  855. }
  856. void
  857. ImageLabeler::addPolyArea(
  858. int aPolyID,
  859. Polygon aPoly,
  860. int itemID
  861. )
  862. {
  863. QListWidgetItem *newItem = new QListWidgetItem;
  864. if (-1 == itemID)
  865. itemID = list_areas_->count();
  866. QString label;
  867. label.append(QString("%1: ").arg(itemID));
  868. label.append(QString("Poly #%1; ").arg(aPolyID));
  869. label.append(QString("LabelID: %1; ").arg(aPoly.label_ID_));
  870. label.append("points:");
  871. for (int i = 0; i < aPoly.poly.count(); i++) {
  872. label.append(
  873. QString("%1;%2;").
  874. arg(aPoly.poly.point(i).x()).
  875. arg(aPoly.poly.point(i).y())
  876. );
  877. }
  878. newItem->setText(label);
  879. //newItem->setFlags(newItem->flags() | Qt::ItemIsEditable);
  880. list_areas_->insertItem(itemID, newItem);
  881. list_areas_->setItemSelected(newItem, true);
  882. }
  883. void
  884. ImageLabeler::editArea()
  885. {
  886. bool oldState = list_areas_->blockSignals(true);
  887. if (!list_areas_->currentItem() || !list_areas_->count()) {
  888. return;
  889. /* NOTREACHED */
  890. }
  891. QListWidgetItem *current = list_areas_->currentItem();
  892. old_area_string_ = current->text();
  893. current->setFlags(current->flags() | Qt::ItemIsEditable);
  894. list_areas_->editItem(current);
  895. list_areas_->blockSignals(oldState);
  896. }
  897. void
  898. ImageLabeler::onAreaItemChange(QListWidgetItem *anItem)
  899. {
  900. list_areas_->blockSignals(true);
  901. QString areaString = anItem->text();
  902. int oldID = -1;
  903. if (-1 != areaString.indexOf("Poly")) {
  904. Polygon *poly = new Polygon;
  905. *poly = polyFromString(&areaString, &oldID);
  906. if (-1 < poly->label_ID_ && !poly->poly.isEmpty() &&
  907. -1 < oldID) {
  908. list_polygon_.takeAt(oldID);
  909. list_polygon_.insert(oldID, poly);
  910. }
  911. else
  912. anItem->setText(old_area_string_);
  913. }
  914. else if (-1 != areaString.indexOf("BBox")) {
  915. BoundingBox *bbox = new BoundingBox;
  916. *bbox = BBoxFromString(&areaString, &oldID);
  917. if (-1 < bbox->label_ID_ && -1 < oldID) {
  918. list_bounding_box_.takeAt(oldID);
  919. list_bounding_box_.insert(oldID, bbox);
  920. }
  921. else
  922. anItem->setText(old_area_string_);
  923. }
  924. else {
  925. showWarning(tr("record format is corrupted, try again"));
  926. anItem->setText(old_area_string_);
  927. }
  928. anItem->setFlags(anItem->flags() ^ Qt::ItemIsEditable);
  929. list_areas_->blockSignals(false);
  930. image_holder_->update();
  931. unsaved_data_ = 1;
  932. }
  933. void
  934. ImageLabeler::onAreaEdit()
  935. {
  936. if (!list_areas_->count() ||
  937. -1 == image_holder_->focusedSelection()) {
  938. //showWarning(tr("You haven't added any label"));
  939. return;
  940. /* NOTREACHED */
  941. }
  942. int figureID = image_holder_->focusedSelection();
  943. Figure figure = image_holder_->focusedSelectionType();
  944. for (int i = 0; i < list_areas_->count(); i++) {
  945. QListWidgetItem *item = list_areas_->item(i);
  946. QString text = item->text();
  947. if (RectFigure == figure && -1 != text.indexOf("BBox")) {
  948. bool ok = 0;
  949. int num = getNumFromString(&text, "BBox #", ";", &ok);
  950. if (ok && num == figureID) {
  951. list_areas_->takeItem(i);
  952. addBBoxArea(num, *list_bounding_box_.at(num), i);
  953. }
  954. }
  955. else if (PolyFigure == figure && -1 != text.indexOf("Poly")) {
  956. bool ok = 0;
  957. int num = getNumFromString(&text, "Poly #", ";", &ok);
  958. if (ok && num == figureID) {
  959. list_areas_->takeItem(i);
  960. addPolyArea(num, *list_polygon_.at(num), i);
  961. }
  962. }
  963. }
  964. unsaved_data_ = 1;
  965. }
  966. void
  967. ImageLabeler::deleteArea()
  968. {
  969. if (!list_areas_->currentItem() || !list_areas_->count()) {
  970. return;
  971. /* NOTREACHED */
  972. }
  973. QString text = list_areas_->currentItem()->text();
  974. bool ok = 0;
  975. //int labelID = getNumFromString(&text, "LabelID:", ";", &ok);
  976. // if (!ok) {
  977. // return;
  978. // /* NOTREACHED */
  979. // }
  980. /*
  981. * 0 - bbox
  982. * 1 - poly
  983. */
  984. QString shape;
  985. if (-1 != text.indexOf("BBox"))
  986. shape = QString("BBox");
  987. else if (-1 != text.indexOf("Poly"))
  988. shape = QString("Poly");
  989. else {
  990. return;
  991. /* NOTREACHED */
  992. }
  993. int areaNum = getNumFromString(&text, "#", ";", &ok);
  994. if (!ok) {
  995. return;
  996. /* NOTREACHED */
  997. }
  998. int currentItemRow = list_areas_->row(list_areas_->currentItem());
  999. /* changing all shapes(depends on current) which are next in the list */
  1000. for (int i = list_areas_->count() - 1; i > currentItemRow; i--) {
  1001. QListWidgetItem item = *(list_areas_->item(i));
  1002. QString newText = item.text();
  1003. if (-1 == newText.indexOf(shape))
  1004. continue;
  1005. int num = getNumFromString(&newText, "#", ";", &ok);
  1006. num--;
  1007. QString numString = QString("%1").arg(num);
  1008. int numPos = newText.indexOf("#") + 1;
  1009. newText.replace(numPos, numString.size(), numString);
  1010. list_areas_->takeItem(i);
  1011. list_areas_->insertItem(i, newText);
  1012. }
  1013. list_areas_->takeItem(currentItemRow);
  1014. if (shape == "BBox")
  1015. list_bounding_box_.removeAt(areaNum);
  1016. else
  1017. list_polygon_.removeAt(areaNum);
  1018. image_holder_->update();
  1019. unsaved_data_ = 1;
  1020. }
  1021. void
  1022. ImageLabeler::toggleLabelPriority()
  1023. {
  1024. if (!list_label_->count()) {
  1025. return;
  1026. /* NOTREACHED */
  1027. }
  1028. QListWidgetItem *item = list_label_->currentItem();
  1029. /* because we need to keep BACKGROUND category */
  1030. if (0 == list_label_->row(item)) {
  1031. return;
  1032. /* NOTREACHED */
  1033. }
  1034. int itemRow = list_label_->row(item);
  1035. QString text = item->text();
  1036. /* cleaning previous " #main" mark */
  1037. if (-1 != main_label_) {
  1038. QListWidgetItem *lastMain = list_label_->item(main_label_);
  1039. QString lastMainText = lastMain->text();
  1040. int mainPos = lastMainText.indexOf(" #main");
  1041. lastMainText = lastMainText.mid(0, mainPos);
  1042. list_label_->blockSignals(true);
  1043. lastMain->setText(lastMainText);
  1044. list_label_->blockSignals(false);
  1045. }
  1046. if (main_label_ == itemRow) {
  1047. int mainPos = text.indexOf(" #main");
  1048. text = text.mid(0, mainPos);
  1049. main_label_ = -1;
  1050. }
  1051. else {
  1052. text.append(" #main");
  1053. main_label_ = list_label_->row(item);
  1054. }
  1055. list_label_->blockSignals(true);
  1056. item->setText(text);
  1057. list_label_->blockSignals(false);
  1058. image_holder_->update();
  1059. unsaved_data_ = 1;
  1060. }
  1061. void
  1062. ImageLabeler::getImagesFromDir(const QDir &dir)
  1063. {
  1064. /* avoiding freezing during recursive search for files */
  1065. QApplication::processEvents();
  1066. if (interrupt_search_) {
  1067. clearAll();
  1068. return;
  1069. }
  1070. QStringList filenameFilter;
  1071. filenameFilter <<
  1072. "*.jpeg" <<
  1073. "*.jpg" <<
  1074. "*.gif" <<
  1075. "*.png" <<
  1076. "*.bmp" <<
  1077. "*.tiff" <<
  1078. "*.dat"
  1079. ;
  1080. QStringList listImages =
  1081. dir.entryList(filenameFilter, QDir::Files);
  1082. QStringList ignoredFiles;
  1083. foreach (QString file, listImages) {
  1084. if (ignoredFiles.contains(file) ||
  1085. file.contains("_segmented", Qt::CaseInsensitive) ||
  1086. file.contains(".dat", Qt::CaseInsensitive)) {
  1087. continue;
  1088. }
  1089. Image newImage;
  1090. newImage.image_ = dir.absoluteFilePath(file);
  1091. /* TODO: think about loading pascal files */
  1092. newImage.pas_ = 0;
  1093. QString labeled = alterFileName(file, "_labeled");
  1094. labeled = removePath(labeled);
  1095. labeled.append(".dat");
  1096. if (listImages.contains(labeled, Qt::CaseInsensitive))
  1097. newImage.labeled_ = 1;
  1098. else
  1099. {
  1100. newImage.labeled_ = 0;
  1101. }
  1102. addImage(&newImage);
  1103. }
  1104. QStringList listDir = dir.entryList(QDir::Dirs);
  1105. foreach (QString subdir, listDir) {
  1106. if ("." == subdir || ".." == subdir)
  1107. continue;
  1108. getImagesFromDir(QDir(dir.absoluteFilePath(subdir)));
  1109. }
  1110. }
  1111. void
  1112. ImageLabeler::nextImage()
  1113. {
  1114. if (list_images_->isEmpty()) {
  1115. return;
  1116. /* NOTREACHED */
  1117. }
  1118. if (askForUnsavedData()) {
  1119. return;
  1120. /* NOTREACHED */
  1121. }
  1122. if (list_images_widget_->count() - 1 == image_ID_) {
  1123. //current_image_ = list_images_->at(0).image_;
  1124. image_ID_ = 0;
  1125. }
  1126. else {
  1127. image_ID_ ++;
  1128. //current_image_ = list_images_->at(image_ID_).image_;
  1129. }
  1130. if (!selectImage(image_ID_)) {
  1131. showWarning(tr("Next image is not available"));
  1132. return;
  1133. /* NOTREACHED */
  1134. }
  1135. list_images_widget_->setCurrentRow(image_ID_);
  1136. if (current_image_.isEmpty()) {
  1137. return;
  1138. /* NOTREACHED */
  1139. }
  1140. QString winTitle;
  1141. winTitle.append("ImageLabeler - ");
  1142. winTitle.append(current_image_);
  1143. setWindowTitle(winTitle);
  1144. image_->load(current_image_);
  1145. image_holder_->resize(image_->size());
  1146. image_holder_->setPixmap(*image_);
  1147. list_bounding_box_.clear();
  1148. list_polygon_.clear();
  1149. list_areas_->clear();
  1150. image_holder_->clearAll();
  1151. segmented_image_.clear();
  1152. clearLabelColorList();
  1153. //setWindowTitle(tr("ImageLabeler"));
  1154. }
  1155. void
  1156. ImageLabeler::prevImage()
  1157. {
  1158. if (!list_images_widget_->count()) {
  1159. return;
  1160. /* NOTREACHED */
  1161. }
  1162. if (askForUnsavedData()) {
  1163. return;
  1164. /* NOTREACHED */
  1165. }
  1166. if (!image_ID_) {
  1167. image_ID_ = list_images_widget_->count() - 1;
  1168. //current_image_ = list_images_->at(image_ID_).image_;
  1169. }
  1170. else {
  1171. image_ID_--;
  1172. //current_image_ = list_images_->at(image_ID_).image_;
  1173. }
  1174. list_images_widget_->setCurrentRow(image_ID_);
  1175. if (!selectImage(image_ID_)) {
  1176. showWarning(tr("Next image is not available"));
  1177. return;
  1178. /* NOTREACHED */
  1179. }
  1180. QString winTitle;
  1181. winTitle.append("ImageLabeler - ");
  1182. winTitle.append(current_image_);
  1183. setWindowTitle(winTitle);
  1184. image_->load(current_image_);
  1185. image_holder_->resize(image_->size());
  1186. image_holder_->setPixmap(*image_);
  1187. list_bounding_box_.clear();
  1188. list_polygon_.clear();
  1189. list_areas_->clear();
  1190. image_holder_->clearAll();
  1191. segmented_image_.clear();
  1192. clearLabelColorList();
  1193. //setWindowTitle(tr("ImageLabeler"));
  1194. }
  1195. void
  1196. ImageLabeler::saveAllInfo()
  1197. {
  1198. if (!list_images_widget_->count()) {
  1199. showWarning("You have not opened any image yet");
  1200. return;
  1201. /* NOTREACHED */
  1202. }
  1203. /* ------------------------------------------------------------------------
  1204. * XML part
  1205. */
  1206. QDomDocument doc(tr("ImageLabeler"));
  1207. QDomElement root = doc.createElement(tr("pixelwise_labeling"));
  1208. doc.appendChild(root);
  1209. QDomElement image = doc.createElement(tr("image"));
  1210. root.appendChild(image);
  1211. QDomText pathToImage = doc.createTextNode(current_image_);
  1212. image.appendChild(pathToImage);
  1213. if (!segmented_image_.isEmpty()) {
  1214. QDomElement segmentedImage = doc.createElement(tr("segmented"));
  1215. root.appendChild(segmentedImage);
  1216. QDomText pathToSegmented = doc.createTextNode(segmented_image_);
  1217. segmentedImage.appendChild(pathToSegmented);
  1218. }
  1219. QDomElement description = doc.createElement(tr("description"));
  1220. root.appendChild(description);
  1221. QDomText descriptionText = doc.createTextNode(image_description_);
  1222. description.appendChild(descriptionText);
  1223. QDomElement tags = doc.createElement(tr("tags"));
  1224. root.appendChild(tags);
  1225. QDomText tagsText = doc.createTextNode(tags_);
  1226. tags.appendChild(tagsText);
  1227. legendToXml(&doc, &root);
  1228. objectsToXml(&doc, &root);
  1229. setPureData();
  1230. QDomElement pureData = doc.createElement(tr("pure_data"));
  1231. QSize imageSize = image_->size();
  1232. QString pixelValues;
  1233. for (int i = 0; i < imageSize.height(); i++) {
  1234. for (int j = 0; j < imageSize.width(); j++) {
  1235. pixelValues.append(QString("%1").arg(pure_data_[i][j]));
  1236. //pixelValues.append(QString(""));
  1237. }
  1238. pixelValues.append("\n");
  1239. }
  1240. QDomText pureDataText = doc.createTextNode(pixelValues);
  1241. pureData.appendChild(pureDataText);
  1242. root.appendChild(pureData);
  1243. QString xml = doc.toString();
  1244. /* ------------------------------------------------------------------------
  1245. * XML part ends
  1246. */
  1247. QFileDialog fileDialog(0, tr("Save all info"));
  1248. fileDialog.setAcceptMode(QFileDialog::AcceptSave);
  1249. fileDialog.setDefaultSuffix("dat");
  1250. fileDialog.setFileMode(QFileDialog::AnyFile);
  1251. QString dir = getDirFromPath(&current_image_);
  1252. /* altering the name of a new file */
  1253. QString newFileName = alterFileName(current_image_, "_labeled");
  1254. newFileName = removePath(newFileName);
  1255. fileDialog.selectFile(newFileName);
  1256. fileDialog.setDirectory(dir);
  1257. QString filename;
  1258. if (fileDialog.exec()) {
  1259. filename = fileDialog.selectedFiles().last();
  1260. }
  1261. else {
  1262. //showWarning(tr("Can not open file dialog"));
  1263. return;
  1264. /* NOTREACHED */
  1265. }
  1266. if (filename.isEmpty()) {
  1267. return;
  1268. /* NOTREACHED */
  1269. }
  1270. QFile file(filename);
  1271. if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
  1272. showWarning(tr("Can not open file for writing"));
  1273. return;
  1274. /* NOTREACHED */
  1275. }
  1276. file.write(xml.toLocal8Bit());
  1277. file.close();
  1278. unsaved_data_ = 0;
  1279. }
  1280. void
  1281. ImageLabeler::saveSegmentedPicture()
  1282. {
  1283. if (list_bounding_box_.isEmpty() && list_polygon_.isEmpty()) {
  1284. return;
  1285. /* NOTREACHED */
  1286. }
  1287. setPureData();
  1288. // QString suffix = *current_image_;
  1289. // int dotPos = suffix.lastIndexOf(".");
  1290. // suffix.mid(dotPos + 1, suffix.size() - dotPos - 1);
  1291. QFileDialog fileDialog(0, tr("Save segmented picture"));
  1292. fileDialog.setAcceptMode(QFileDialog::AcceptSave);
  1293. fileDialog.setDefaultSuffix("png");
  1294. fileDialog.setFileMode(QFileDialog::AnyFile);
  1295. QString dir = getDirFromPath(&current_image_);
  1296. /* altering the name of a new file */
  1297. QString newFileName = alterFileName(current_image_, "_segmented");
  1298. newFileName = removePath(newFileName);
  1299. fileDialog.selectFile(newFileName);
  1300. fileDialog.setDirectory(dir);
  1301. QString filename;
  1302. if (fileDialog.exec()) {
  1303. filename = fileDialog.selectedFiles().last();
  1304. }
  1305. else {
  1306. return;
  1307. /* NOTREACHED */
  1308. }
  1309. QSize imageSize = image_holder_->pixmap()->size();
  1310. QImage newImage(imageSize, QImage::Format_RGB32);
  1311. bool generateColorsFlag = auto_color_generation_;
  1312. bool flag = 0;
  1313. /* checking if all the colors are are different from white(default) */
  1314. if (!generateColorsFlag) {
  1315. for (int i = 1; i < list_label_->count(); i++) {
  1316. if (list_label_colors_.at(i) == 0xffffffff && !flag)
  1317. flag = 1;
  1318. else if (list_label_colors_.at(i) == 0xffffffff && flag) {
  1319. QMessageBox msgBox;
  1320. msgBox.setText(tr("There are few labels with default white color."));
  1321. msgBox.setInformativeText(tr("Do you want to generate all colors automatically? Otherwise you'll have to do it manually."));
  1322. msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
  1323. msgBox.setDefaultButton(QMessageBox::Yes);
  1324. msgBox.setIcon(QMessageBox::Question);
  1325. int ret = msgBox.exec();
  1326. if (QMessageBox::Yes == ret) {
  1327. generateColorsFlag = 1;
  1328. break;
  1329. }
  1330. else {
  1331. return;
  1332. /* NOTREACHED */
  1333. }
  1334. }
  1335. }
  1336. }
  1337. /* generating colors for labels */
  1338. if (list_label_colors_.count() < list_label_->count() ||
  1339. generateColorsFlag) {
  1340. generateColors();
  1341. }
  1342. for (int i = 0; i < imageSize.height(); i++)
  1343. for (int j = 0; j < imageSize.width(); j++) {
  1344. newImage.setPixel(j, i, list_label_colors_.at(pure_data_[i][j]));
  1345. }
  1346. if (!newImage.save(filename, "png", 100)) {
  1347. showWarning(tr("An error occurred while saving the segmented image"));
  1348. return;
  1349. /* NOTREACHED */
  1350. }
  1351. segmented_image_ = filename;
  1352. action_view_segmented_->setEnabled(true);
  1353. }
  1354. void
  1355. ImageLabeler::saveLegend()
  1356. {
  1357. if (!list_label_->count()) {
  1358. showWarning("You have not added any label yet");
  1359. return;
  1360. /* NOTREACHED */
  1361. }
  1362. /* ------------------------------------------------------------------------
  1363. * XML part
  1364. */
  1365. QDomDocument doc(tr("ImageLabeler"));
  1366. QDomElement root = doc.createElement(tr("root"));
  1367. doc.appendChild(root);
  1368. legendToXml(&doc, &root);
  1369. QString xml = doc.toString();
  1370. /* ------------------------------------------------------------------------
  1371. * XML part ends
  1372. */
  1373. QFileDialog fileDialog(0, tr("Save legend"));
  1374. fileDialog.setAcceptMode(QFileDialog::AcceptSave);
  1375. fileDialog.setDefaultSuffix("dat");
  1376. fileDialog.setFileMode(QFileDialog::AnyFile);
  1377. QString dir = getDirFromPath(&current_image_);
  1378. /* altering the name of a new file */
  1379. QString newFileName = alterFileName(current_image_, "_legend");
  1380. newFileName = removePath(newFileName);
  1381. fileDialog.selectFile(newFileName);
  1382. fileDialog.setDirectory(dir);
  1383. QString filename;
  1384. if (fileDialog.exec()) {
  1385. filename = fileDialog.selectedFiles().last();
  1386. }
  1387. else {
  1388. //showWarning(tr("Can not open file dialog"));
  1389. return;
  1390. /* NOTREACHED */
  1391. }
  1392. if (filename.isEmpty()) {
  1393. return;
  1394. /* NOTREACHED */
  1395. }
  1396. QFile file(filename);
  1397. if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
  1398. showWarning(tr("Can not open file for writing"));
  1399. return;
  1400. /* NOTREACHED */
  1401. }
  1402. file.write(xml.toLocal8Bit());
  1403. file.close();
  1404. }
  1405. void
  1406. ImageLabeler::loadInfo()
  1407. {
  1408. if (askForUnsavedData()) {
  1409. return;
  1410. /* NOTREACHED */
  1411. }
  1412. QFileDialog fileDialog(0, tr("Load file with info"));
  1413. fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
  1414. fileDialog.setDefaultSuffix("dat");
  1415. fileDialog.setFileMode(QFileDialog::AnyFile);
  1416. QString filename;
  1417. if (fileDialog.exec()) {
  1418. filename = fileDialog.selectedFiles().last();
  1419. }
  1420. else {
  1421. //showWarning(tr("Can not open file dialog"));
  1422. return;
  1423. /* NOTREACHED */
  1424. }
  1425. clearAllTool();
  1426. clearLabelList();
  1427. if (loadInfo(filename)) {
  1428. enableTools();
  1429. Image newImage;
  1430. newImage.image_ = current_image_;
  1431. newImage.labeled_ = 1;
  1432. newImage.pas_ = 0;
  1433. addImage(&newImage);
  1434. image_ID_ = list_images_widget_->count() - 1;
  1435. list_images_widget_->setCurrentRow(image_ID_);
  1436. }
  1437. unsaved_data_ = 0;
  1438. }
  1439. bool
  1440. ImageLabeler::loadInfo(QString filename)
  1441. {
  1442. QDomDocument doc("Image Labeler");
  1443. QFile file(filename);
  1444. if (!file.open(QIODevice::ReadOnly)) {
  1445. showWarning(tr("Can not open such file"));
  1446. return false;
  1447. /* NOTREACHED */
  1448. }
  1449. QString errMsg;
  1450. if (!doc.setContent(&file, &errMsg)) {
  1451. showWarning(errMsg);
  1452. file.close();
  1453. return false;
  1454. /* NOTREACHED */
  1455. }
  1456. file.close();
  1457. //clearAll();
  1458. //enableTools();
  1459. /* getting all info */
  1460. QDomElement elements = doc.documentElement();
  1461. QDomNode rootNode = elements.firstChild();
  1462. QString string;
  1463. while(!rootNode.isNull()) {
  1464. QDomElement element = rootNode.toElement();
  1465. if(!element.isNull()) {
  1466. /* path to the image */
  1467. if (element.tagName() == "image") {
  1468. string = element.text();
  1469. if (string.isEmpty()) {
  1470. showWarning(
  1471. tr(
  1472. "The file with data doesn't contain path to the image"
  1473. )
  1474. );
  1475. return false;
  1476. /* NOTREACHED */
  1477. }
  1478. if (!image_->load(string)) {
  1479. return false;
  1480. /* NOTREACHED */
  1481. }
  1482. // Image newImage;
  1483. // newImage.image_ = string;
  1484. // newImage.labeled_ = 1;
  1485. // addImage(&newImage);
  1486. current_image_ = string;
  1487. // image_ID_ = list_images_widget_->count() - 1;
  1488. // list_images_widget_->setCurrentRow(image_ID_);
  1489. QString winTitle;
  1490. winTitle.append("ImageLabeler - ");
  1491. winTitle.append(current_image_);
  1492. setWindowTitle(winTitle);
  1493. image_holder_->resize(image_->size());
  1494. image_holder_->setPixmap(*image_);
  1495. }
  1496. /* path to the segmented image */
  1497. if (element.tagName() == "segmented") {
  1498. string = element.text();
  1499. if (string.isEmpty()) {
  1500. continue;
  1501. }
  1502. segmented_image_ = string;
  1503. action_view_segmented_->setEnabled(true);
  1504. }
  1505. /* image description */
  1506. else if (element.tagName() == "description" &&
  1507. !element.text().isEmpty()) {
  1508. image_description_ = element.text();
  1509. }
  1510. /* legend */
  1511. else if (element.tagName() == "legend") {
  1512. loadLegendFromNode(&element);
  1513. }
  1514. /* objects */
  1515. else if (element.tagName() == "objects") {
  1516. QDomNode subNode = element.firstChild();
  1517. QDomElement subElement;
  1518. while(!subNode.isNull()) {
  1519. subElement = subNode.toElement();
  1520. if (subElement.isNull() || subElement.text().isEmpty()) {
  1521. subNode = subNode.nextSibling();
  1522. continue;
  1523. }
  1524. string = subElement.attribute("id");
  1525. bool ok = 1;
  1526. int id = string.toInt(&ok, 10);
  1527. if (!ok) {
  1528. qDebug() <<
  1529. "loadInfo: "
  1530. "poly id format is corrupted";
  1531. subNode = subNode.nextSibling();
  1532. continue;
  1533. }
  1534. string = subElement.text();
  1535. if (subElement.tagName() == "bbox") {
  1536. addBBoxFromData(&string, &id);
  1537. }
  1538. if (subElement.tagName() == "poly") {
  1539. addPolyFromData(&string, &id);
  1540. }
  1541. subNode = subNode.nextSibling();
  1542. }
  1543. }
  1544. }
  1545. rootNode = rootNode.nextSibling();
  1546. }
  1547. unsaved_data_ = 0;
  1548. return true;
  1549. }
  1550. void
  1551. ImageLabeler::loadPascalFile()
  1552. {
  1553. if (askForUnsavedData()) {
  1554. return;
  1555. /* NOTREACHED */
  1556. }
  1557. QFileDialog fileDialog(0, tr("Load pascal file"));
  1558. fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
  1559. fileDialog.setDefaultSuffix("xml");
  1560. fileDialog.setFileMode(QFileDialog::AnyFile);
  1561. QStringList filters;
  1562. filters << "PASCAL xml data (*.xml)"
  1563. << "Any files (*)";
  1564. fileDialog.setNameFilters(filters);
  1565. QString filename;
  1566. if (fileDialog.exec()) {
  1567. filename = fileDialog.selectedFiles().last();
  1568. }
  1569. else {
  1570. //showWarning(tr("Can not open file dialog"));
  1571. return;
  1572. /* NOTREACHED */
  1573. }
  1574. clearAllTool();
  1575. clearLabelList();
  1576. if (loadPascalFile(filename)) {
  1577. enableTools();
  1578. Image newImage;
  1579. newImage.image_ = current_image_;
  1580. newImage.labeled_ = 1;
  1581. newImage.pas_ = 1;
  1582. addImage(&newImage);
  1583. image_ID_ = list_images_widget_->count() - 1;
  1584. list_images_widget_->setCurrentRow(image_ID_);
  1585. }
  1586. unsaved_data_ = 0;
  1587. }
  1588. bool
  1589. ImageLabeler::loadPascalFile(QString aFilename)
  1590. {
  1591. QDomDocument doc;
  1592. QFile file(aFilename);
  1593. if (!file.open(QIODevice::ReadOnly)) {
  1594. showWarning(tr("Can not open such file"));
  1595. return false;
  1596. /* NOTREACHED */
  1597. }
  1598. QString errMsg;
  1599. if (!doc.setContent(&file, &errMsg)) {
  1600. showWarning(errMsg);
  1601. file.close();
  1602. return false;
  1603. /* NOTREACHED */
  1604. }
  1605. file.close();
  1606. //clearAll();
  1607. //enableTools();
  1608. /* getting all info */
  1609. QDomElement elements = doc.documentElement();
  1610. QDomNode rootNode = elements.firstChild();
  1611. QString string;
  1612. QString path = getPathFromFilename(aFilename);
  1613. QString filename;
  1614. QStringList labels;
  1615. labels << "BACKGROUND";
  1616. int labelID;
  1617. while(!rootNode.isNull()) {
  1618. QDomElement element = rootNode.toElement();
  1619. if(!element.isNull()) {
  1620. /* folder */
  1621. if (element.tagName() == "folder") {
  1622. string = element.text();
  1623. if (!string.isEmpty()) {
  1624. path.append(string);
  1625. }
  1626. }
  1627. /* filename */
  1628. else if (element.tagName() == "filename") {
  1629. string = element.text();
  1630. if (!string.isEmpty()) {
  1631. filename = string;
  1632. }
  1633. }
  1634. /* object */
  1635. else if (element.tagName() == "object") {
  1636. QDomNode subNode = element.firstChild();
  1637. QDomElement subElement;
  1638. while(!subNode.isNull()) {
  1639. subElement = subNode.toElement();
  1640. if (subElement.isNull() || subElement.text().isEmpty()) {
  1641. subNode = subNode.nextSibling();
  1642. continue;
  1643. }
  1644. /* label */
  1645. if (subElement.tagName() == "name") {
  1646. string = subElement.text();
  1647. if (!string.isEmpty() &&
  1648. !labels.contains(string, Qt::CaseInsensitive))
  1649. {
  1650. addLabel(list_label_->count(), 0, string);
  1651. labelID = labels.count();
  1652. labels << string;
  1653. }
  1654. else if (labels.contains(string, Qt::CaseInsensitive)) {
  1655. for (int i = 0; i < labels.count(); i++) {
  1656. if (labels.at(i) == string)
  1657. labelID = i;
  1658. }
  1659. }
  1660. }
  1661. if (subElement.tagName() == "bndbox") {
  1662. /* 2 points */
  1663. QPoint topLeft;
  1664. QPoint bottomRight;
  1665. QDomNode bboxNode = subElement.firstChild();
  1666. QDomElement bboxElement;
  1667. while(!bboxNode.isNull()) {
  1668. bboxElement = bboxNode.toElement();
  1669. string.clear();
  1670. bool ok = 1;
  1671. if (bboxElement.tagName() == "xmin") {
  1672. string = bboxElement.text();
  1673. if (string.isEmpty())
  1674. ok = 0;
  1675. double xmin = string.toDouble(&ok);
  1676. if (ok)
  1677. topLeft.setX(qRound(xmin));
  1678. }
  1679. else if (bboxElement.tagName() == "ymin") {
  1680. string = bboxElement.text();
  1681. if (string.isEmpty())
  1682. ok = 0;
  1683. double ymin = string.toDouble(&ok);
  1684. if (ok)
  1685. topLeft.setY(qRound(ymin));
  1686. }
  1687. else if (bboxElement.tagName() == "xmax") {
  1688. string = bboxElement.text();
  1689. if (string.isEmpty())
  1690. ok = 0;
  1691. double xmax = string.toDouble(&ok);
  1692. if (ok)
  1693. bottomRight.setX(qRound(xmax));
  1694. }
  1695. else if (bboxElement.tagName() == "ymax") {
  1696. string = bboxElement.text();
  1697. if (string.isEmpty())
  1698. ok = 0;
  1699. double ymax = string.toDouble(&ok);
  1700. if (ok)
  1701. bottomRight.setY(qRound(ymax));
  1702. }
  1703. if (string.isEmpty() || !ok)
  1704. break;
  1705. bboxNode = bboxNode.nextSibling();
  1706. if (bboxNode.isNull()) {
  1707. BoundingBox *bbox = new BoundingBox;
  1708. bbox->rect.setTopLeft(topLeft);
  1709. bbox->rect.setBottomRight(bottomRight);
  1710. bbox->label_ID_ = labelID;
  1711. addBBox(bbox);
  1712. }
  1713. }
  1714. }
  1715. subNode = subNode.nextSibling();
  1716. }
  1717. }
  1718. }
  1719. rootNode = rootNode.nextSibling();
  1720. }
  1721. if (!image_->load(path + "/" + filename)) {
  1722. return false;
  1723. /* NOTREACHED */
  1724. }
  1725. current_image_ = path + filename;
  1726. QString winTitle;
  1727. winTitle.append("ImageLabeler - ");
  1728. winTitle.append(current_image_);
  1729. setWindowTitle(winTitle);
  1730. image_holder_->resize(image_->size());
  1731. image_holder_->setPixmap(*image_);
  1732. unsaved_data_ = 0;
  1733. return true;
  1734. }
  1735. void
  1736. ImageLabeler::loadPascalPolys()
  1737. {
  1738. if (current_image_.isEmpty()) {
  1739. return;
  1740. /* NOTREACHED */
  1741. }
  1742. QFileDialog fileDialog(0, tr("Load pascal polygons"));
  1743. fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
  1744. fileDialog.setDefaultSuffix("polygon");
  1745. fileDialog.setFileMode(QFileDialog::AnyFile);
  1746. QStringList filters;
  1747. filters << "PASCAL polygons (*.polygon)"
  1748. << "Any files (*)";
  1749. fileDialog.setNameFilters(filters);
  1750. QString filename;
  1751. if (fileDialog.exec()) {
  1752. filename = fileDialog.selectedFiles().last();
  1753. }
  1754. else {
  1755. //showWarning(tr("Can not open file dialog"));
  1756. return;
  1757. /* NOTREACHED */
  1758. }
  1759. //clearAllTool();
  1760. //clearLabelList();
  1761. if (!loadPascalPolys(filename)) {
  1762. showWarning(tr("File format is corrupted."));
  1763. }
  1764. unsaved_data_ = 0;
  1765. image_holder_->update();
  1766. }
  1767. bool
  1768. ImageLabeler::loadPascalPolys(QString aFilename)
  1769. {
  1770. QFile file(aFilename);
  1771. if (!file.open(QIODevice::ReadOnly)) {
  1772. showWarning(tr("Can not open such file"));
  1773. return false;
  1774. /* NOTREACHED */
  1775. }
  1776. QByteArray data = file.readAll();
  1777. file.close();
  1778. QString label;
  1779. int lastSpace = 0;
  1780. int pointCount = 0;
  1781. Polygon *poly = 0;
  1782. QPoint point;
  1783. bool evenFlag = 0;
  1784. //for (int i = 0; i < data.length(); i++) {
  1785. int i = 0;
  1786. while (i < data.length()) {
  1787. if (data.at(i) == ' ' && label.isEmpty() && !pointCount) {
  1788. label = QString(data.mid(lastSpace, i - lastSpace));
  1789. lastSpace = i + 1;
  1790. }
  1791. else if (data.at(i) == ' ' && !label.isEmpty() && !pointCount) {
  1792. QString num = QString(data.mid(lastSpace, i - lastSpace));
  1793. bool ok = 1;
  1794. pointCount = num.toInt(&ok, 10);
  1795. if (!ok) {
  1796. return false;
  1797. /* NOTREACHED */
  1798. }
  1799. poly = new Polygon;
  1800. poly->label_ID_ = -1;
  1801. lastSpace = i + 1;
  1802. }
  1803. else if (data.at(i) == ' ' &&
  1804. !label.isEmpty() &&
  1805. pointCount &&
  1806. !evenFlag)
  1807. {
  1808. evenFlag = 1;
  1809. QString num = QString(data.mid(lastSpace, i - lastSpace));
  1810. bool ok = 1;
  1811. int coor = qRound(num.toDouble(&ok));
  1812. if (!ok) {
  1813. return false;
  1814. /* NOTREACHED */
  1815. }
  1816. point.setX(coor);
  1817. lastSpace = i + 1;
  1818. }
  1819. else if (data.at(i) == ' ' &&
  1820. !label.isEmpty() &&
  1821. pointCount &&
  1822. evenFlag)
  1823. {
  1824. evenFlag = 0;
  1825. pointCount--;
  1826. QString num = QString(data.mid(lastSpace, i - lastSpace));
  1827. bool ok = 1;
  1828. int coor = qRound(num.toDouble(&ok));
  1829. if (!ok) {
  1830. return false;
  1831. /* NOTREACHED */
  1832. }
  1833. point.setY(coor);
  1834. lastSpace = i + 1;
  1835. poly->poly << point;
  1836. }
  1837. else if (data.at(i) == '\n') {
  1838. if (pointCount || !poly) {
  1839. return false;
  1840. /* NOTREACHED */
  1841. }
  1842. lastSpace = i + 1;
  1843. for (int j = 0; j < list_label_->count(); j++) {
  1844. if (list_label_->item(j)->text().contains(label, Qt::CaseInsensitive)) {
  1845. poly->label_ID_ = j;
  1846. }
  1847. }
  1848. if (-1 == poly->label_ID_) {
  1849. int labelID = list_label_->count();
  1850. addLabel(labelID, 0, label);
  1851. poly->label_ID_ = labelID;
  1852. }
  1853. addPoly(poly);
  1854. label.clear();
  1855. }
  1856. i++;
  1857. }
  1858. //clearAll();
  1859. //enableTools();
  1860. return true;
  1861. }
  1862. void
  1863. ImageLabeler::loadImage()
  1864. {
  1865. if (askForUnsavedData()) {
  1866. return;
  1867. /* NOTREACHED */
  1868. }
  1869. QFileDialog fileDialog(0, tr("Load image"));
  1870. fileDialog.setFileMode(QFileDialog::ExistingFile);
  1871. QStringList filters;
  1872. filters << "Image files (*.jpeg *.jpg *.gif *.png *.bmp *.tiff)"
  1873. << "Any files (*)";
  1874. fileDialog.setNameFilters(filters);
  1875. QString filename;
  1876. if (fileDialog.exec()) {
  1877. filename = fileDialog.selectedFiles().last();
  1878. }
  1879. else {
  1880. //showWarning(tr("Could not open file dialog"));
  1881. return;
  1882. /* NOTREACHED */
  1883. }
  1884. if (filename.isEmpty()) {
  1885. return;
  1886. /* NOTREACHED */
  1887. }
  1888. QString dirPath = getPathFromFilename(filename);
  1889. QDir dir(dirPath);
  1890. QStringList filter;
  1891. filter << "*.dat";
  1892. QStringList fileList = dir.entryList(filter, QDir::Files);
  1893. QString labeled = alterFileName(filename, "_labeled");
  1894. labeled = removePath(labeled);
  1895. labeled.append(".dat");
  1896. if (fileList.contains(labeled, Qt::CaseInsensitive)) {
  1897. labeled = dir.absoluteFilePath(labeled);
  1898. loadInfo(labeled);
  1899. Image *newImage = new Image;
  1900. newImage->image_ = filename;
  1901. newImage->labeled_ = 1;
  1902. newImage->pas_ = 0;
  1903. addImage(newImage);
  1904. enableTools();
  1905. return;
  1906. /* NOTREACHED */
  1907. }
  1908. clearAllTool();
  1909. QString winTitle;
  1910. winTitle.append("ImageLabeler - ");
  1911. winTitle.append(current_image_);
  1912. setWindowTitle(winTitle);
  1913. if (!image_->load(filename)) {
  1914. return;
  1915. /* NOTREACHED */
  1916. }
  1917. image_holder_->resize(image_->size());
  1918. image_holder_->setPixmap(*image_);
  1919. current_image_ = filename;
  1920. image_ID_ = list_images_widget_->count() - 1;
  1921. list_images_widget_->setCurrentRow(image_ID_);
  1922. Image *newImage = new Image;
  1923. newImage->image_ = filename;
  1924. newImage->labeled_ = 0;
  1925. newImage->pas_ = 0;
  1926. addImage(newImage);
  1927. if (!list_images_widget_->count()) {
  1928. return;
  1929. /* NOTREACHED */
  1930. }
  1931. enableTools();
  1932. }
  1933. void
  1934. ImageLabeler::loadImages()
  1935. {
  1936. if (askForUnsavedData()) {
  1937. return;
  1938. /* NOTREACHED */
  1939. }
  1940. QFileDialog fileDialog(0, tr("Load images"));
  1941. fileDialog.setFileMode(QFileDialog::Directory);
  1942. QString dirName("");
  1943. if (fileDialog.exec()) {
  1944. /* TODO: make it possible to select multiple folders */
  1945. dirName = fileDialog.selectedFiles().last();
  1946. }
  1947. else {
  1948. //showWarning(tr("Could not open file dialog"));
  1949. return;
  1950. /* NOTREACHED */
  1951. }
  1952. clearAllTool();
  1953. QWidget *searchInProgress = new QWidget(0);
  1954. searchInProgress->setWindowTitle(tr("Loading images"));
  1955. QLabel *info = new QLabel(searchInProgress);
  1956. info->setText(
  1957. tr("Program is looking for all image files in your directory recursively."));
  1958. QPushButton *cancel = new QPushButton(tr("Cancel"), searchInProgress);
  1959. connect(cancel, SIGNAL(clicked()), this, SLOT(interruptSearch()));
  1960. QVBoxLayout *layout = new QVBoxLayout(searchInProgress);
  1961. searchInProgress->setLayout(layout);
  1962. layout->addWidget(info);
  1963. layout->addWidget(cancel);
  1964. searchInProgress->adjustSize();
  1965. searchInProgress->move(QApplication::desktop()->screen()->rect().center() - rect().center());
  1966. searchInProgress->show();
  1967. getImagesFromDir(QDir(dirName));
  1968. cancel->disconnect();
  1969. searchInProgress->hide();
  1970. delete info;
  1971. delete cancel;
  1972. delete layout;
  1973. delete searchInProgress;
  1974. if (interrupt_search_) {
  1975. interrupt_search_ = 0;
  1976. return;
  1977. /* NOTREACHED */
  1978. }
  1979. if (!list_images_widget_->count()) {
  1980. showWarning(tr("The folder you selected contains no images"));
  1981. return;
  1982. /* NOTREACHED */
  1983. }
  1984. bool ret = 0;
  1985. if (list_images_->at(0).labeled_) {
  1986. QString labeled =
  1987. alterFileName(list_images_->at(0).image_, "_labeled");
  1988. labeled.append(".dat");
  1989. ret = loadInfo(labeled);
  1990. }
  1991. else
  1992. ret = image_->load(list_images_->at(0).image_);
  1993. if (!ret) {
  1994. return;
  1995. /* NOTREACHED */
  1996. }
  1997. current_image_ = list_images_->at(0).image_;
  1998. image_ID_ = 0;
  1999. list_images_widget_->setCurrentRow(image_ID_);
  2000. QString winTitle;
  2001. winTitle.append("ImageLabeler - ");
  2002. winTitle.append(current_image_);
  2003. setWindowTitle(winTitle);
  2004. image_holder_->resize(image_->size());
  2005. image_holder_->setPixmap(*image_);
  2006. enableTools();
  2007. }
  2008. void
  2009. ImageLabeler::loadLegendFromFile()
  2010. {
  2011. QFileDialog fileDialog(0, tr("Load legend"));
  2012. fileDialog.setFileMode(QFileDialog::AnyFile);
  2013. QString filename;
  2014. if (fileDialog.exec()) {
  2015. filename = fileDialog.selectedFiles().last();
  2016. }
  2017. else {
  2018. //showWarning(tr("Could not open file dialog"));
  2019. return;
  2020. /* NOTREACHED */
  2021. }
  2022. QDomDocument doc("Image Labeler");
  2023. QFile file(filename);
  2024. if (!file.open(QIODevice::ReadOnly)) {
  2025. showWarning(tr("Can not open such file"));
  2026. return;
  2027. /* NOTREACHED */
  2028. }
  2029. QString errMsg;
  2030. if (!doc.setContent(&file, &errMsg)) {
  2031. showWarning(errMsg);
  2032. file.close();
  2033. return;
  2034. /* NOTREACHED */
  2035. }
  2036. file.close();
  2037. list_label_->clear();
  2038. /* getting legend */
  2039. QDomElement elements = doc.documentElement();
  2040. QDomNode rootNode = elements.firstChild();
  2041. QString string;
  2042. while(!rootNode.isNull()) {
  2043. QDomElement element = rootNode.toElement();
  2044. if(!element.isNull()) {
  2045. if (element.tagName() == "legend") {
  2046. loadLegendFromNode(&element);
  2047. }
  2048. }
  2049. rootNode = rootNode.nextSibling();
  2050. }
  2051. }
  2052. void
  2053. ImageLabeler::loadLegendFromNode(QDomElement *anElement)
  2054. {
  2055. if (!anElement) {
  2056. return;
  2057. /* NOTREACHED */
  2058. }
  2059. QDomNode subNode = anElement->firstChild();
  2060. QDomElement subElement;
  2061. QString string;
  2062. int id = -1;
  2063. bool isMain;
  2064. uint color = 0xff000000;
  2065. while(!subNode.isNull()) {
  2066. subElement = subNode.toElement();
  2067. if (!subElement.isNull() && !subElement.text().isEmpty()) {
  2068. string = subElement.attribute("id");
  2069. bool ok = 0;
  2070. id = string.toInt(&ok, 10);
  2071. if (!ok) {
  2072. qDebug() <<
  2073. "loadLegendFromNode: "
  2074. "label id format is corrupted";
  2075. subNode = subNode.nextSibling();
  2076. continue;
  2077. }
  2078. string = subElement.attribute("isMain");
  2079. isMain = string.toInt(&ok, 2);
  2080. if (!ok) {
  2081. qDebug() <<
  2082. "loadLegendFromNode: "
  2083. "label isMain flag format is corrupted";
  2084. subNode = subNode.nextSibling();
  2085. continue;
  2086. }
  2087. string = subElement.attribute("color");
  2088. color = string.toUInt(&ok, 16);
  2089. if (!ok) {
  2090. qDebug() <<
  2091. "loadLegendFromNode: "
  2092. "label color format is corrupted";
  2093. subNode = subNode.nextSibling();
  2094. continue;
  2095. }
  2096. string = subElement.text();
  2097. addLabel(id, isMain, string);
  2098. setLabelColor(id, color);
  2099. }
  2100. subNode = subNode.nextSibling();
  2101. }
  2102. }
  2103. void
  2104. ImageLabeler::legendToXml(QDomDocument *aDoc, QDomElement *aRoot)
  2105. {
  2106. QDomElement legend = aDoc->createElement(tr("legend"));
  2107. aRoot->appendChild(legend);
  2108. /* storing all labels made by user */
  2109. int labelCount = list_label_->count();
  2110. for (int i = 0; i < labelCount; i++) {
  2111. QDomElement label = aDoc->createElement(tr("label"));
  2112. label.setAttribute("color", QString("%1").arg(list_label_colors_.at(i), 0, 16));
  2113. label.setAttribute("id", i);
  2114. QString priority;
  2115. if (main_label_ == i)
  2116. priority.append("1");
  2117. else
  2118. priority.append("0");
  2119. label.setAttribute("isMain", priority);
  2120. QString labelText = list_label_->item(i)->text();
  2121. /* removing the number prefix of label */
  2122. if (-1 != labelText.indexOf(QString("%1: ").arg(i))) {
  2123. labelText = labelText.mid(3, labelText.size() - 3);
  2124. }
  2125. QDomText labelName = aDoc->createTextNode(labelText);
  2126. label.appendChild(labelName);
  2127. legend.appendChild(label);
  2128. }
  2129. /* in case we have no labels */
  2130. if (0 == labelCount) {
  2131. QDomElement label = aDoc->createElement(tr("label"));
  2132. label.setAttribute(tr("id"), -1);
  2133. legend.appendChild(label);
  2134. }
  2135. }
  2136. void
  2137. ImageLabeler::objectsToXml(QDomDocument *aDoc, QDomElement *aRoot)
  2138. {
  2139. QDomElement objects = aDoc->createElement(tr("objects"));
  2140. aRoot->appendChild(objects);
  2141. /* rects first */
  2142. for (int i = 0; i < list_bounding_box_.size(); i++) {
  2143. QDomElement rectData = aDoc->createElement(tr("bbox"));
  2144. rectData.setAttribute("id", list_bounding_box_.at(i)->label_ID_);
  2145. QRect rect = list_bounding_box_.at(i)->rect.normalized();
  2146. QString rectDataString =
  2147. QString("%1;%2;%3;%4;").
  2148. arg(rect.x()).
  2149. arg(rect.y()).
  2150. arg(rect.width()).
  2151. arg(rect.height());
  2152. QDomText rectDataText = aDoc->createTextNode(rectDataString);
  2153. rectData.appendChild(rectDataText);
  2154. objects.appendChild(rectData);
  2155. }
  2156. /* polys next */
  2157. for (int i = 0; i < list_polygon_.size(); i++) {
  2158. QDomElement polyData = aDoc->createElement(tr("poly"));
  2159. polyData.setAttribute("id", list_polygon_.at(i)->label_ID_);
  2160. QPolygon poly = list_polygon_.at(i)->poly;
  2161. QString polyDataString;
  2162. for (int j = 0; j < poly.count(); j++)
  2163. polyDataString.append(
  2164. QString("%1;%2;").
  2165. arg(poly.point(j).x()).
  2166. arg(poly.point(j).y())
  2167. );
  2168. QDomText polyDataText = aDoc->createTextNode(polyDataString);
  2169. polyData.appendChild(polyDataText);
  2170. objects.appendChild(polyData);
  2171. }
  2172. }
  2173. void
  2174. ImageLabeler::generateColors()
  2175. {
  2176. int labelCount = list_label_->count();
  2177. if (!labelCount) {
  2178. showWarning(tr("you have not added any labels yet"));
  2179. return;
  2180. /* NOTREACHED */
  2181. }
  2182. int coeff = (0xff / labelCount) * 3;
  2183. //QList< uint > colors;
  2184. list_label_colors_.clear();
  2185. list_label_colors_.append(0);
  2186. uchar red = 0xff;
  2187. uchar green = 0xff;
  2188. uchar blue = 0xff;
  2189. uchar iterationColor = coeff;
  2190. uint color = 0xffffffff;
  2191. int j = 1;
  2192. for (int i = 1; i < labelCount; i++) {
  2193. if (6 == j) {
  2194. iterationColor += coeff;
  2195. j = 1;
  2196. }
  2197. if (5 == j) {
  2198. red = 0xff - iterationColor;
  2199. green = 0xff - iterationColor;
  2200. blue = 0xff;
  2201. }
  2202. else if (4 == j) {
  2203. red = 0xff - iterationColor;
  2204. green = 0xff;
  2205. blue = 0xff - iterationColor;
  2206. }
  2207. else if (3 == j) {
  2208. red = 0xff - iterationColor;
  2209. green = 0xff;
  2210. blue = 0xff;
  2211. }
  2212. else if (2 == j) {
  2213. red = 0xff;
  2214. green = 0xff - iterationColor;
  2215. blue = 0xff;
  2216. }
  2217. else if (1 == j){
  2218. red = 0xff;
  2219. green = 0xff;
  2220. blue = 0xff - iterationColor;
  2221. }
  2222. j++;
  2223. color = red + (green * 0x100) + (blue * 0x10000) + 0xff000000;
  2224. int itemNo = list_label_colors_.count();
  2225. QPixmap iconPix = QPixmap(20, 20);
  2226. iconPix.fill(color);
  2227. QIcon icon(iconPix);
  2228. list_label_->item(itemNo)->setIcon(icon);
  2229. list_label_colors_.append(color);
  2230. }
  2231. image_holder_->update();
  2232. }
  2233. void
  2234. ImageLabeler::addBBoxFromData(
  2235. QString *aBBoxData,
  2236. int *ID
  2237. )
  2238. {
  2239. BoundingBox *bbox = new BoundingBox;
  2240. *bbox = BBoxFromData(aBBoxData);
  2241. if (!bbox->rect.isValid() || !ID) {
  2242. return;
  2243. /* NOTREACHED */
  2244. }
  2245. bbox->label_ID_ = *ID;
  2246. list_bounding_box_.append(bbox);
  2247. addBBoxArea(list_bounding_box_.count() - 1, *bbox);
  2248. }
  2249. BoundingBox
  2250. ImageLabeler::BBoxFromData(
  2251. QString *aBBoxData
  2252. )
  2253. {
  2254. BoundingBox bbox;
  2255. QString buffer;
  2256. bbox.rect.setRect(-1, -1, -1, -1);
  2257. int startPos = 0;
  2258. bool ok = 1;
  2259. for (int i = 0; i < aBBoxData->size(); i++) {
  2260. if (';' != aBBoxData->at(i))
  2261. continue;
  2262. buffer = aBBoxData->mid(startPos, i - startPos);
  2263. int bboxData = buffer.toInt(&ok, 10);
  2264. if (!ok) {
  2265. qDebug() <<
  2266. "BBoxFromData: "
  2267. "bbox format is corrupted";
  2268. break;
  2269. }
  2270. if (-1 == bbox.rect.x()) {
  2271. bbox.rect.setX(bboxData);
  2272. bbox.rect.setWidth(-1);
  2273. }
  2274. else if (-1 == bbox.rect.y()) {
  2275. bbox.rect.setY(bboxData);
  2276. bbox.rect.setHeight(-1);
  2277. }
  2278. else if (-1 == bbox.rect.width()) {
  2279. bbox.rect.setWidth(bboxData);
  2280. }
  2281. else if (-1 == bbox.rect.height()) {
  2282. bbox.rect.setHeight(bboxData);
  2283. }
  2284. startPos = i + 1;
  2285. }
  2286. if (!bbox.rect.isValid()) {
  2287. qDebug() <<
  2288. "BBoxFromData: "
  2289. "bbox format is corrupted";
  2290. bbox.rect.setRect(-1, -1, -1, -1);
  2291. }
  2292. else if (!ok) {
  2293. bbox.rect.setRect(-1, -1, -1, -1);
  2294. }
  2295. return bbox;
  2296. }
  2297. BoundingBox
  2298. ImageLabeler::BBoxFromString(
  2299. QString *aString,
  2300. int *oldID
  2301. )
  2302. {
  2303. BoundingBox bbox;
  2304. bbox.label_ID_ = -1;
  2305. *oldID = -1;
  2306. if (!aString) {
  2307. return bbox;
  2308. /* NOTREACHED */
  2309. }
  2310. if (-1 == aString->indexOf("BBox")) {
  2311. return bbox;
  2312. /* NOTREACHED */
  2313. }
  2314. /* getting bbox id in the list(it cannot be changed) */
  2315. bool ok = 0;
  2316. int bboxID = getNumFromString(aString, "BBox #", ";", &ok);
  2317. if (!ok || bboxID <= -1) {
  2318. qDebug() <<
  2319. "BBoxFromString: bboxID is corrupted";
  2320. return bbox;
  2321. /* NOTREACHED */
  2322. }
  2323. /* getting new label id */
  2324. int labelID = getNumFromString(aString, "LabelID: ", ";", &ok);
  2325. if (!ok || labelID <= -1) {
  2326. showWarning(
  2327. tr("new LabelID is wrong, area can not be changed")
  2328. );
  2329. return bbox;
  2330. /* NOTREACHED */
  2331. }
  2332. /* getting new points */
  2333. int pointsPos = aString->indexOf("data:") + 5;
  2334. int pointsLen = aString->size() - pointsPos;
  2335. if (pointsLen <= 0) {
  2336. showWarning(
  2337. tr("new data is wrong, area can not be changed")
  2338. );
  2339. return bbox;
  2340. /* NOTREACHED */
  2341. }
  2342. QString pointsData = aString->mid(pointsPos, pointsLen);
  2343. bbox = BBoxFromData(&pointsData);
  2344. bbox.label_ID_ = labelID;
  2345. *oldID = bboxID;
  2346. return bbox;
  2347. }
  2348. void
  2349. ImageLabeler::addPoly(Polygon *poly)
  2350. {
  2351. if (poly->poly.isEmpty() || poly->label_ID_ < 0) {
  2352. return;
  2353. /* NOTREACHED */
  2354. }
  2355. list_polygon_.append(poly);
  2356. addPolyArea(list_polygon_.count() - 1, *poly);
  2357. }
  2358. void
  2359. ImageLabeler::addBBox(BoundingBox *bbox)
  2360. {
  2361. if (bbox->rect.isEmpty() || bbox->label_ID_ < 0) {
  2362. return;
  2363. /* NOTREACHED */
  2364. }
  2365. list_bounding_box_.append(bbox);
  2366. addBBoxArea(list_bounding_box_.count() - 1, *bbox);
  2367. }
  2368. void
  2369. ImageLabeler::addPolyFromData(
  2370. QString *aPolyData,
  2371. int *labelID
  2372. )
  2373. {
  2374. Polygon *poly = new Polygon;
  2375. *poly = polyFromData(aPolyData);
  2376. if (poly->poly.isEmpty() || !labelID) {
  2377. return;
  2378. /* NOTREACHED */
  2379. }
  2380. poly->label_ID_ = *labelID;
  2381. list_polygon_.append(poly);
  2382. addPolyArea(list_polygon_.count() - 1, *poly);
  2383. }
  2384. Polygon
  2385. ImageLabeler::polyFromData(
  2386. QString *aPolyData
  2387. )
  2388. {
  2389. Polygon poly;
  2390. poly.label_ID_ = -1;
  2391. QPoint point;
  2392. QString buffer;
  2393. int startPos = 0;
  2394. bool ok = 1;
  2395. bool evenFlag = 0;
  2396. for (int i = 0; i < aPolyData->size(); i++) {
  2397. if (';' != aPolyData->at(i))
  2398. continue;
  2399. buffer = aPolyData->mid(startPos, i - startPos);
  2400. int polyCoor = buffer.toInt(&ok, 10);
  2401. if (!ok) {
  2402. qDebug() <<
  2403. "polyFromData: "
  2404. "poly format is corrupted";
  2405. break;
  2406. }
  2407. if (!evenFlag) {
  2408. point.setX(polyCoor);
  2409. evenFlag = 1;
  2410. }
  2411. else {
  2412. point.setY(polyCoor);
  2413. poly.poly.append(point);
  2414. evenFlag = 0;
  2415. }
  2416. startPos = i + 1;
  2417. }
  2418. if (evenFlag) {
  2419. qDebug() <<
  2420. "polyFromData: "
  2421. "poly format is corrupted";
  2422. poly.poly.clear();
  2423. }
  2424. else if (!ok) {
  2425. poly.poly.clear();
  2426. }
  2427. return poly;
  2428. }
  2429. Polygon
  2430. ImageLabeler::polyFromString(
  2431. QString *aString,
  2432. int *oldID
  2433. )
  2434. {
  2435. Polygon poly;
  2436. poly.label_ID_ = -1;
  2437. *oldID = -1;
  2438. if (!aString) {
  2439. return poly;
  2440. /* NOTREACHED */
  2441. }
  2442. if (-1 == aString->indexOf("Poly")) {
  2443. return poly;
  2444. /* NOTREACHED */
  2445. }
  2446. /* getting poly id in the list(it cannot be changed) */
  2447. bool ok = 0;
  2448. int polyID = getNumFromString(aString, "Poly #", ";", &ok);
  2449. if (!ok || polyID <= -1) {
  2450. qDebug() <<
  2451. "polyFromString: poly ID is corrupted";
  2452. return poly;
  2453. /* NOTREACHED */
  2454. }
  2455. /* getting new label id */
  2456. int labelID = getNumFromString(aString, "LabelID: ", ";", &ok);
  2457. if (!ok || labelID <= -1) {
  2458. showWarning(
  2459. tr("new LabelID is wrong, area can not be changed")
  2460. );
  2461. return poly;
  2462. /* NOTREACHED */
  2463. }
  2464. /* getting new points */
  2465. int pointsPos = aString->indexOf("points:") + 7;
  2466. int pointsLen = aString->size() - pointsPos;
  2467. if (pointsLen <= 0) {
  2468. showWarning(
  2469. tr("new points data is wrong, area can not be changed")
  2470. );
  2471. return poly;
  2472. /* NOTREACHED */
  2473. }
  2474. QString pointsData = aString->mid(pointsPos, pointsLen);
  2475. poly = polyFromData(&pointsData);
  2476. poly.label_ID_ = labelID;
  2477. *oldID = polyID;
  2478. return poly;
  2479. }
  2480. void
  2481. ImageLabeler::showWarning(
  2482. const QString text
  2483. )
  2484. {
  2485. if (text.isEmpty()) {
  2486. return;
  2487. /* NOTREACHED */
  2488. }
  2489. QMessageBox msgBox;
  2490. msgBox.setText(text);
  2491. msgBox.setIcon(QMessageBox::Warning);
  2492. msgBox.exec();
  2493. }
  2494. bool
  2495. ImageLabeler::askForUnsavedData()
  2496. {
  2497. if ((!list_bounding_box_.isEmpty() ||
  2498. !list_polygon_.isEmpty()) &&
  2499. unsaved_data_)
  2500. {
  2501. QMessageBox msgBox;
  2502. msgBox.setText(tr("There is some unsaved data"));
  2503. msgBox.setInformativeText(tr("Do you want to save your progress?"));
  2504. msgBox.setStandardButtons(
  2505. QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
  2506. msgBox.setDefaultButton(QMessageBox::Save);
  2507. msgBox.setIcon(QMessageBox::Question);
  2508. int ret = msgBox.exec();
  2509. if (QMessageBox::Save == ret)
  2510. saveAllInfo();
  2511. else if (QMessageBox::Cancel == ret)
  2512. return true;
  2513. }
  2514. return false;
  2515. }
  2516. void
  2517. ImageLabeler::setBoundingBoxTool(bool aButtonPressed)
  2518. {
  2519. if (aButtonPressed)
  2520. image_holder_->setTool(ImageHolder::BoundingBoxTool);
  2521. else {
  2522. image_holder_->setTool(ImageHolder::NoTool);
  2523. image_holder_->clearLast();
  2524. }
  2525. }
  2526. void
  2527. ImageLabeler::setPolygonTool(bool aButtonPressed)
  2528. {
  2529. if (aButtonPressed) {
  2530. image_holder_->setTool(ImageHolder::PolygonTool);
  2531. image_holder_->setFocus();
  2532. }
  2533. else {
  2534. image_holder_->setTool(ImageHolder::NoTool);
  2535. image_holder_->clearLast();
  2536. }
  2537. }
  2538. void
  2539. ImageLabeler::onSelectionStarted()
  2540. {
  2541. button_confirm_selection_->setEnabled(true);
  2542. }
  2543. void
  2544. ImageLabeler::onImageScaled()
  2545. {
  2546. }
  2547. void
  2548. ImageLabeler::confirmSelection()
  2549. {
  2550. if (!list_label_->count()) {
  2551. showWarning(tr("You haven't added any label"));
  2552. return;
  2553. /* NOTREACHED */
  2554. }
  2555. image_holder_->confirmSelection();
  2556. if (label_ID_ < 0)
  2557. label_ID_ = 0;
  2558. ImageHolder::Tool tool = image_holder_->tool();
  2559. switch (tool) {
  2560. case ImageHolder::BoundingBoxTool:
  2561. list_bounding_box_.last()->label_ID_ = label_ID_;
  2562. addBBoxArea(
  2563. list_bounding_box_.count() - 1,
  2564. *(list_bounding_box_.last())
  2565. );
  2566. break;
  2567. case ImageHolder::PolygonTool:
  2568. list_polygon_.last()->label_ID_ = label_ID_;
  2569. addPolyArea(
  2570. list_polygon_.count() - 1,
  2571. *(list_polygon_.last())
  2572. );
  2573. break;
  2574. default:
  2575. break;
  2576. }
  2577. button_confirm_selection_->setEnabled(false);
  2578. unsaved_data_ = 1;
  2579. }
  2580. void
  2581. ImageLabeler::clearAll()
  2582. {
  2583. clearLabelList();
  2584. list_areas_->clear();
  2585. list_bounding_box_.clear();
  2586. list_polygon_.clear();
  2587. list_images_->clear();
  2588. list_images_widget_->clear();
  2589. main_label_ = -1;
  2590. image_holder_->clearAll();
  2591. segmented_image_.clear();
  2592. action_view_normal_->setEnabled(false);
  2593. action_view_segmented_->setEnabled(false);
  2594. }
  2595. void
  2596. ImageLabeler::clearAllTool()
  2597. {
  2598. list_areas_->clear();
  2599. list_bounding_box_.clear();
  2600. list_polygon_.clear();
  2601. main_label_ = -1;
  2602. image_holder_->clearAll();
  2603. }
  2604. void ImageLabeler::clearLabelList()
  2605. {
  2606. list_label_->clear();
  2607. addLabel(0, false, "BACKGROUND");
  2608. list_label_->item(0)->setFlags(
  2609. Qt::ItemIsUserCheckable | Qt::ItemIsSelectable |
  2610. Qt::ItemIsEnabled
  2611. );
  2612. }
  2613. void ImageLabeler::clearLabelColorList()
  2614. {
  2615. list_label_colors_.clear();
  2616. list_label_colors_.append(0x0);
  2617. }
  2618. void
  2619. ImageLabeler::enableTools()
  2620. {
  2621. action_save_labels_->setEnabled(true);
  2622. action_save_segmented_->setEnabled(true);
  2623. action_save_legend_->setEnabled(true);
  2624. action_bound_box_tool_->setEnabled(true);
  2625. action_polygon_tool_->setEnabled(true);
  2626. action_add_description_->setEnabled(true);
  2627. action_undo_->setEnabled(true);
  2628. action_redo_->setEnabled(true);
  2629. button_bound_box_tool_->setEnabled(true);
  2630. button_polygon_tool_->setEnabled(true);
  2631. button_tagging_tool_->setEnabled(true);
  2632. button_add_label_->setEnabled(true);
  2633. button_remove_label_->setEnabled(true);
  2634. button_prev_image_->setEnabled(true);
  2635. button_next_image_->setEnabled(true);
  2636. button_clear_selection_tool_->setEnabled(true);
  2637. button_generate_colors_->setEnabled(true);
  2638. button_delete_all_labels_->setEnabled(true);
  2639. }
  2640. void
  2641. ImageLabeler::disableTools()
  2642. {
  2643. action_save_labels_->setEnabled(false);
  2644. action_save_segmented_->setEnabled(false);
  2645. action_save_legend_->setEnabled(false);
  2646. action_bound_box_tool_->setEnabled(false);
  2647. action_polygon_tool_->setEnabled(false);
  2648. button_tagging_tool_->setEnabled(false);
  2649. action_add_description_->setEnabled(false);
  2650. action_undo_->setEnabled(false);
  2651. action_redo_->setEnabled(false);
  2652. button_bound_box_tool_->setEnabled(false);
  2653. button_polygon_tool_->setEnabled(false);
  2654. button_add_label_->setEnabled(false);
  2655. button_remove_label_->setEnabled(false);
  2656. button_prev_image_->setEnabled(false);
  2657. button_next_image_->setEnabled(false);
  2658. button_clear_selection_tool_->setEnabled(false);
  2659. button_generate_colors_->setEnabled(false);
  2660. button_delete_all_labels_->setEnabled(false);
  2661. }
  2662. void
  2663. ImageLabeler::areaListPopupMenu(const QPoint &aPos)
  2664. {
  2665. QPoint globalPos = list_areas_->mapToGlobal(aPos);
  2666. QModelIndex index = list_areas_->indexAt(aPos);
  2667. if (-1 == index.row()) {
  2668. return;
  2669. /* NOTREACHED */
  2670. }
  2671. list_areas_->item(index.row())->setSelected(true);
  2672. popup_area_list_->exec(globalPos);
  2673. }
  2674. void
  2675. ImageLabeler::labelListPopupMenu(const QPoint &aPos)
  2676. {
  2677. QPoint globalPos = list_label_->mapToGlobal(aPos);
  2678. QModelIndex index = list_label_->indexAt(aPos);
  2679. if (-1 == index.row() || !index.row()) {
  2680. return;
  2681. /* NOTREACHED */
  2682. }
  2683. list_label_->item(index.row())->setSelected(true);
  2684. popup_label_list_->exec(globalPos);
  2685. }
  2686. void
  2687. ImageLabeler::setDataFromForm(QString aData)
  2688. {
  2689. if (ImageDescriptionPurpose == line_edit_form_.purpose()) {
  2690. image_description_ = aData;
  2691. setWindowTitle(image_description_);
  2692. }
  2693. else if (TaggingPurpose == line_edit_form_.purpose()) {
  2694. tags_ = aData;
  2695. }
  2696. }
  2697. void
  2698. ImageLabeler::setPureData()
  2699. {
  2700. /* initializing array */
  2701. if (pure_data_) {
  2702. delete[] *pure_data_;
  2703. delete pure_data_;
  2704. }
  2705. QSize imageSize = image_->size();
  2706. pure_data_ = new int *[imageSize.height()];
  2707. if (!pure_data_) {
  2708. return;
  2709. /* NOTREACHED */
  2710. }
  2711. for (int i = 0; i < imageSize.height(); i++) {
  2712. pure_data_[i] = new int[imageSize.width()];
  2713. if (!pure_data_[i]) {
  2714. return;
  2715. /* NOTREACHED */
  2716. }
  2717. }
  2718. int bboxCnt = list_bounding_box_.count();
  2719. int polyCnt = list_polygon_.count();
  2720. for (int i = 0; i < imageSize.height(); i++)
  2721. for (int j = 0; j < imageSize.width(); j++) {
  2722. pure_data_[i][j] = 0;
  2723. /* bboxes first */
  2724. for (int cnt = 0; cnt < bboxCnt; cnt++) {
  2725. BoundingBox *bbox = list_bounding_box_.at(cnt);
  2726. if (bbox->rect.contains(j, i)) {
  2727. pure_data_[i][j] = bbox->label_ID_;
  2728. }
  2729. }
  2730. /* polys next */
  2731. for (int cnt = 0; cnt < polyCnt; cnt++) {
  2732. Polygon *poly = list_polygon_.at(cnt);
  2733. if (poly->poly.containsPoint(QPoint(j, i), Qt::OddEvenFill)) {
  2734. pure_data_[i][j] = poly->label_ID_;
  2735. }
  2736. }
  2737. }
  2738. }
  2739. void
  2740. ImageLabeler::setLabelColor()
  2741. {
  2742. if (list_label_colors_.count() < list_label_->count()) {
  2743. generateColors();
  2744. }
  2745. QListWidgetItem *current = list_label_->currentItem();
  2746. int labelID = list_label_->row(current);
  2747. QColor defaultColor;
  2748. defaultColor.setRgb(list_label_colors_.at(labelID));
  2749. QColor newColor = QColorDialog::getColor(
  2750. defaultColor,
  2751. list_label_
  2752. );
  2753. if (!newColor.isValid()) {
  2754. return;
  2755. /* NOTREACHED */
  2756. }
  2757. list_label_colors_.takeAt(labelID);
  2758. list_label_colors_.insert(labelID, newColor.rgb());
  2759. QPixmap iconPix = QPixmap(20, 20);
  2760. iconPix.fill(newColor);
  2761. QIcon icon(iconPix);
  2762. current->setIcon(icon);
  2763. image_holder_->update();
  2764. }
  2765. void
  2766. ImageLabeler::setLabelColor(int anID, QColor aColor)
  2767. {
  2768. if (anID < 0) {
  2769. return;
  2770. /* NOTREACHED */
  2771. }
  2772. if (list_label_colors_.count() < list_label_->count()) {
  2773. generateColors();
  2774. }
  2775. QListWidgetItem *item = list_label_->item(anID);
  2776. list_label_colors_.takeAt(anID);
  2777. list_label_colors_.insert(anID, aColor.rgb());
  2778. QPixmap iconPix = QPixmap(20, 20);
  2779. iconPix.fill(aColor);
  2780. QIcon icon(iconPix);
  2781. item->setIcon(icon);
  2782. image_holder_->update();
  2783. }
  2784. void
  2785. ImageLabeler::onOptionsSet()
  2786. {
  2787. auto_color_generation_ = options_form_.autoColorGeneration();
  2788. }
  2789. void
  2790. ImageLabeler::viewNormal()
  2791. {
  2792. if (current_image_.isEmpty()) {
  2793. return;
  2794. /* NOTREACHED */
  2795. }
  2796. image_->load(current_image_);
  2797. image_holder_->setPixmap(*image_);
  2798. action_view_segmented_->setEnabled(true);
  2799. action_view_normal_->setEnabled(false);
  2800. }
  2801. void
  2802. ImageLabeler::viewSegmented()
  2803. {
  2804. if (segmented_image_.isEmpty()) {
  2805. return;
  2806. /* NOTREACHED */
  2807. }
  2808. image_->load(segmented_image_);
  2809. image_holder_->setPixmap(*image_);
  2810. action_view_segmented_->setEnabled(false);
  2811. action_view_normal_->setEnabled(true);
  2812. }
  2813. void
  2814. ImageLabeler::interruptSearch()
  2815. {
  2816. interrupt_search_ = 1;
  2817. }
  2818. void
  2819. ImageLabeler::selectImage(QListWidgetItem *anItem)
  2820. {
  2821. if (!anItem || list_images_widget_->row(anItem) < 0 ||
  2822. list_images_->isEmpty())
  2823. {
  2824. return;
  2825. /* NOTREACHED */
  2826. }
  2827. clearAllTool();
  2828. clearLabelList();
  2829. clearLabelColorList();
  2830. image_ID_ = list_images_widget_->row(anItem);
  2831. selectImage(image_ID_);
  2832. // if (list_images_->at(image_ID_).labeled_ &&
  2833. // !list_images_->at(image_ID_).pas_)
  2834. // {
  2835. // list_label_->clear();
  2836. // QString labeled =
  2837. // alterFileName(list_images_->at(image_ID_).image_, "_labeled");
  2838. // labeled.append(".dat");
  2839. // loadInfo(labeled);
  2840. // }
  2841. // else if (list_images_->at(image_ID_).labeled_ &&
  2842. // list_images_->at(image_ID_).pas_)
  2843. // {
  2844. // /* TODO: do the pascal file selecting */
  2845. // showWarning("this function doesn't work at the moment, sorry.");
  2846. // }
  2847. // else {
  2848. // current_image_ = list_images_->at(image_ID_).image_;
  2849. // image_->load(current_image_);
  2850. // image_holder_->setPixmap(*image_);
  2851. // image_holder_->resize(image_->size());
  2852. // }
  2853. }
  2854. bool
  2855. ImageLabeler::selectImage(int anImageID)
  2856. {
  2857. if (anImageID < 0 || list_images_->isEmpty() ||
  2858. list_images_->count() <= anImageID)
  2859. {
  2860. return false;
  2861. /* NOTREACHED */
  2862. }
  2863. if (list_images_->at(anImageID).labeled_ &&
  2864. !list_images_->at(anImageID).pas_)
  2865. {
  2866. list_label_->clear();
  2867. QString labeled =
  2868. alterFileName(list_images_->at(anImageID).image_, "_labeled");
  2869. labeled.append(".dat");
  2870. loadInfo(labeled);
  2871. }
  2872. else if (list_images_->at(anImageID).labeled_ &&
  2873. list_images_->at(anImageID).pas_)
  2874. {
  2875. /* TODO: do the pascal file selecting */
  2876. showWarning("this function doesn't work at the moment, sorry.");
  2877. }
  2878. else {
  2879. current_image_ = list_images_->at(anImageID).image_;
  2880. image_->load(current_image_);
  2881. image_holder_->setPixmap(*image_);
  2882. image_holder_->resize(image_->size());
  2883. }
  2884. return true;
  2885. }
  2886. void
  2887. ImageLabeler::imageListPopupMenu(const QPoint &aPos)
  2888. {
  2889. QPoint globalPos = list_images_widget_->mapToGlobal(aPos);
  2890. QModelIndex index = list_images_widget_->indexAt(aPos);
  2891. if (-1 == index.row()) {
  2892. return;
  2893. /* NOTREACHED */
  2894. }
  2895. list_images_widget_->item(index.row())->setSelected(true);
  2896. popup_images_list_->exec(globalPos);
  2897. }
  2898. void
  2899. ImageLabeler::removeImage()
  2900. {
  2901. int num = list_images_widget_->currentRow();
  2902. list_images_widget_->takeItem(num);
  2903. list_images_->takeAt(num);
  2904. for (int i = num ; i < list_images_widget_->count(); i++) {
  2905. QString newStr = getFilenameFromPath(&(list_images_->at(i).image_));
  2906. newStr.prepend(QString("%1: ").arg(i));
  2907. list_images_widget_->item(i)->setText(newStr);
  2908. }
  2909. }
  2910. void
  2911. ImageLabeler::resizeEvent (QResizeEvent *anEvent)
  2912. {
  2913. QWidget::resizeEvent(anEvent);
  2914. }
  2915. void
  2916. ImageLabeler::mousePressEvent(QMouseEvent *anEvent)
  2917. {
  2918. QWidget::mousePressEvent(anEvent);
  2919. }
  2920. void
  2921. ImageLabeler::keyPressEvent(QKeyEvent *anEvent)
  2922. {
  2923. keyboard_modifier_ = anEvent->modifiers();
  2924. if (Qt::Key_Left == anEvent->key() &&
  2925. Qt::ControlModifier == keyboard_modifier_) {
  2926. prevImage();
  2927. }
  2928. if (Qt::Key_Right == anEvent->key() &&
  2929. Qt::ControlModifier == keyboard_modifier_) {
  2930. nextImage();
  2931. }
  2932. if ((Qt::Key_Enter == anEvent->key() ||
  2933. Qt::Key_Return == anEvent->key()) &&
  2934. // Qt::NoModifier == anEvent->modifiers() &&
  2935. ImageHolder::NewSelection == image_holder_->state()) {
  2936. confirmSelection();
  2937. }
  2938. if ((Qt::Key_Enter == anEvent->key() ||
  2939. Qt::Key_Return == anEvent->key()) &&
  2940. // Qt::NoModifier == anEvent->modifiers() &&
  2941. -1 != image_holder_->focusedSelection()) {
  2942. image_holder_->clearFocusOnArea();
  2943. image_holder_->clearEdition();
  2944. image_holder_->update();
  2945. }
  2946. if (Qt::Key_Escape == anEvent->key()) {
  2947. image_holder_->clearLast();
  2948. image_holder_->clearFocusOnArea();
  2949. image_holder_->clearEdition();
  2950. image_holder_->update();
  2951. }
  2952. if (Qt::Key_Z == anEvent->key() &&
  2953. Qt::ControlModifier == anEvent->modifiers()) {
  2954. image_holder_->undo();
  2955. }
  2956. if (Qt::Key_Y == anEvent->key() &&
  2957. Qt::ControlModifier == anEvent->modifiers()) {
  2958. image_holder_->redo();
  2959. }
  2960. QWidget::keyPressEvent(anEvent);
  2961. }
  2962. void
  2963. ImageLabeler::keyReleaseEvent(QKeyEvent *anEvent)
  2964. {
  2965. keyboard_modifier_ = anEvent->modifiers();
  2966. }
  2967. void
  2968. ImageLabeler::wheelEvent(QWheelEvent *anEvent)
  2969. {
  2970. /* zoomin */
  2971. if (0 < anEvent->delta() &&
  2972. Qt::ControlModifier == keyboard_modifier_) {
  2973. image_holder_->scaleImage(ZoomIn, 1.1);
  2974. }
  2975. /* zoomout */
  2976. else if (anEvent->delta() < 0 &&
  2977. Qt::ControlModifier == keyboard_modifier_) {
  2978. image_holder_->scaleImage(ZoomOut, 1.1);
  2979. }
  2980. }
  2981. /*
  2982. *
  2983. */