You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

detection.js 88 kB

4 years ago
4 years ago
4 years ago
4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957
  1. //
  2. /**
  3. * @author zhaiyunpeng
  4. * @copyright 2019
  5. * javascript for person and vehicle detection
  6. */
  7. var regions;
  8. var img=new Image();
  9. var imginfo = {};
  10. var ip = getIp();
  11. var token = getSessionStorageMessage("token");
  12. var userType = getSessionStorageMessage("userType");
  13. console.log("token=" + token);
  14. var loadFinished=false; //判断是否加载完成,防止上下张快捷键过快,导致保存冲刷掉原有数据,保存空数据
  15. var currentImage=true;
  16. if(userType == 2){
  17. $('#title_id').text("通用图片审核");
  18. }
  19. function getCookieOrMessage(key){
  20. var value = getCookie(key);
  21. return value;
  22. }
  23. function getSessionStorageMessage(key){
  24. var value = sessionStorage.getItem(key);
  25. if(isEmpty(value)){
  26. return localStorage.getItem(key);
  27. }
  28. return value;
  29. }
  30. //获取元素绝对位置 获取鼠标坐标
  31. function getElementLeft(element){
  32. var actualLeft = element.offsetLeft;
  33. var current = element.offsetParent;
  34. while (current !==null){
  35. actualLeft += (current.offsetLeft+current.clientLeft);
  36. current = current.offsetParent;
  37. }
  38. return actualLeft;
  39. }
  40. function getElementTop(element){
  41. var actualTop = element.offsetTop;
  42. var current = element.offsetParent;
  43. while (current !== null){
  44. actualTop += (current.offsetTop+current.clientTop);
  45. current = current.offsetParent;
  46. }
  47. return actualTop;
  48. }
  49. // canvas 矩形框集合
  50. //by yunpeng zhai
  51. //变量定义//变量重置
  52. //
  53. var verifyMap = {"1":"大小不合格","2":"颜色不合格","3":"其它不合格"};
  54. var label_task = getSessionStorageMessage("label_task");
  55. var label_task_status = getSessionStorageMessage("label_task_status"); //1表示审核
  56. console.log("label_task=" + label_task);
  57. var label_task_info;
  58. var labeltastresult;
  59. var rects=[];
  60. var masks=[];
  61. var pointShapes =[];
  62. var copyrects;//复制变量
  63. var copymasks;//复制使用的变量
  64. var copyPointShapes;
  65. var undoShape;
  66. var color_dict = {"rect":"#13c90c","car":"#0099CC", "person":"#FF99CC","point":"#00cc00","pointselected":"red"};
  67. var color_person = {"0":"#13c90c","1":"#fc0707","2":"#FF99CC","3":"#fceb07"};
  68. var color_all={"0":"#13c90c","1":"#fc0707","2":"#FF99CC","3":"#fceb07","4":"#FF33FF","5":"#666600","6":"#4B0082","7":"#B8860B","8": "#000000","9":"#800000","10": "#FF00FF","11":"#8B4513","12":" #0000CD","13":" #008B8B","14":"#708090","15": "#00FFFF","16":"#FF00FF","17":"#9370DB","18":"#7CFC00","19":"#F08080","20":"#C71585"};
  69. var SelectedRect;
  70. var SelectedpointId;
  71. var Selectedmask;
  72. var SelectedPointShape;
  73. var creatingmask;
  74. var SelectedmaskpointId;
  75. var tocreaterect=false;
  76. var tocreatemask=false;
  77. var toCreatePoint = false;
  78. var boxcls = "person";
  79. var mouseonpoint_mask;
  80. var mouseonpoint_rect;
  81. var mouseonrect_rect;
  82. var mouseonmask_mask;
  83. var old_click_x1;
  84. var old_click_y1;
  85. var stretch=false;
  86. var stretch_mask=false;
  87. var isDragging = false;
  88. var showpopVar = false;
  89. var widthstart,widthend;
  90. var heightstart,heightend;
  91. var dragging = false;
  92. var startx = 0;
  93. var starty = 0;
  94. var imgScale = 1;
  95. var fileindex=0;
  96. var lastindex=false;
  97. var isLabelChange = false;
  98. var maxIdNum=0;
  99. function reset_var(){
  100. SelectedRect=null;
  101. SelectedpointId=null;
  102. SelectedmaskpointId = null;
  103. Selectedmask = null;
  104. SelectedPointShape = null;
  105. creatingmask = null;
  106. toCreatePoint = false;
  107. tocreaterect=false;
  108. tocreatemask = false;
  109. boxcls = "person";
  110. mouseonpoint_mask = null;
  111. mouseonpoint_rect=null;
  112. mouseonrect_rect=null;
  113. mouseonmask_mask=null;
  114. old_click_x1=null;
  115. old_click_y1=null;
  116. stretch=false;
  117. stretch_mask = false;
  118. isDragging = false;
  119. showpopVar = false;
  120. widthstart,widthend=null;
  121. heightstart,heightend=null;
  122. imgScale = 1;
  123. dragging = false;
  124. startx = 0;
  125. starty = 0;
  126. }
  127. var label_attributes ;
  128. //by yunpeng zhai
  129. //基本对象的定义 点, 矩形, 多边形MASK
  130. //
  131. function point(x,y){
  132. this.x = x;
  133. this.y = y;
  134. this.isSelected = false;
  135. };
  136. function pointShape(x,y,type,score=1.0){
  137. this.x = x;
  138. this.y = y;
  139. this.isSelected = false;
  140. this.type = type;
  141. this.score = score;
  142. this.id =""; //标识
  143. this.blurred=false;//模糊不清的; 记不清的; 难以区分的; 模棱两可的
  144. this.goodIllumination = false; //照明
  145. this.frontview = false;//正面图
  146. this.other = {};//自定义属性
  147. this.other['region_attributes'] = {};
  148. }
  149. function rectar(x1,y1,x2,y2, type, score=1.0){
  150. // this.x = x;
  151. // this.y = y;
  152. // this.width = width;
  153. // this.height = height;
  154. this.type = type;
  155. this.score = score;
  156. //0--1,
  157. //| |
  158. //2--3
  159. this.points = [new point(x1,y1), new point(x1, y2),new point(x2, y1),new point(x2, y2)];
  160. this.getXYWH = function(){
  161. var x_min=Math.min(this.points[0].x,this.points[1].x,this.points[2].x,this.points[3].x);
  162. var x_max=Math.max(this.points[0].x,this.points[1].x,this.points[2].x,this.points[3].x);
  163. var y_min=Math.min(this.points[0].y,this.points[1].y,this.points[2].y,this.points[3].y);
  164. var y_max=Math.max(this.points[0].y,this.points[1].y,this.points[2].y,this.points[3].y);
  165. return [x_min,y_min,x_max-x_min,y_max-y_min];
  166. }
  167. this.getX1Y1X2Y2 = function(){
  168. var x_min=Math.min(this.points[0].x,this.points[1].x,this.points[2].x,this.points[3].x);
  169. var x_max=Math.max(this.points[0].x,this.points[1].x,this.points[2].x,this.points[3].x);
  170. var y_min=Math.min(this.points[0].y,this.points[1].y,this.points[2].y,this.points[3].y);
  171. var y_max=Math.max(this.points[0].y,this.points[1].y,this.points[2].y,this.points[3].y);
  172. return [x_min,y_min,x_max,y_max];
  173. }
  174. this.getdiapid = function(pid){//获取对角点
  175. var twooverlapped,fouroverlapped;
  176. for (var i=0;i<4;i++){
  177. if ((this.points[pid].x!=this.points[i].x)&&(this.points[pid].y!=this.points[i].y)){
  178. return i;
  179. }
  180. if ((this.points[pid].x!=this.points[i].x)||(this.points[pid].y!=this.points[i].y)){
  181. twooverlapped=i;
  182. }
  183. if (i!=pid) fouroverlapped=i;
  184. }
  185. if (twooverlapped)
  186. return twooverlapped;
  187. return fouroverlapped;
  188. }
  189. this.mouseonpoint = false;
  190. this.mouseonrect = false;
  191. this.isSelected = false;
  192. this.id =""; //标识
  193. this.blurred=false;//模糊不清的; 记不清的; 难以区分的; 模棱两可的
  194. this.goodIllumination = true; //照明
  195. this.frontview = true;//正面图
  196. this.other = {};//自定义属性
  197. this.other['region_attributes'] = {};
  198. //{} -> key = "type" , value = {"type":"dropdown,radio,checkbox", "description" : "..", "options":{"car" : "car", "person" : "person"}, "default_options" : {"car" : "car"}}
  199. // key = "color", value = {"type" : "text", "description" : "..", "def":"11111"}
  200. };
  201. function maskar(x0,y0,type,score=1.0){
  202. this.type = type;
  203. this.points = [new point(x0,y0)];
  204. this.finish = false;
  205. this.mouseonpoint = false;
  206. this.mouseonmask = false;
  207. this.isSelected = false;
  208. this.score = score;
  209. this.getX1Y1 = function(){return [this.points[0].x,this.points[0].y]}
  210. this.getBound = function(){
  211. mlen = this.points.length;
  212. var minX = 999999999, minY = 999999999, maxX = -1, maxY = -1;
  213. for (var i = 0; i < mlen; i ++){
  214. if(minX > this.points[i].x){
  215. minX = this.points[i].x;
  216. }
  217. if(maxX < this.points[i].x){
  218. maxX = this.points[i].x;
  219. }
  220. if(minY > this.points[i].y){
  221. minY = this.points[i].y;
  222. }
  223. if(maxY < this.points[i].y){
  224. maxY = this.points[i].y;
  225. }
  226. }
  227. return [minX, minY, maxX, maxY];
  228. }
  229. this.id =""; //标识
  230. this.blurred=false;//模糊不清的; 记不清的; 难以区分的; 模棱两可的
  231. this.goodIllumination = true; //照明
  232. this.frontview = true;//正面图
  233. this.other = {};//自定义属性
  234. this.other['region_attributes'] = {};
  235. }
  236. function getShowShape(recttype){
  237. var tmp;
  238. if(recttype == "rect"){
  239. tmp = rects;
  240. }else if(recttype == "mask"){
  241. tmp = masks;
  242. }else if(recttype == "pointshape"){
  243. tmp = pointShapes;
  244. }
  245. return tmp;
  246. }
  247. function showPopup(topx,lefty,rectIndex,recttype) {
  248. if (topx > canvas.height){
  249. topx = canvas.height;
  250. }
  251. if (lefty > canvas.width){
  252. lefty = canvas.width;
  253. }
  254. _via_display_area_content_name = VIA_DISPLAY_AREA_CONTENT_NAME.IMAGE;
  255. regions = getShowShape(recttype);
  256. if(isEmpty(regions)){
  257. return;
  258. }
  259. _via_is_region_selected = true;
  260. annotation_editor_show(topx,lefty,rectIndex,recttype);
  261. /*
  262. // 弹框下拉焦点消失
  263. $("select").bind("focus", function(){
  264. if(this.blur){
  265. this.blur();
  266. }
  267. }); */
  268. }
  269. //关闭弹窗函数,设置display为none,传一个参数,把true和false传进去
  270. function hidePopup() {
  271. // document.getElementById("annotation_editor").style.display = "none";
  272. annotation_editor_remove();
  273. for (var i=0;i<rects.length;i++){
  274. rects[i].isSelected = false;
  275. }
  276. // showPopup(bigLocY(x)+145, bigLocX(y) + 235,rectIndex,shapetype);
  277. for (var i=0;i<masks.length;i++){
  278. masks[i].isSelected = false;
  279. }
  280. for (var i=0;i<pointShapes.length;i++){
  281. pointShapes[i].isSelected = false;
  282. }
  283. drawRect();
  284. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  285. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  286. }
  287. function copyOneBox(){
  288. copyrects=[];
  289. copymasks=[];
  290. copyPointShapes=[];
  291. for (var i=0;i<rects.length;i++){
  292. if (rects[i].isSelected==true){
  293. copyrects.push(rects[i]);
  294. }
  295. }
  296. // showPopup(bigLocY(x)+145, bigLocX(y) + 235,rectIndex,shapetype);
  297. for (var i=0;i<masks.length;i++){
  298. if (masks[i].isSelected==true){
  299. copymasks.push(masks[i]);
  300. }
  301. }
  302. for (var i=0;i<pointShapes.length;i++){
  303. if (pointShapes[i].isSelected==true){
  304. copyPointShapes.push(pointShapes[i]);
  305. }
  306. }
  307. currentImage=true;
  308. }
  309. function copy(){
  310. // copyrects=[];
  311. // copymasks=[];
  312. // copyPointShapes=[];
  313. copyrects = rects.slice();
  314. copymasks = masks.slice();
  315. copyPointShapes = pointShapes.slice();
  316. console.log("拷贝数据:"+JSON.stringify(copyrects));
  317. currentImage=true;
  318. }
  319. function paste(){
  320. if(currentImage==true){
  321. alert("当前页暂不能粘贴");
  322. return;
  323. }
  324. if(!isEmpty(copyrects)){
  325. var tmpRects = copyrects.slice();
  326. // copyrects.length = 0;
  327. for(var i = 0; i <tmpRects.length; i++){
  328. if (maxIdNum< parseInt(tmpRects[i].other["region_attributes"]["id"])){
  329. maxIdNum = parseInt(tmpRects[i].other["region_attributes"]["id"]);
  330. }
  331. else{
  332. tmpRects[i].other["region_attributes"]["id"] = maxIdNum+1;
  333. tmpRects[i].id = maxIdNum+1;
  334. maxIdNum = maxIdNum +1;
  335. }
  336. tmpRects[i].isSelected=false;
  337. rects.push(tmpRects[i]);
  338. }
  339. console.log("粘贴数据:"+JSON.stringify(rects));
  340. }
  341. if(!isEmpty(copymasks)){
  342. var tmpMasks = copymasks.slice();
  343. // copymasks.length = 0;
  344. for(var i = 0; i <tmpMasks.length; i++){
  345. if (maxIdNum< parseInt(tmpMasks[i].other["region_attributes"]["id"])){
  346. maxIdNum = parseInt(tmpMasks[i].other["region_attributes"]["id"]);
  347. }
  348. else{
  349. tmpMasks[i].other["region_attributes"]["id"] = maxIdNum+1;
  350. tmpMasks[i].id = maxIdNum+1;
  351. maxIdNum = maxIdNum +1;
  352. }
  353. tmpMasks[i].isSelected=false;
  354. masks.push(tmpMasks[i]);
  355. }
  356. }
  357. if(!isEmpty(copyPointShapes)){
  358. var tmpPointShapes = copyPointShapes.slice();
  359. // copyPointShapes.length = 0;
  360. for(var i = 0; i <tmpPointShapes.length; i++){
  361. if (maxIdNum< parseInt(tmpPointShapes[i].other["region_attributes"]["id"])){ //不会出现重复的框
  362. maxIdNum = parseInt(tmpPointShapes[i].other["region_attributes"]["id"]);
  363. }
  364. else{
  365. tmpPointShapes[i].other["region_attributes"]["id"] = maxIdNum+1; //会出现重复的目标框
  366. tmpPointShapes[i].id = maxIdNum+1;
  367. maxIdNum = maxIdNum +1;
  368. }
  369. tmpPointShapes[i]=false;
  370. pointShapes.push(tmpPointShapes[i]);
  371. }
  372. }
  373. drawRect();
  374. updateLabelHtml();
  375. currentImage=true;
  376. }
  377. function undo(){//删除矩形框或者mask
  378. hidePopup();
  379. if(undoShape){
  380. var index = rects.indexOf(undoShape);
  381. if (index!=-1){
  382. rects.splice(index, 1);
  383. }
  384. index = masks.indexOf(undoShape);
  385. if (index!=-1){
  386. masks.splice(index, 1);
  387. }
  388. index = pointShapes.indexOf(undoShape);
  389. if (index!=-1){
  390. pointShapes.splice(index, 1);
  391. }
  392. }
  393. drawRect();
  394. updateLabelHtml();
  395. }
  396. function updateSetting(){
  397. hidePopup();
  398. // show_region_attributes_update_panel();
  399. var set_attributes = document.getElementById("set_attributes")
  400. set_attributes.setAttribute('style', 'overflow:auto;'+'top:' + 185 + 'px;left:'+ 50 +'px;width:'+ 502+'px;position:absolute');
  401. update_attributes_update_panel();
  402. $('#message_panel').css('display','block');
  403. $('#message_panel .content').css('display','inline');
  404. }
  405. function save_attribute(){
  406. var set_attributes = document.getElementById("set_attributes");
  407. var _via_attributes_str = JSON.stringify(_via_attributes['region']);
  408. update_labeltask(_via_attributes_str);
  409. set_attributes.style.display = "none";
  410. document.getElementById('message_panel').style.display = "none";
  411. document.getElementById('message_panel_content').style.display = 'none';
  412. }
  413. function close_attribute(){
  414. set_attributes.style.display = "none";
  415. onload();
  416. document.getElementById("user_input_attribute_id").value='';
  417. document.getElementById('attribute_properties').innerHTML = '';
  418. document.getElementById('attribute_options').innerHTML = '';
  419. document.getElementById("type_color").style.display = "none";
  420. document.getElementById("type_car").style.display = "none";
  421. document.getElementById('message_panel').style.display = "none";
  422. document.getElementById('message_panel_content').style.display = 'none';
  423. }
  424. function close_exist_child_attributes(){
  425. var set_attributes = document.getElementById("atttibute_child");
  426. document.getElementById('atttibute_childe').innerHTML = '';
  427. // var atttibute_child = document.getElementById('atttibute_child');
  428. // if ( atttibute_child ) {
  429. // atttibute_child.style.display = "none";
  430. // // p.remove();
  431. // //
  432. // }
  433. // set_attributes.style.display = "none";
  434. }
  435. function moveAllShape(x,y){
  436. for (var i=0;i<rects.length;i++){
  437. moverect(rects[i],x,y);
  438. }
  439. for (var i=0;i<masks.length;i++){
  440. moveMask(masks[i],x,y);
  441. }
  442. for(var i =0; i < pointShapes.length;i++){
  443. pointShapes[i].x += x;
  444. pointShapes[i].y += y;
  445. }
  446. drawRect();
  447. }
  448. function moveLeftOnePx(){
  449. moveAllShape(-1,0);
  450. }
  451. function moveRightOnePx(){
  452. moveAllShape(1,0);
  453. }
  454. function moveUpOnePx(){
  455. moveAllShape(0,-1);
  456. }
  457. function moveDownOnePx(){
  458. moveAllShape(0,1);
  459. }
  460. function moveSingleShape(x,y) {
  461. if(SelectedRect) {
  462. var index = rects.indexOf(SelectedRect);
  463. moverect(rects[index], x, y);
  464. }
  465. if(Selectedmask){
  466. var index = masks.indexOf(Selectedmask);
  467. moveMask(masks[index], x, y);
  468. }
  469. if(SelectedPointShape) {
  470. var index = pointShapes.indexOf(SelectedPointShape);
  471. pointShapes[index].x += x;
  472. pointShapes[index].y += y;
  473. }
  474. drawRect();
  475. }
  476. function moveLeftSinglePx() {
  477. //$("#hiddenLeft").click();
  478. moveSingleShape(-1,0);
  479. }
  480. function moveRightSinglePx(){
  481. moveSingleShape(1,0);
  482. }
  483. function moveUpSinglePx(){
  484. moveSingleShape(0,-1);
  485. }
  486. function moveDownSinglePx(){
  487. moveSingleShape(0,1);
  488. }
  489. function createRectLabel(){
  490. createrect(getDefaultType());
  491. }
  492. function getDefaultType(){
  493. var tmpType = "";
  494. if(!isEmpty(_via_attributes['region']['type']) && !isEmpty(_via_attributes['region']['type']["default_options"])){
  495. if(_via_attributes['region']['type']['type'] == "dropdown" || _via_attributes['region']['type']['type'] == "radio" || _via_attributes['region']['type']['type'] == "checkbox"){
  496. var tmp = _via_attributes['region']['type']["default_options"];
  497. console.log("aa=" + tmp);
  498. for(var key in tmp){
  499. if(tmp[key] == true){
  500. tmpType = key;
  501. break;
  502. }
  503. }
  504. }
  505. }
  506. console.log("defaulttyype=" + tmpType);
  507. return tmpType;
  508. }
  509. function createMaskLabel(){
  510. createmask(getDefaultType());
  511. }
  512. function createPointLabel(){
  513. createPoint(getDefaultType());
  514. }
  515. function createPoint(classes){
  516. boxcls = classes;
  517. toCreatePoint = true;
  518. }
  519. function createrect(classes){
  520. boxcls = classes;
  521. tocreaterect = true;
  522. }
  523. function createmask(classes){
  524. boxcls = classes;
  525. tocreatemask = true;
  526. }
  527. function cancel(){
  528. hidePopup();
  529. tocreaterect=false;
  530. tocreatemask=false;
  531. if (creatingmask){
  532. creatingmask.finish=true;
  533. creatingmask = null;
  534. }
  535. // boxcls = null;
  536. drawRect();
  537. }
  538. function deleterect(){//删除矩形框或者mask
  539. hidePopup();
  540. if(SelectedRect){
  541. var index = rects.indexOf(SelectedRect);
  542. rects.splice(index, 1);
  543. // regions.splice( index, 1);
  544. SelectedRect=null;
  545. }
  546. if(Selectedmask){
  547. var index = masks.indexOf(Selectedmask);
  548. masks.splice(index, 1);
  549. // regions.splice( index+100, 1);
  550. Selectedmask=null;
  551. }
  552. if(SelectedPointShape){
  553. var index = pointShapes.indexOf(SelectedPointShape);
  554. pointShapes.splice(index, 1);
  555. // regions.splice( index+200, 1);
  556. SelectedPointShape=null;
  557. }
  558. drawRect();
  559. updateLabelHtml();
  560. save();
  561. }
  562. function deleteAllRect(){
  563. hidePopup();
  564. rects.length=0;
  565. masks.length=0;
  566. pointShapes.length=0;
  567. drawRect();
  568. updateLabelHtml();
  569. save();
  570. }
  571. function clearCanvas() {
  572. // 去除所有矩形
  573. rects = [];
  574. masks=[];
  575. pointShapes = [];
  576. // 重新绘制画布.
  577. drawRect();
  578. }
  579. //对象高级操作
  580. //
  581. //标注位置校正 移动,拉伸
  582. function moverect(rect, x, y){
  583. //x y 为拖动坐标增量
  584. for(var i =0; i < rect.points.length;i++){
  585. rect.points[i].x += x;
  586. rect.points[i].y += y;
  587. }
  588. }
  589. function moveMask(mask, x, y){
  590. //x y 为目标位置的左上角
  591. for(var i =0; i < mask.points.length;i++){
  592. mask.points[i].x += x;
  593. mask.points[i].y += y;
  594. }
  595. }
  596. function stretchmask(mask, pid, x, y){
  597. console.log("pid=" + pid + " mask.points.length=" + mask.points.length);
  598. mask.points[pid].x=x;
  599. mask.points[pid].y=y;
  600. }
  601. function stretchrect(rect, pid, x, y){
  602. //x y 为所拖动的点的目标位置
  603. diapid = rect.getdiapid(pid);
  604. rect.points[pid].x=x;
  605. rect.points[pid].y=y;
  606. var first=true;
  607. for (var j=0;j<4;j++){
  608. if((j!=diapid)&&(j!=pid)){
  609. if (first){
  610. rect.points[j].x = x;
  611. rect.points[j].y = rect.points[diapid].y;
  612. first = false;
  613. }
  614. else{
  615. rect.points[j].x = rect.points[diapid].x;
  616. rect.points[j].y = y;
  617. }
  618. }
  619. };
  620. }
  621. //图片操作
  622. //
  623. //
  624. function loadimg(){
  625. reset_var();
  626. var picturePath = labeltastresult[fileindex].pic_image_field;
  627. img.src = ip + "/getgiteaimage?filename=" + picturePath;
  628. console.log("picturePath",picturePath)
  629. var picIndex = picturePath.indexOf("/",70);
  630. if(picIndex != -1){
  631. float_text_name = picturePath.substring(picIndex + 1);
  632. float_text_name = float_text_name.substring(float_text_name.indexOf('/')+1);
  633. }else{
  634. float_text_name = picturePath.substring(picturePath.lastIndexOf("/") + 1)
  635. }
  636. console.log("float_text_name",float_text_name)
  637. var html = float_text_name + "&nbsp;&nbsp;"+ "(" + (tablePageData.current * pageSize + fileindex + 1) + "/" + tablePageData.total + ")"
  638. document.getElementById("float_text").innerHTML = html;
  639. }
  640. function save(){
  641. hidePopup();
  642. var re = updatelabel(fileindex);
  643. if (re=true){
  644. //window.alert("保存成功!");
  645. }
  646. else{window.alert("保存失败!");}
  647. showfilelist();
  648. }
  649. function clearCache(){
  650. rects = [];
  651. masks = [];
  652. pointShapes = [];
  653. }
  654. function next(){
  655. currentImage = false;
  656. hidePopup();
  657. if(fileindex<labeltastresult.length-1) {
  658. if(loadFinished==true){
  659. updatelabel(fileindex);
  660. }
  661. clearCache();
  662. fileindex=fileindex+1;
  663. loadimg();
  664. showfilelist();
  665. }else{
  666. if((tablePageData.current + 1) * pageSize < tablePageData.total){
  667. if (loadFinished==true){
  668. updatelabel(fileindex);
  669. }
  670. clearCache();
  671. nextPage();
  672. }
  673. }
  674. loadFinished=false;
  675. }
  676. function last(){
  677. currentImage = false;
  678. hidePopup();
  679. if(fileindex>0){
  680. if(loadFinished==true){
  681. loadFinished=false;
  682. updatelabel(fileindex);
  683. }
  684. clearCache();
  685. fileindex=fileindex-1;
  686. loadimg();
  687. showfilelist();
  688. }else{
  689. var current = $('#displayPage1').text();
  690. if(current > 1){
  691. lastindex = true;
  692. if(loadFinished==true){
  693. loadFinished=false;
  694. updatelabel(fileindex);
  695. }
  696. clearCache();
  697. prePage();
  698. lastindex = false;
  699. }
  700. }
  701. }
  702. function clickfilelist(index){
  703. hidePopup();
  704. clearCache();
  705. fileindex = index;
  706. loadimg();
  707. showfilelist();
  708. currentImage = false;
  709. }
  710. //画布操作、
  711. //
  712. //
  713. function onpoint(x,y,pt){
  714. var biasx = Math.abs(x - pt.x);
  715. var biasy = Math.abs(y - pt.y);
  716. if ((biasx<=3) && (biasy<=3)){
  717. return true;
  718. }
  719. else{
  720. return false;
  721. }
  722. }
  723. function onrect(x,y,recta){
  724. rectxywh = recta.getXYWH();
  725. widthstart=rectxywh[0];
  726. widthend=rectxywh[0]+rectxywh[2];
  727. heightstart=rectxywh[1];
  728. heightend=rectxywh[1]+rectxywh[3];
  729. if ((x>=widthstart&&x<(widthend))&&(y>=heightstart)&&(y<(heightend))){
  730. return true;
  731. }
  732. else{
  733. return false;
  734. }
  735. }
  736. function clearboard(){
  737. context.clearRect(0, 0, canvas.width, canvas.height);
  738. }
  739. function fillMask(mask){
  740. context.beginPath();
  741. context.moveTo(bigLocX(mask.points[0].x), bigLocY(mask.points[0].y));
  742. for (var i=1; i<mask.points.length; i++){
  743. context.lineTo(bigLocX(mask.points[i].x), bigLocY(mask.points[i].y));
  744. }
  745. context.closePath();
  746. context.fill();
  747. }
  748. //判断一个点是否在多边形中。
  749. //核心是从这个点出发垂直线或水平线,与多边形相交的次数一定是奇数
  750. function onmask_new(x,y, mask,vs) {
  751. var vs = mask.points;
  752. var inside = false;
  753. for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) {
  754. var xi = vs[i].x, yi = vs[i].y;
  755. var xj = vs[j].x, yj = vs[j].y;
  756. var intersect = ((yi > y) != (yj > y))
  757. && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
  758. if (intersect) inside = !inside;
  759. }
  760. return inside;
  761. };
  762. function drawRect(x=null,y=null,resize=0) {
  763. //document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  764. //document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  765. //清除画布,准备绘制
  766. context.clearRect(0, 0, canvas.width, canvas.height);
  767. var imgWidth = canvas.width;
  768. var imgHeight = canvas.height
  769. if(imgScale > 1){//当没有放大时,就用画布的大小
  770. imgWidth = canvas.width * imgScale;
  771. imgHeight = canvas.height * imgScale;
  772. }
  773. //console.log("startx=" + startx + " starty=" + starty + " img.width=" + img.width + " imgWidth=" + imgWidth + " imgScale=" + imgScale + " img.width / (canvas.width * imgScale)=" + (img.width / (canvas.width * imgScale)));
  774. context.drawImage(
  775. img, //规定要使用的图像、画布或视频。
  776. startx, starty, //开始剪切的 x 坐标位置。
  777. img.width, img.height, //被剪切图像的高度。
  778. //imgWidth, imgHeight,
  779. 0, 0,//在画布上放置图像的 x 、y坐标位置。
  780. imgWidth, imgHeight //要使用的图像的宽度、高度
  781. //canvas.width,canvas.height
  782. );
  783. //context.drawImage(img, 0, 0, imgWidth, imgHeight, 0, 0, canvas.width, canvas.height);
  784. //context.drawImage(img,0,0,canvas.width,canvas.height);
  785. //遍历画所有矩形框
  786. drawRectShape();
  787. //创建Rect时,显示横竖两条黑线
  788. if (tocreaterect && (x!=-1)){
  789. //row
  790. context.strokeStyle="black"
  791. context.beginPath();
  792. context.moveTo(0,y);
  793. context.lineTo(canvas.width,y);
  794. context.moveTo(x,0);
  795. context.lineTo(x,canvas.height);
  796. context.stroke();
  797. context.closePath();
  798. }
  799. //遍历画所有Mask矩形框
  800. drawMaskShape(x,y);
  801. //遍历画所有的圆点
  802. drawPointShape();
  803. }
  804. function drawPointShape(){
  805. for(var i = 0; i < pointShapes.length; i++){
  806. context.strokeStyle="yellow";
  807. selectColor(pointShapes,i);
  808. context.beginPath();//标志开始一个路径
  809. context.arc(bigLocX(pointShapes[i].x),bigLocY(pointShapes[i].y),5,0,2*Math.PI);//在canvas中绘制圆形
  810. if(pointShapes[i].isSelected){
  811. console.log("choose a point.");
  812. context.fillStyle = "rgba(97, 216, 162, 0.5)";
  813. context.fill();
  814. }
  815. context.stroke()
  816. }
  817. }
  818. function bigLocX(x){
  819. var tmp = img.width / (canvas.width * imgScale);
  820. return x * imgScale - startx/tmp ;
  821. }
  822. function bigLocY(y){
  823. var tmp = img.height / (canvas.height * imgScale);
  824. return y * imgScale - starty /tmp;
  825. }
  826. function smallLocX(x){
  827. var tmp = img.width /canvas.width;
  828. return x / imgScale + startx/tmp;
  829. }
  830. function smallLocY(y){
  831. var tmp = img.height /canvas.height;
  832. return y / imgScale + starty / tmp;
  833. }
  834. //画所有矩形框
  835. function drawRectShape(){
  836. var drawLineWidth = 1;
  837. for(var i=0; i<rects.length; i++) {
  838. var rect = rects[i];
  839. rectxywh = rect.getXYWH();
  840. x1y1x2y2 = rect.getX1Y1X2Y2();
  841. // 绘制矩形
  842. if (rect.isSelected) {
  843. context.fillStyle = "rgba(97, 216, 162, 0.7)";
  844. //context.fillStyle = "rgba(10, 114, 6, 0.5)";
  845. //context.fillRect(bigLocX(rectxywh[0]),bigLocY(rectxywh[1]),bigLocX(rectxywh[2]),bigLocY(rectxywh[3]));
  846. context.fillRect(bigLocX(x1y1x2y2[0]),bigLocY(x1y1x2y2[1]),bigLocX(x1y1x2y2[2]) - bigLocX(x1y1x2y2[0]),bigLocY(x1y1x2y2[3]) - bigLocY(x1y1x2y2[1]));
  847. context.lineWidth = drawLineWidth;
  848. }
  849. else if(rect.mouseonrect || rect.mouseonpoint){//鼠标移到矩形框中或者在矩形点上
  850. context.fillStyle = "rgba(97, 216, 162, 0.2)";
  851. //context.fillStyle = "rgba(10, 114, 6, 0.5)";
  852. //context.fillRect(bigLocX(rectxywh[0]),bigLocY(rectxywh[1]),bigLocX(rectxywh[2]),bigLocY(rectxywh[3]));
  853. context.fillRect(bigLocX(x1y1x2y2[0]),bigLocY(x1y1x2y2[1]),bigLocX(x1y1x2y2[2]) - bigLocX(x1y1x2y2[0]),bigLocY(x1y1x2y2[3]) - bigLocY(x1y1x2y2[1]));
  854. context.lineWidth = drawLineWidth;
  855. }
  856. else{
  857. context.lineWidth = drawLineWidth;
  858. }
  859. // if(rect.type == "person"){
  860. // context.strokeStyle = color_person[ i % 4];
  861. // }else{
  862. context.strokeStyle=color_dict["rect"]; //初始颜色
  863. // }
  864. selectColor(rects,i);
  865. setVerifyLineWidth(rect);
  866. //context.strokeRect(bigLocX(rectxywh[0]),bigLocY(rectxywh[1]),bigLocX(rectxywh[2]),bigLocY(rectxywh[3]),rect.color);
  867. context.strokeRect(bigLocX(x1y1x2y2[0]),bigLocY(x1y1x2y2[1]),bigLocX(x1y1x2y2[2]) - bigLocX(x1y1x2y2[0]),bigLocY(x1y1x2y2[3]) - bigLocY(x1y1x2y2[1]),rect.color);
  868. setVerifyText(rect,bigLocX(x1y1x2y2[0]),bigLocY(x1y1x2y2[1]));
  869. for(var j=0; j<4; j++){
  870. var p = rect.points[j]
  871. // context.fillStyle = "green";
  872. // context.fillRect(p.x-3,p.y-3,6,6);
  873. if (rect.mouseonpoint){
  874. context.fillStyle = color_dict["pointselected"];
  875. context.fillRect(bigLocX(p.x)-5,bigLocY(p.y)-5,10,10);
  876. }
  877. else{
  878. context.fillStyle = color_dict["point"];
  879. context.fillRect(bigLocX(p.x)-3,bigLocY(p.y)-3,6,6);
  880. }
  881. }
  882. }
  883. }
  884. function setVerifyText(rect,x,y){
  885. if(!isEmpty(rect.other.region_attributes.verify)){
  886. if(rect.other.region_attributes.verify != 0){
  887. context.font = "15px Georgia";
  888. context.fillStyle= context.strokeStyle;
  889. context.fillText(verifyMap[rect.other.region_attributes.verify], x,y-5);
  890. }
  891. }
  892. }
  893. function setVerifyLineWidth(rect){
  894. if(!isEmpty(rect.other.region_attributes.verify)){
  895. if(rect.other.region_attributes.verify != 0){
  896. context.lineWidth = 3;
  897. context.strokeStyle = "#DC143C";
  898. }
  899. }
  900. }
  901. function selectColor(regions,i){
  902. if(!isEmpty(_via_attributes['region']['type'])){
  903. var dict = _via_attributes['region']['type']["options"];
  904. var color_num=0;
  905. for (var key in dict){
  906. if (key==regions[i].other.region_attributes.type){
  907. context.strokeStyle=color_all[String(color_num)];
  908. break;
  909. }
  910. color_num++;
  911. }
  912. }
  913. }
  914. function drawMaskShape(x,y){
  915. for (var i=0; i<masks.length; i++){
  916. context.strokeStyle="purple"
  917. var mask =masks[i];
  918. if (mask.isSelected){
  919. context.lineWidth = 3;
  920. }
  921. else{
  922. context.lineWidth = 2;
  923. }
  924. selectColor(masks,i);
  925. for (var j=1; j<mask.points.length; j++){
  926. context.beginPath();
  927. context.moveTo(bigLocX(mask.points[j-1].x), bigLocY(mask.points[j-1].y));
  928. context.lineTo(bigLocX(mask.points[j].x),bigLocY(mask.points[j].y));
  929. context.stroke();
  930. // context.closePath();
  931. }
  932. if(mask.finish){
  933. context.moveTo(bigLocX(mask.points[mask.points.length-1].x), bigLocY(mask.points[mask.points.length-1].y));
  934. context.lineTo(bigLocX(mask.points[0].x), bigLocY(mask.points[0].y));
  935. context.stroke();
  936. context.closePath();
  937. // 绘制Mask
  938. if (mask.isSelected) {
  939. context.fillStyle = "rgba(97, 216, 162, 0.5)";
  940. fillMask(mask);
  941. }
  942. else if(mask.mouseonmask || mask.mouseonpoint){
  943. context.fillStyle = "rgba(97, 216, 162, 0.2)";
  944. fillMask(mask);
  945. }
  946. }
  947. else{
  948. if(x&&y){
  949. context.beginPath();
  950. context.moveTo(bigLocX(mask.points[mask.points.length-1].x),bigLocY(mask.points[mask.points.length-1].y));
  951. context.lineTo(x,y);
  952. context.stroke();
  953. // context.closePath();
  954. }
  955. }
  956. for (var j=0; j<mask.points.length; j++){
  957. var p = mask.points[j]
  958. if (onpoint(smallLocX(x),smallLocY(y),p)){
  959. context.fillStyle = color_dict["pointselected"];
  960. context.fillRect(bigLocX(p.x)-5,bigLocY(p.y)-5,10,10);
  961. }
  962. else{
  963. context.fillStyle = color_dict["point"];
  964. context.fillRect(bigLocX(p.x)-3,bigLocY(p.y)-3,6,6);
  965. }
  966. }
  967. }
  968. }
  969. function resetSelectShapeEmpty(){
  970. if (Selectedmask != null){
  971. console.log("set select mask is null.");
  972. if (SelectedmaskpointId != null){
  973. Selectedmask.points[SelectedmaskpointId].isSelected = false;
  974. SelectedmaskpointId = null;
  975. }
  976. Selectedmask.isSelected = false;
  977. Selectedmask = null;
  978. }
  979. if (SelectedRect != null){
  980. console.log("set select rect is null.");
  981. if (SelectedpointId != null){
  982. SelectedRect.points[SelectedpointId].isSelected = false;
  983. SelectedpointId= null;
  984. }
  985. SelectedRect.isSelected = false;
  986. SelectedRect = null;
  987. }
  988. if(SelectedPointShape != null){
  989. SelectedPointShape = null;
  990. }
  991. }
  992. function clickPointInMask(clickX,clickY){
  993. //查看点击的点是否是Mask的标注点,如果是,则着重显示该点。
  994. for(var i=masks.length-1; i>=0; i--) {
  995. var mask = masks[i];
  996. var maskpoints = mask.points
  997. for (var j=0;j<maskpoints.length;j++){
  998. var pt = maskpoints[j];
  999. if (onpoint(smallLocX(clickX),smallLocY(clickY),pt)){
  1000. mask.isSelected=true;
  1001. Selectedmask = mask;
  1002. stretch_mask = true;
  1003. SelectedmaskpointId=j;
  1004. //更新显示
  1005. drawRect(clickX,clickY);
  1006. //停止搜索
  1007. return true;
  1008. }
  1009. }
  1010. }
  1011. //检查点击的点是否在某个Mask的范围内,如果是,则该Mask的范围内背景色需要修改,显示该Mask的标注信息
  1012. for(var i=masks.length-1; i>=0; i--) {
  1013. var mask = masks[i];
  1014. if (onmask_new(smallLocX(clickX),smallLocY(clickY),mask)){
  1015. Selectedmask = mask;
  1016. console.log("at mask.clickX=" + clickX + " clicky=" + clickY);
  1017. mask.isSelected=true;
  1018. Selectedmask = mask;
  1019. // 允许被拉伸
  1020. stretch_mask =true;
  1021. //允许拖动
  1022. isDragging = true;
  1023. old_click_x1=clickX;
  1024. old_click_y1=clickY;
  1025. //更新显示
  1026. drawRect();
  1027. //弹出标注信息框
  1028. var bound = mask.getBound();
  1029. var new_region_id =i;
  1030. regions = masks;
  1031. select_only_region(new_region_id);
  1032. showPopup(bigLocY(bound[3])+5, bigLocX(bound[2])+5,i,"mask");
  1033. // showPopup(bigLocY(bound[3])+145, bigLocX(bound[2]) + 235,i,"mask");
  1034. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1035. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1036. //停止搜索
  1037. return true;
  1038. }else{
  1039. //console.log("not at mask.clickX=" + clickX + " clicky=" + clickY);
  1040. }
  1041. }
  1042. return false;
  1043. }
  1044. function clickPointInRect(clickX,clickY){
  1045. // //查看点击的点是否是Rect的标注点,如果是,则着重显示该点。
  1046. for(var i=rects.length-1; i>=0; i--) {
  1047. var rect = rects[i];
  1048. var rectpoints = rect.points
  1049. for (var j=0;j<rectpoints.length;j++){
  1050. var pt = rectpoints[j];
  1051. //console.log("clickX,clickY=" + clickX + "," + clickY + " smallLocX,smallLocY=" + smallLocX(clickX) + "," +smallLocY(clickY) + " pt.x,pt.y=" + pt.x + "," + pt.y);
  1052. if (onpoint(smallLocX(clickX),smallLocY(clickY),pt)){
  1053. pt.isSelected=true;
  1054. rect.isSelected=true;
  1055. SelectedRect = rect;
  1056. SelectedpointId = j;
  1057. stretch = true;//允许拉伸
  1058. console.log("choose rect 3333:");
  1059. //更新显示
  1060. drawRect();
  1061. //停止搜索
  1062. return true;
  1063. }
  1064. }
  1065. }
  1066. for(var i=rects.length-1; i>=0; i--) {
  1067. var rect = rects[i];
  1068. if (onrect(smallLocX(clickX),smallLocY(clickY),rect)){
  1069. SelectedRect = rect;
  1070. old_click_x1=clickX;
  1071. old_click_y1=clickY;
  1072. //选择新圆圈
  1073. rect.isSelected = true;
  1074. //允许拖拽
  1075. isDragging = true;
  1076. //更新显示
  1077. drawRect();
  1078. xy = rect.getX1Y1X2Y2();
  1079. console.log("choose rect 2: top=" + clickX + " left=" + clickY + " x1=" + xy[0] + " y1=" + xy[1] + " x2=" + xy[2] + " y2=" + xy[3] + " startx=" + startx + " starty=" + starty);
  1080. select_only_region(i);
  1081. showPopup(bigLocY(xy[1])+5, bigLocX(xy[2])+5 , i,"rect");
  1082. // showPopup(bigLocY(xy[3])+145, bigLocX(xy[2]) + 235,i,"rect");
  1083. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1084. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1085. //停止搜索
  1086. return true;
  1087. }
  1088. }
  1089. return false;
  1090. }
  1091. function clickPointInPointShape(clickX,clickY){
  1092. var t = -1;
  1093. for(var i = 0; i < pointShapes.length; i++){
  1094. if (onpoint(smallLocX(clickX),smallLocY(clickY),pointShapes[i])){
  1095. console.log("clickX=," + clickX + "clickY=," + clickY + " pointShapes[i].x=" + + pointShapes[i].x + "pointShapes[i].y=" + pointShapes[i].y);
  1096. pointShapes[i].isSelected=true;
  1097. SelectedPointShape = pointShapes[i];
  1098. t = i;
  1099. }else{
  1100. pointShapes[i].isSelected=false;
  1101. }
  1102. }
  1103. if( t >= 0){
  1104. drawRect();
  1105. select_only_region(t);
  1106. showPopup(bigLocY(SelectedPointShape.y) +5, bigLocX(SelectedPointShape.x) +5,t,"pointshape");
  1107. // showPopup(bigLocY(SelectedPointShape.y) + 165, bigLocX(SelectedPointShape.x) + 250,t,"pointshape");
  1108. //showPopup(bigLocY(SelectedPointShape.y) + 165, bigLocX(SelectedPointShape.x) + 250,t,"pointshape");
  1109. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1110. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1111. return true;
  1112. }
  1113. return false;
  1114. }
  1115. //交互
  1116. //画布内鼠标响应操作
  1117. function canvasClick(e) {
  1118. // 取得画布上被单击的点
  1119. var clickX = e.pageX - getElementLeft(canvas);
  1120. var clickY = e.pageY - getElementTop(canvas);
  1121. var smallClickX = smallLocX(clickX);
  1122. var smallClickY = smallLocY(clickY);
  1123. if (tocreaterect){
  1124. var rect=new rectar(smallClickX,smallClickY,smallClickX,smallClickY,boxcls);
  1125. rects.push(rect);
  1126. console.log("draw rect...10");
  1127. showpopVar = true;
  1128. tocreaterect=false;
  1129. hidePopup();
  1130. undoShape = rect;
  1131. }
  1132. if (tocreatemask){
  1133. showpopVar = true;
  1134. hidePopup();
  1135. if (creatingmask == null){
  1136. var mask=new maskar(smallClickX,smallClickY,boxcls);
  1137. masks.push(mask);
  1138. Selectedmask = mask;
  1139. creatingmask = mask;
  1140. }
  1141. else{
  1142. if (onpoint(smallClickX,smallClickY,creatingmask.points[0])){
  1143. Selectedmask.finish=true;
  1144. creatingmask=null;
  1145. tocreatemask=false;
  1146. drawRect();
  1147. var new_region_id =masks.length-1;
  1148. var bound = masks[new_region_id].getBound();
  1149. regions = masks;
  1150. set_region_annotations_to_default_value( new_region_id );
  1151. select_only_region(new_region_id);
  1152. showPopup(bigLocY(bound[3])+5, bigLocX(bound[2])+5,new_region_id,"mask");
  1153. // showPopup(bigLocY(bound[3])+145, bigLocX(bound[2]) + 235,i,"mask");
  1154. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1155. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1156. undoShape = masks[new_region_id];
  1157. resetSelectShapeEmpty();
  1158. return;
  1159. }
  1160. creatingmask.points.push(new point(smallClickX,smallClickY))
  1161. }
  1162. }
  1163. if(toCreatePoint){
  1164. console.log("point x,y=" + clickX + "," + clickY);
  1165. var pointObj = new pointShape(smallClickX,smallClickY,boxcls);
  1166. pointShapes.push(pointObj);
  1167. var len_points = pointShapes.length;
  1168. var new_region_id =len_points-1;
  1169. regions = pointShapes;
  1170. set_region_annotations_to_default_value(new_region_id);
  1171. toCreatePoint = false;
  1172. undoShape = pointShapes[new_region_id];
  1173. }
  1174. //将选择信息设置为空,在下面重新查找设置
  1175. resetSelectShapeEmpty();
  1176. if(clickPointInPointShape(clickX,clickY)){
  1177. return;
  1178. }
  1179. //如果点在Mask内,已经画完了,则返回。
  1180. if(clickPointInMask(clickX,clickY)){
  1181. return;
  1182. }
  1183. //如果点在Rect内,已经画完了,则返回。
  1184. if(clickPointInRect(clickX,clickY)){
  1185. return;
  1186. }
  1187. //如果点不在标注区域内
  1188. drawRect(clickX,clickY);
  1189. hidePopup();
  1190. dragging = true;
  1191. old_click_x1 = clickX;
  1192. old_click_y1 = clickY;
  1193. }
  1194. function dragRect(e) {
  1195. // 取得鼠标位置
  1196. var x = e.pageX - getElementLeft(canvas);
  1197. var y = e.pageY - getElementTop(canvas);
  1198. var smallX = smallLocX(x);
  1199. var smallY = smallLocY(y);
  1200. if (tocreaterect || tocreatemask){
  1201. drawRect(x,y);
  1202. }
  1203. //悬停变色
  1204. var found=false;
  1205. for(var i=rects.length-1; i>=0; i--) {
  1206. var rect = rects[i];
  1207. var rectpoints = rect.points
  1208. for (var j=0;j<rectpoints.length;j++){
  1209. var pt = rectpoints[j];
  1210. if (onpoint(smallX,smallY,pt)){
  1211. rect.mouseonpoint=true;
  1212. mouseonpoint_rect = rect;
  1213. //更新显示
  1214. drawRect(x,y);
  1215. //停止搜索
  1216. found=true;
  1217. break;
  1218. }
  1219. }
  1220. if (found){
  1221. break;
  1222. }
  1223. }
  1224. for(var i=masks.length-1; i>=0; i--) {
  1225. var mask = masks[i];
  1226. var maskpoints = mask.points
  1227. for (var j=0;j<maskpoints.length;j++){
  1228. var pt = maskpoints[j];
  1229. if (onpoint(smallX,smallY,pt)){
  1230. mask.mouseonpoint=true;
  1231. mouseonpoint_mask = mask;
  1232. //更新显示
  1233. drawRect(x,y);
  1234. //停止搜索
  1235. found=true;
  1236. break;
  1237. }
  1238. }
  1239. if (found){
  1240. break;
  1241. }
  1242. }
  1243. if ((!found)&& (mouseonpoint_mask!=null)&&(!stretch)) {
  1244. mouseonpoint_mask.mouseonpoint=false;
  1245. mouseonpoint_mask=null;
  1246. drawRect(x,y);
  1247. }
  1248. if ((!found)&& (mouseonpoint_rect!=null)&&(!stretch)) {
  1249. mouseonpoint_rect.mouseonpoint=false;
  1250. mouseonpoint_rect=null;
  1251. drawRect(x,y);
  1252. }
  1253. if (!found){//不在点上
  1254. for(var i=rects.length-1; i>=0; i--) {
  1255. var rect = rects[i];
  1256. if (onrect(smallX,smallY,rect)){
  1257. if (mouseonrect_rect) {mouseonrect_rect.mouseonrect=false;}
  1258. rect.mouseonrect=true;
  1259. mouseonrect_rect = rect;
  1260. //更新显示
  1261. drawRect(x,y);
  1262. //停止搜索
  1263. found=true;
  1264. break;
  1265. }
  1266. }
  1267. for(var i=masks.length-1; i>=0; i--) {
  1268. var mask = masks[i];
  1269. var maskpoints = mask.points
  1270. if (onmask_new(smallX,smallY,mask)){
  1271. if (mouseonmask_mask) {mouseonmask_mask.mouseonmask=false;}
  1272. mask.mouseonmask=true;
  1273. mouseonmask_mask = mask;
  1274. //更新显示
  1275. drawRect(x,y);
  1276. //停止搜索
  1277. found=true;
  1278. break;
  1279. }
  1280. }
  1281. if((!found)&& (mouseonrect_rect!=null)){
  1282. mouseonrect_rect.mouseonrect=false;
  1283. mouseonrect_rect=null;
  1284. drawRect(x,y);
  1285. }
  1286. if((!found)&& (mouseonmask_mask!=null)){
  1287. mouseonmask_mask.mouseonmask=false;
  1288. mouseonmask_mask=null;
  1289. drawRect(x,y);
  1290. }
  1291. }
  1292. // 判断矩形是否开始拖拽
  1293. if (isDragging == true) {
  1294. // 判断拖拽对象是否存在
  1295. if (SelectedRect != null) {
  1296. // 将圆圈移动到鼠标位置
  1297. //console.log("old(" + old_click_x1 + "," + old_click_y1 +") new(" + x + "," + y + ")");
  1298. moverect(SelectedRect, x-old_click_x1, y-old_click_y1);
  1299. old_click_x1 = x;
  1300. old_click_y1 = y;
  1301. // 更新画布
  1302. drawRect();
  1303. }else if(Selectedmask != null){
  1304. moveMask(Selectedmask, x-old_click_x1, y-old_click_y1);
  1305. old_click_x1 = x;
  1306. old_click_y1 = y;
  1307. // 更新画布
  1308. drawRect();
  1309. }
  1310. hidePopup();
  1311. }
  1312. //判断是否开始拉伸
  1313. if (stretch) {
  1314. stretchrect(SelectedRect, SelectedpointId, smallLocX(x), smallLocY(y));
  1315. drawRect();
  1316. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1317. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1318. }
  1319. //判断mask是否开始拉伸
  1320. if (stretch_mask && SelectedmaskpointId != null) {
  1321. stretchmask(Selectedmask, SelectedmaskpointId, smallLocX(x), smallLocY(y));
  1322. drawRect();
  1323. }
  1324. if(dragging){
  1325. var dx = x - old_click_x1;
  1326. var dy = y - old_click_y1;
  1327. startx -= dx;
  1328. starty -= dy;
  1329. console.log("x=" + x + " y=" + y + " move x=" + dx + " move y=" + dy + " startx=" +startx + ",starty=" + starty);
  1330. drawRect();
  1331. old_click_x1 = x;
  1332. old_click_y1 = y;
  1333. }
  1334. };
  1335. function stopDragging() {
  1336. isDragging = false;
  1337. dragging = false;
  1338. stretch=false;
  1339. stretch_mask=false;
  1340. //console.log("choose rect 10:")
  1341. if (tocreaterect) {
  1342. drawRect(-1,-1);
  1343. }
  1344. if(showpopVar){
  1345. showpopVar= false;
  1346. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1347. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1348. for(var i=rects.length-1; i>=0; i--) {
  1349. var rect = rects[i];
  1350. if (rect.isSelected){
  1351. xy = rect.getX1Y1X2Y2();
  1352. console.log("create rect show: x1=" + xy[0] + " y1=" + xy[1] + " x2=" + xy[2] + " y2=" + xy[3] + " startx=" + startx + ",starty=" + starty);
  1353. // wang
  1354. // var original_img_region = new file_region();
  1355. var new_region_id =i;
  1356. regions = rects;
  1357. set_region_annotations_to_default_value( new_region_id );
  1358. select_only_region(new_region_id);
  1359. showPopup(bigLocY(xy[3])+5, bigLocX(xy[2])+5 , i,"rect");
  1360. // showPopup(bigLocY(xy[3])+145, bigLocX(xy[2]) + 235, i,"rect");
  1361. //停止搜索
  1362. return;
  1363. }
  1364. }
  1365. for(var i=masks.length-1; i>=0; i--) {
  1366. var mask = masks[i];
  1367. if (mask.isSelected && mask.finish){
  1368. var new_region_id =i;
  1369. regions = masks;
  1370. select_only_region(new_region_id);
  1371. set_region_annotations_to_default_value(new_region_id);
  1372. var bound = mask.getBound();
  1373. showPopup(bigLocY(bound[3])+5, bigLocX(bound[2])+5 ,i,"mask");
  1374. // showPopup(bigLocY(bound[3])+145, bigLocX(bound[2]) + 235,i,"mask");
  1375. console.log("create mask--show...13");
  1376. //停止搜索
  1377. return;
  1378. }
  1379. }
  1380. for(var i=pointShapes.length-1; i>=0; i--) {
  1381. var pointShape = pointShapes[i];
  1382. if (pointShape.isSelected && pointShape.finish){
  1383. var new_region_id =i;
  1384. regions = pointShapes;
  1385. select_only_region(new_region_id);
  1386. set_region_annotations_to_default_value(new_region_id);
  1387. // var bound = mask.getBound();
  1388. showPopup(bigLocY(pointShape.x)+5, bigLocX(pointShape.y)+5 ,i,"pointShapes");
  1389. // showPopup(bigLocY(pointShape.x)+145, bigLocX(pointShape.y) + 235,i,"pointShapes");
  1390. console.log("create mask--show...13");
  1391. //停止搜索
  1392. return;
  1393. }
  1394. }
  1395. }
  1396. };
  1397. function updateLabelHtml(){
  1398. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1399. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1400. }
  1401. //边栏
  1402. //任务信息
  1403. function showtaskinfo(){
  1404. $('#task_info').text(label_task_info.task_name);
  1405. $('#task_progress').text(label_task_info.task_status_desc);
  1406. var percent=label_task_info.task_status_desc.split('(')[0]
  1407. $("div[role='progressbar']").width(percent)
  1408. $("div[role='progressbar']").attr('aria-valuemax',tablePageData.total)
  1409. }
  1410. var orderType = 1;
  1411. var findLast = 0;
  1412. function showOrder(value){
  1413. console.log("--------",value)
  1414. hidePopup();
  1415. if (value == "1"){ //文件名排序
  1416. console.log("value=1")
  1417. orderType = 1;
  1418. findLast = 0;
  1419. }
  1420. else if (value == "2"){
  1421. console.log("value=2")
  1422. orderType = 0;
  1423. findLast = 0;
  1424. }
  1425. else if (value == "3"){
  1426. orderType = 0;
  1427. findLast = 3;
  1428. }
  1429. page(0,pageSize);
  1430. }
  1431. function skipLast(){
  1432. hidePopup();
  1433. if (orderType == 0){
  1434. return ;
  1435. }
  1436. findLast = 1;
  1437. page(0,pageSize);
  1438. }
  1439. function isVerified(){
  1440. if(userType == 2 && label_task_status == 1){
  1441. return true;
  1442. }
  1443. return false;
  1444. }
  1445. //显示文件列表
  1446. function showfilelist(){
  1447. var htmlstr="";
  1448. for (var i=0;i<labeltastresult.length;i++){
  1449. var fname = labeltastresult[i].pic_image_field.substring(labeltastresult[i].pic_image_field.lastIndexOf('/') + 1);
  1450. if(labeltastresult[i].pic_image_field.length > 70){
  1451. var tmpIndex = labeltastresult[i].pic_image_field.indexOf("/",70);
  1452. console.log(tmpIndex)
  1453. if(tmpIndex != -1){
  1454. fname = labeltastresult[i].pic_image_field.substring(tmpIndex + 1);
  1455. fname = fname.substring(fname.indexOf('/')+1);
  1456. }
  1457. }
  1458. var isfinished = labeltastresult[i].label_status;
  1459. if(isVerified()){
  1460. isfinished = labeltastresult[i].verify_status - 1;
  1461. }
  1462. var lablebg=" style=\"cursor:pointer\"";
  1463. var classStr = "style=\"color:#FF6200;background: transparent;border: 0;\"";
  1464. var finish="未完成";
  1465. if (isfinished=="0"){finish="已完成";classStr = "style=\"color:#27c24c;background: transparent;border: 0;\"";}
  1466. if (i==fileindex){lablebg=" style=\"color:#fff;cursor:pointer;\"";classStr = "style=\"color:#04B3E5;background: transparent;border: 0;\"";finish="标注中"}
  1467. if(isVerified()){
  1468. htmlstr = htmlstr+"<tr onclick=\"clickfilelist("+i+");\""+ lablebg+"> <td width=\"70\"" +"style=\"vertical-align:middle\""+ classStr + ">"+"<button"+classStr+" type=\"button\" onclick=\"changeVerifyStatus("+i+");\" style=\"border:none;background:none\">"+finish +"</button>"+"</td><td>"+ fname+ "</td></tr>";
  1469. }else{
  1470. htmlstr = htmlstr+"<tr onclick=\"clickfilelist("+i+");\""+lablebg+"><td>"+fname+"</td><td width=\"110\""+"style=\"vertical-align:middle\">"+"<button onclick=\"changeStatus("+i+");\" "+ classStr +" style=\"border:none;background:none\">"+finish +"</button>"+"</td></tr>";
  1471. }
  1472. }
  1473. document.getElementById("filelist").innerHTML=htmlstr;
  1474. }
  1475. function changeStatus(i){
  1476. var tmpId='changeStatus_'+i;
  1477. var htmlstr= "<div class=\"panel\" style=\"background:#020004;border:0.5px solid #222324;margin-bottom:0;border-radius:0;\""
  1478. +">"
  1479. +"<label for=\"st\" style=\"padding:0.8em;color: #7092BE;\"> 标注状态修改为:</label>"+
  1480. "<select id="+tmpId+" name=\"标注状态\" style=\"text-align:center;border-radius:4px;margin-left: 1em;\">"+
  1481. "<option value=0 selected=\"\">已完成</option>"+
  1482. "<option value=1 >未完成</option>"+
  1483. "</select>"+
  1484. "<button onclick=\"updateStatus("+i+");\" class=\"btn\" style=\"padding:0;margin-left:3em;background: transparent;border:0;color:#04B3E5;\">提交</button>"
  1485. +"</div>"
  1486. document.getElementById("labelStatus").innerHTML=htmlstr;
  1487. }
  1488. // function changeStatus(i){
  1489. // var tmpId='changeStatus_'+i;
  1490. // var htmlstr= "<div class=\"panel\" style=background:#ffff;border: 1px solid rgba(0,0,0,0.2);border-radius: 6px;top:10px;"
  1491. // +">"
  1492. // +"<label for=\"st\" style=\"margin:15px;color:#333\"> 标注状态修改为:</label>"+
  1493. // "<select id="+tmpId+" name=\"标注状态\" style=\"width:100px;text-align:center;border-radius:4px;\">"+
  1494. // "<option value=0 selected=\"\">已完成</option>"+
  1495. // "<option value=1 >未完成</option>"+
  1496. // "</select>"+
  1497. // "<br />"+
  1498. // "<button onclick=\"updateStatus("+i+");\" class=\"btn btn-default\" style=\"margin:0 auto;display: block;border-radius:5px;width: 50px;\">提交</button>"
  1499. // +"</div>"
  1500. // document.getElementById("labelStatus").innerHTML=htmlstr;
  1501. // }
  1502. function changeVerifyStatus(i){
  1503. var tmpId='changeStatus_'+i;
  1504. var htmlstr= "<div class=\"panel\" style=background:#ffff;border: 1px solid rgba(0,0,0,0.2);border-radius: 6px;top:10px;"
  1505. +">"
  1506. +"<label for=\"st\" style=\"margin:15px;color:#333\"> 审核状态修改为:</label>"+
  1507. "<select id="+tmpId+" name=\"审核状态\" style=\"width:100px;text-align:center;border-radius:4px;\">"+
  1508. "<option value=1 selected=\"\">已完成</option>"+
  1509. "<option value=0 >未完成</option>"+
  1510. "</select>"+
  1511. "<br />"+
  1512. "<button onclick=\"updateVerifyStatus("+i+");\" class=\"btn btn-default\" style=\"margin:0 auto;display: block;border-radius:5px;width: 50px;\">提交</button>"
  1513. +"</div>"
  1514. document.getElementById("labelStatus").innerHTML=htmlstr;
  1515. }
  1516. function updateStatus(i){
  1517. var status_id = 'changeStatus_'+i;
  1518. var label_status=document.getElementById(status_id).value;
  1519. labeltastresult[fileindex].label_status = label_status;
  1520. $.ajax({
  1521. type:"PATCH",
  1522. url:ip + "/gitea/label-task-item-status/",
  1523. contentType:'application/json',
  1524. headers: {
  1525. authorization:token,
  1526. },
  1527. dataType:"json",
  1528. async:false,
  1529. data:JSON.stringify({'id':labeltastresult[fileindex].id,
  1530. 'label_task_id':label_task_info.id,
  1531. 'label_status':label_status,
  1532. }),
  1533. success:function(json){
  1534. showfilelist();
  1535. document.getElementById("labelStatus").innerHTML = "";
  1536. return true;
  1537. },
  1538. error:function(response) {
  1539. redirect(response);
  1540. }
  1541. });
  1542. }
  1543. function updateVerifyStatus(i){
  1544. var status_id = 'changeStatus_'+i;
  1545. var verify_status=document.getElementById(status_id).value;
  1546. labeltastresult[fileindex].verify_status = verify_status;
  1547. $.ajax({
  1548. type:"PATCH",
  1549. url:ip + "/gitea/label-task-item-verify-status/",
  1550. contentType:'application/json',
  1551. headers: {
  1552. authorization:token,
  1553. },
  1554. dataType:"json",
  1555. async:false,
  1556. data:JSON.stringify({'id':labeltastresult[fileindex].id,
  1557. 'label_task_id':label_task_info.id,
  1558. 'verify_status':verify_status,
  1559. }),
  1560. success:function(json){
  1561. showfilelist();
  1562. document.getElementById("labelStatus").innerHTML = "";
  1563. return true;
  1564. },
  1565. error:function(response) {
  1566. redirect(response);
  1567. }
  1568. });
  1569. }
  1570. //this.id =""; //标识
  1571. //this.blurred=false;//模糊不清的; 记不清的; 难以区分的; 模棱两可的
  1572. //this.goodIllumination = true; //照明
  1573. //this.frontview = true;//正面图
  1574. function parse_labelinfo(labelinfo){
  1575. rects.length = 0;
  1576. masks.length = 0;
  1577. pointShapes.length = 0;
  1578. if(!isEmpty(labelinfo)){
  1579. // console.log("标注信息:"+labelinfo);
  1580. var label_arr = JSON.parse(labelinfo);
  1581. for(var i=0;i<label_arr.length;i++){
  1582. if(!isEmpty(label_arr[i].mask)){
  1583. cls=label_arr[i].class_name;
  1584. var tmpMask = new maskar(getCanvasLocationX(label_arr[i].mask[0]),getCanvasLocationY(label_arr[i].mask[1]),cls);
  1585. for(var j = 2; j < label_arr[i].mask.length; j+=2){
  1586. tmpMask.points.push(new point(getCanvasLocationX(label_arr[i].mask[j]),getCanvasLocationY(label_arr[i].mask[j+1])));
  1587. }
  1588. if(!isEmpty(label_arr[i].id)){
  1589. tmpMask.id= label_arr[i].id;
  1590. }
  1591. if(!isEmpty(label_arr[i].blurred)){
  1592. tmpMask.blurred = label_arr[i].blurred;
  1593. }
  1594. if(!isEmpty(label_arr[i].goodIllumination)){
  1595. tmpMask.goodIllumination = label_arr[i].goodIllumination;
  1596. }
  1597. if(!isEmpty(label_arr[i].frontview)){
  1598. tmpMask.frontview = label_arr[i].frontview;
  1599. }
  1600. if(!isEmpty(label_arr[i].other)){
  1601. tmpMask.other = label_arr[i].other;
  1602. }else if (isEmpty(label_arr[i].other)){
  1603. tmpMask.other["region_attributes"]["type"] = tmpMask.type;
  1604. tmpMask.other["region_attributes"]["id"] = tmpMask.id;
  1605. }
  1606. tmpMask.finish = true;
  1607. if (maxIdNum< parseInt(tmpMask.other["region_attributes"]["id"])){
  1608. maxIdNum = parseInt(tmpMask.other["region_attributes"]["id"]);
  1609. }
  1610. masks.push(tmpMask);
  1611. }
  1612. else if(!isEmpty(label_arr[i].box)){
  1613. x1 = getCanvasLocationX(label_arr[i].box[0]);
  1614. y1 = getCanvasLocationY(label_arr[i].box[1]);
  1615. x2 = getCanvasLocationX(label_arr[i].box[2]);
  1616. y2 = getCanvasLocationY(label_arr[i].box[3]);
  1617. cls=label_arr[i].class_name;
  1618. score = label_arr[i].score;
  1619. var rect = new rectar(x1,y1,x2,y2,cls,score);
  1620. if(!isEmpty(label_arr[i].id)){
  1621. rect.id= label_arr[i].id;
  1622. }
  1623. if(!isEmpty(label_arr[i].blurred)){
  1624. rect.blurred = label_arr[i].blurred;
  1625. }
  1626. if(!isEmpty(label_arr[i].goodIllumination)){
  1627. rect.goodIllumination = label_arr[i].goodIllumination;
  1628. }
  1629. if(!isEmpty(label_arr[i].frontview)){
  1630. rect.frontview = label_arr[i].frontview;
  1631. }
  1632. if(!isEmpty(label_arr[i].other)){
  1633. rect.other = label_arr[i].other;
  1634. }
  1635. // else if (isEmpty(label_arr[i].other) && (isEmpty(label_attributes) || Object.keys(label_attributes).length == 0)){
  1636. else if (isEmpty(label_arr[i].other)){
  1637. rect.other["region_attributes"]["type"] = rect.type;
  1638. rect.other["region_attributes"]["id"] = rect.id;
  1639. }
  1640. if (maxIdNum< parseInt(rect.other["region_attributes"]["id"])){
  1641. maxIdNum = parseInt(rect.other["region_attributes"]["id"]);
  1642. }
  1643. rects.push(rect);
  1644. }
  1645. else if(!isEmpty(label_arr[i].keypoints)){
  1646. cls=label_arr[i].class_name;
  1647. score = label_arr[i].score;
  1648. var pointShapeObj = new pointShape(getCanvasLocationX(label_arr[i].keypoints[0]),getCanvasLocationY(label_arr[i].keypoints[1]),cls,score);
  1649. if(!isEmpty(label_arr[i].other)){
  1650. pointShapeObj.other = label_arr[i].other;
  1651. }
  1652. else if (isEmpty(label_arr[i].other)){
  1653. pointShapeObj.other["region_attributes"]["type"] = pointShapeObj.type;
  1654. pointShapeObj.other["region_attributes"]["id"] = pointShapeObj.id;
  1655. }
  1656. if (maxIdNum< parseInt(pointShapeObj.other["region_attributes"]["id"])){
  1657. maxIdNum = parseInt(pointShapeObj.other["region_attributes"]["id"]);
  1658. }
  1659. pointShapes.push(pointShapeObj);
  1660. }
  1661. }
  1662. //console.log(rects);
  1663. //console.log(masks);
  1664. }
  1665. document.getElementById("boxlabels").innerHTML=boxlabelshtml();
  1666. document.getElementById("labelcounttable").innerHTML=boxlabelcounthtml();
  1667. // 加载值:需要打开已有属性和属性值,需要回传_via_attributes, _via_img_metadata两个值的获取
  1668. //暂时默认设置只有类别属性
  1669. set_display_area_content( VIA_DISPLAY_AREA_CONTENT_NAME.IMAGE );
  1670. }
  1671. function getHtmlStr(shape,shapetype,rectIndex){
  1672. var lablebg="";
  1673. if (shape.isSelected){
  1674. lablebg=" style=\"background:#eee;color:#5a5a5a;\"";
  1675. var tmp = "tr_" + shapetype + "_" + Math.max(rectIndex-1,0);
  1676. var $objTr = $("#"+tmp) ; //找到要定位的地方 tr
  1677. var objTr = $objTr[0]; //转化为dom对象
  1678. if (!isEmpty(objTr)){
  1679. $("#labelpanel").animate({scrollTop:objTr.offsetTop},0); //滚动条滚动
  1680. }
  1681. }
  1682. var tmpType = shape.type;
  1683. //console.log("tmpType =" + tmpType);
  1684. if(!isEmpty(shape.other["region_attributes"]["type"])){
  1685. tmpType = shape.other["region_attributes"]["type"];
  1686. }
  1687. var shapeswidthHeigth = "";
  1688. if (shapetype == "bbox"){
  1689. xywh = shape.getXYWH();
  1690. shapeswidthHeigth = getRealLocationX(xywh[2]) + "," + getRealLocationY(xywh[3]);
  1691. }
  1692. var xy=shape.points;
  1693. var x ;
  1694. var y ;
  1695. if (shapetype == "point"){
  1696. x = shape.x;
  1697. y = shape.y;
  1698. }
  1699. else{
  1700. x = xy[0].x;
  1701. y = xy[0].y;
  1702. }
  1703. return "<tr id=\"tr_" + shapetype + "_" + rectIndex + "\" onclick=\"highlight("+x+","+y+", "+rectIndex+", '"+shapetype+"');\"" +lablebg + "><td style=\"width:10px\"></td> <td>"+ tmpType + "</td><td>" + shapetype + "</td><td>" + shapeswidthHeigth + "</td></tr>";
  1704. }
  1705. function setStyle(rectIndex,shapetype){
  1706. for (var i=0;i<rects.length;i++){
  1707. document.getElementById("tr_bbox_" + i).style = "";
  1708. }
  1709. for (var i=0;i<pointShapes.length;i++){
  1710. document.getElementById("tr_point_" + i).style = "";
  1711. }
  1712. for (var i=0;i<masks.length;i++){
  1713. document.getElementById("tr_mask_" + i).style = "";
  1714. }
  1715. document.getElementById("tr_" + shapetype + "_" + rectIndex).style = "background:#eee;color:#5a5a5a;";
  1716. }
  1717. function highlight(x,y,rectIndex,shapetype){
  1718. setStyle(rectIndex,shapetype);
  1719. Selectedmask = null;
  1720. SelectedRect = null;
  1721. SelectedPointShape = null;
  1722. if (shapetype=="bbox"){
  1723. for (var i=0;i<rects.length;i++){
  1724. rects[i].isSelected = false;
  1725. if (i==rectIndex){
  1726. rects[i].isSelected = true;
  1727. SelectedRect = rects[i];
  1728. }
  1729. }
  1730. for (var i=0;i<pointShapes.length;i++){
  1731. pointShapes[i].isSelected = false;
  1732. }
  1733. for (var i=0;i<masks.length;i++){
  1734. masks[i].isSelected = false;
  1735. }
  1736. }
  1737. else if (shapetype=="point"){
  1738. for (var i=0;i<rects.length;i++){
  1739. rects[i].isSelected = false;
  1740. }
  1741. for (var i=0;i<pointShapes.length;i++){
  1742. pointShapes[i].isSelected = false;
  1743. if (i==rectIndex){
  1744. pointShapes[i].isSelected = true;
  1745. SelectedPointShape = pointShapes[i];
  1746. }
  1747. }
  1748. for (var i=0;i<masks.length;i++){
  1749. masks[i].isSelected = false;
  1750. }
  1751. }
  1752. else{
  1753. SelectedRect = null;
  1754. for (var i=0;i<rects.length;i++){
  1755. rects[i].isSelected = false;
  1756. }
  1757. for (var i=0;i<pointShapes.length;i++){
  1758. pointShapes[i].isSelected = false;
  1759. }
  1760. for (var i=0;i<masks.length;i++){
  1761. masks[i].isSelected = false;
  1762. if (i==rectIndex){
  1763. masks[i].isSelected = true;
  1764. Selectedmask = masks[i];
  1765. }
  1766. }
  1767. }
  1768. drawRect();
  1769. }
  1770. function boxlabelshtml(){
  1771. var htmlstr="";
  1772. for (var i=0;i<rects.length;i++){
  1773. htmlstr = htmlstr + getHtmlStr(rects[i],'bbox',i);
  1774. }
  1775. for (var i=0;i<masks.length;i++){
  1776. htmlstr = htmlstr + getHtmlStr(masks[i],'mask',i);
  1777. }
  1778. for(var i = 0; i < pointShapes.length; i++){
  1779. htmlstr = htmlstr + getHtmlStr(pointShapes[i],'point',i);
  1780. }
  1781. return htmlstr;
  1782. }
  1783. function boxlabelCount(labelMap,shape){
  1784. var tmpType = shape.type;
  1785. if(!isEmpty(shape.other["region_attributes"]["type"])){
  1786. tmpType = shape.other["region_attributes"]["type"];
  1787. }
  1788. if(labelMap[tmpType] == null){
  1789. labelMap[tmpType] = 1;
  1790. }else{
  1791. labelMap[tmpType] = labelMap[tmpType] + 1;
  1792. }
  1793. }
  1794. function boxlabelcounthtml(){
  1795. var htmlstr="";
  1796. var labelMap = {};
  1797. for (var i=0;i<rects.length;i++){
  1798. boxlabelCount(labelMap,rects[i]);
  1799. }
  1800. for (var i=0;i<masks.length;i++){
  1801. boxlabelCount(labelMap,masks[i]);
  1802. }
  1803. for (var i=0;i<pointShapes.length;i++){
  1804. boxlabelCount(labelMap,pointShapes[i]);
  1805. }
  1806. for (item in labelMap){
  1807. htmlstr = htmlstr + "<tr><td style=\"width:10px\"></td> <td>"+ item + "</td><td>" + labelMap[item] +"</td></tr>";
  1808. }
  1809. return htmlstr;
  1810. }
  1811. function getRealLocationX(num){
  1812. var loc = Math.round(num*img.width/canvas.width);
  1813. // if (img.width<600){
  1814. // loc = Math.round(num);
  1815. // }
  1816. if(loc <= 0){
  1817. loc = 1;
  1818. }
  1819. if(loc > img.width){
  1820. loc = img.width -1;
  1821. }
  1822. return loc;
  1823. }
  1824. function getRealLocationY(num){
  1825. var loc = Math.round(num*img.height/canvas.height);
  1826. // if (img.width<600){
  1827. // loc = Math.round(num);
  1828. // }
  1829. if(loc <= 0){
  1830. loc = 1;
  1831. }
  1832. if( loc > img.height){
  1833. loc = img.height -1;
  1834. }
  1835. return loc;
  1836. }
  1837. function getCanvasLocationX(num){
  1838. return Math.round(num*canvas.width/parseInt(img.width));
  1839. }
  1840. function getCanvasLocationY(num){
  1841. return Math.round(num*canvas.height/parseInt(img.height));
  1842. }
  1843. function setAutoModel(){
  1844. hidePopup();
  1845. loadModel();
  1846. display_createlabel();
  1847. }
  1848. var algModelList;
  1849. function loadModel(){
  1850. $.ajax({
  1851. type:"GET",
  1852. contentType:'application/json',
  1853. url: ip + "/api/queryAlgModelForHandLabel/",
  1854. dataType:"json",
  1855. async:false,
  1856. headers: {
  1857. // Accept: "text/html; q=1.0",
  1858. authorization:token,
  1859. },
  1860. // enctype:"multipart/form-data",
  1861. success:function(jsonList){
  1862. console.log(jsonList);
  1863. algModelList = jsonList;
  1864. // return json.token;
  1865. },
  1866. error:function(response) {
  1867. redirect(response);
  1868. }
  1869. });
  1870. }
  1871. function display_createlabel(){
  1872. var html="<option value=\"\" selected=\"\">请选择</option>";
  1873. for (var i=0;i<algModelList.length;i++){
  1874. if (i==2){
  1875. var row = "<option selected value=\""+algModelList[i].id+
  1876. "\">"+algModelList[i].model_name+
  1877. "</option>";
  1878. }
  1879. else{
  1880. var row = "<option value=\""+algModelList[i].id+
  1881. "\">"+algModelList[i].model_name+
  1882. "</option>";
  1883. }
  1884. html=html+row;
  1885. }
  1886. console.log(html);
  1887. $('#tracking_startid').val('1');
  1888. $('#tracking_endid').val(tablePageData.total);
  1889. document.getElementById('predict_model').innerHTML=html;
  1890. document.getElementById("tracking_startid_div").style.display="none";
  1891. document.getElementById("tracking_endid_div").style.display="none";
  1892. document.getElementById("label_id_div").style.display="none";
  1893. document.getElementById("labelOption_div").style.display="none";
  1894. //document.getElementById("labelOption").innerHTML="<option value=\"2\" selected=\"\">请选择</option> <option value=\"3\">识别车的类型与颜色</option>";
  1895. document.getElementById('predtask_id').disabled=false;
  1896. $('#label_id').val('1');
  1897. bar.style.width='1%';
  1898. document.getElementById('text-progress').innerHTML='0%';
  1899. }
  1900. function submit_predtask(){
  1901. var item_id = labeltastresult[fileindex].id;
  1902. var predict_model_val = $('#predict_model').val();
  1903. if(isEmpty(predict_model_val)){
  1904. alert("请选择标注任务使用的模型。");
  1905. return;
  1906. }
  1907. if(labeltastresult[fileindex].label_status == 0 && !(predict_model_val == 12 || predict_model_val == 16 || predict_model_val == 20 || predict_model_val == 21)){
  1908. alert("标注状态已经完成,不能进行自动检测。");
  1909. return;
  1910. }
  1911. var task_type = "1";
  1912. var start_id = 0;
  1913. var end_id = 0;
  1914. var label_id = 1;
  1915. var label_option = null;
  1916. if(predict_model_val == 12 || predict_model_val == 16 || predict_model_val == 20 || predict_model_val == 21){
  1917. task_type = "2";
  1918. start_id = $('#tracking_startid').val();
  1919. end_id = $('#tracking_endid').val();
  1920. label_id = $('#label_id').val();
  1921. if(start_id < 1 || start_id > tablePageData.total){
  1922. alert("请输入正确的追踪起始图片ID,范围为1到" + tablePageData.total);
  1923. return;
  1924. }
  1925. if(end_id < 1 || end_id > tablePageData.total){
  1926. alert("请输入正确的追踪结束图片ID,范围为1到" + tablePageData.total);
  1927. return;
  1928. }
  1929. if(label_id < 1){
  1930. alert("标注框ID为大于等于1的整数。");
  1931. return;
  1932. }
  1933. }
  1934. document.getElementById('predtask_id').disabled=true;
  1935. $.ajax({
  1936. type:"POST",
  1937. url:ip + "/gitea/auto-label-task",
  1938. contentType:'application/json',
  1939. headers: {
  1940. authorization:token,
  1941. },
  1942. dataType:"json",
  1943. async:false,
  1944. data:JSON.stringify({'label_task_id':item_id,
  1945. 'model':predict_model_val,
  1946. 'pic_object_name' : img.width + "," + img.height,
  1947. 'task_type':task_type,
  1948. 'startIndex':start_id,
  1949. 'endIndex':end_id,
  1950. 'taskId':label_task,
  1951. 'label_id':label_id,
  1952. 'label_option':label_option
  1953. }),
  1954. success:function(res){
  1955. console.log('创建数据信息');
  1956. },
  1957. error:function(response) {
  1958. redirect(response);
  1959. }
  1960. });
  1961. setIntervalToDo();
  1962. }
  1963. var timeId;
  1964. var count;
  1965. var progress;
  1966. function setIntervalToDo(){
  1967. count=0;
  1968. timeId = self.setInterval("clock()",1000);//5秒刷新
  1969. console.log("开始刷新。timeId=" + timeId);
  1970. }
  1971. function clock(){
  1972. count++;
  1973. if(count > 600 ){
  1974. console.log("清除定时器。timeId=" + timeId);
  1975. window.clearInterval(timeId);
  1976. timeId = null;
  1977. $("#autoLabel").modal('hide');
  1978. return;
  1979. }
  1980. $.ajax({
  1981. type:"GET",
  1982. url:ip + "/api/query-auto-label-task-progress/",
  1983. headers: {
  1984. authorization:token,
  1985. },
  1986. dataType:"json",
  1987. data:{'taskId': label_task},
  1988. async:false,
  1989. success:function(json){
  1990. progress = json;
  1991. console.log(json);
  1992. },
  1993. error:function(response) {
  1994. progress = null;
  1995. console.log("query progress error");
  1996. redirect(response);
  1997. }
  1998. });
  1999. if(isEmpty(progress)){
  2000. console.log("清除定时器。timeId=" + timeId);
  2001. bar.style.width='100%';
  2002. document.getElementById('text-progress').innerHTML='100%';
  2003. window.clearInterval(timeId);
  2004. timeId = null;
  2005. var current = $('#displayPage1').text();
  2006. $("#autoLabel").modal('hide');
  2007. console.log("开始获取结果。current=" + current);
  2008. if(current >= 1){
  2009. pageReload(current - 1,pageSize,fileindex);
  2010. }
  2011. }else{
  2012. //更新进度
  2013. var iSpeed = progress.progress;
  2014. bar.style.width=iSpeed+'%';
  2015. document.getElementById('text-progress').innerHTML=iSpeed+'%'
  2016. }
  2017. /*
  2018. var current = $('#displayPage1').text();
  2019. console.log("开始刷新。current=" + current);
  2020. if(current >= 1){
  2021. pageReload(current - 1,pageSize,fileindex);
  2022. if(!isEmpty(labeltastresult[fileindex].label_info)){
  2023. window.clearInterval(timeId);
  2024. timeId = null;
  2025. }
  2026. }
  2027. */
  2028. }
  2029. function submit_deletelabel(){
  2030. var start_id = $('#delete_startid').val();
  2031. var end_id = $('#delete_endid').val();
  2032. if(start_id < 1 || start_id > tablePageData.total){
  2033. alert("请输入正确的起始图片ID,范围为1到" + tablePageData.total);
  2034. return;
  2035. }
  2036. if(end_id < 1 || end_id > tablePageData.total){
  2037. alert("请输入正确的结束图片ID,范围为1到" + tablePageData.total);
  2038. return;
  2039. }
  2040. //var one_reid_name = $('#one_reid_name').val();
  2041. $.ajax({
  2042. type:"POST",
  2043. url:ip + "/gitea/label-task-delete-label",
  2044. headers: {
  2045. authorization:token,
  2046. },
  2047. dataType:"json",
  2048. async:false,
  2049. data:{'label_task_id':label_task_info.id,
  2050. 'start_id':start_id,
  2051. 'end_id' : end_id
  2052. //'one_reid_name':one_reid_name
  2053. },
  2054. success:function(res){
  2055. console.log('创建数据信息');
  2056. },
  2057. error:function(response) {
  2058. redirect(response);
  2059. }
  2060. });
  2061. $("#deleteLabel").modal('hide');
  2062. var current = $('#displayPage1').text();
  2063. if(current >= 1){
  2064. pageReload(current - 1,pageSize,fileindex);
  2065. }
  2066. }
  2067. function updatelabel(fileindex){
  2068. var label_list=[]
  2069. for (var i=0;i<rects.length;i++){
  2070. x1y1x2y2=rects[i].getX1Y1X2Y2();
  2071. rects[i].type = '';//regions[i].other.["region_attributes"]["type"];
  2072. var label= {'class_name':rects[i].type, "score":1.0};
  2073. if(!isEmpty(rects[i].other.region_attributes.type)){
  2074. label['class_name'] = rects[i].other.region_attributes.type;
  2075. }
  2076. if(!isEmpty(rects[i].other.region_attributes.id)){
  2077. rects[i].id = rects[i].other.region_attributes.id;
  2078. }
  2079. var xmin = getRealLocationX(x1y1x2y2[0]);
  2080. var ymin = getRealLocationY(x1y1x2y2[1]);
  2081. var xmax = getRealLocationX(x1y1x2y2[2]);
  2082. var ymax = getRealLocationY(x1y1x2y2[3]);
  2083. label['box']=[xmin,ymin, xmax,ymax];
  2084. if(isEmpty(rects[i].id)){
  2085. label['id'] = i+'';
  2086. }else{
  2087. label['id'] = rects[i].id+'';
  2088. }
  2089. label['blurred']=rects[i].blurred;
  2090. label['goodIllumination']=rects[i].goodIllumination;
  2091. label['frontview']=rects[i].frontview;
  2092. label['other']=rects[i].other;
  2093. //console.log(label);
  2094. label_list.push(label);
  2095. }
  2096. for (var i=0;i<masks.length;i++){
  2097. masks[i].type = '';//regions[i].other.["region_attributes"]["type"];
  2098. var label = {'class_name':masks[i].type, "score":1.0};
  2099. if(!isEmpty(masks[i].other.region_attributes.type)){
  2100. label['class_name'] = masks[i].other.region_attributes.type;
  2101. }
  2102. if(!isEmpty(masks[i].other.region_attributes.id)){
  2103. masks[i].id = masks[i].other.region_attributes.id;
  2104. }
  2105. var labelMaskList = [];
  2106. for(var j = 0; j < masks[i].points.length; j++){
  2107. labelMaskList.push(getRealLocationX(masks[i].points[j].x));
  2108. labelMaskList.push(getRealLocationY(masks[i].points[j].y));
  2109. }
  2110. label['mask'] = labelMaskList;
  2111. label['id'] = masks[i].id+'';
  2112. label['blurred']=masks[i].blurred;
  2113. label['goodIllumination']=masks[i].goodIllumination;
  2114. label['frontview']=masks[i].frontview;
  2115. label['other']=masks[i].other;
  2116. //console.log(label);
  2117. label_list.push(label);
  2118. }
  2119. for (var i=0;i<pointShapes.length;i++){
  2120. pointShapes[i].type = '';//regions[i].other.["region_attributes"]["type"];
  2121. var label = {'class_name':pointShapes[i].type, "score":1.0};
  2122. if(!isEmpty(pointShapes[i].other.region_attributes.type)){
  2123. label['class_name'] = pointShapes[i].other.region_attributes.type;
  2124. }
  2125. if(!isEmpty(pointShapes[i].other.region_attributes.id)){
  2126. pointShapes[i].id = pointShapes[i].other.region_attributes.id;
  2127. }
  2128. var pointList = [];
  2129. pointList.push(getRealLocationX(pointShapes[i].x));
  2130. pointList.push(getRealLocationY(pointShapes[i].y));
  2131. pointList.push(2);//0表示这个关键点没有标注(这种情况下x=y=v=0),1表示这个关键点标注了但是不可见(被遮挡了),2 表示这个关键点标注了同时也可见
  2132. label['keypoints'] = pointList;
  2133. label['id'] = pointShapes[i].id+'';
  2134. label['blurred']=pointShapes[i].blurred;
  2135. label['goodIllumination']=pointShapes[i].goodIllumination;
  2136. label['frontview']=pointShapes[i].frontview;
  2137. label['other']=pointShapes[i].other;
  2138. //console.log(label);
  2139. label_list.push(label);
  2140. }
  2141. labelinfo_jsonstr = JSON.stringify(label_list);
  2142. labeltastresult[fileindex].label_info=labelinfo_jsonstr;
  2143. var flag = 0;
  2144. if(isVerified()){
  2145. labeltastresult[fileindex].verify_status=1;
  2146. flag = 100;
  2147. }else{
  2148. if(label_list.length > 0){
  2149. labeltastresult[fileindex].label_status=0;
  2150. }
  2151. else{
  2152. labeltastresult[fileindex].label_status=1;
  2153. }
  2154. }
  2155. $.ajax({
  2156. type:"PATCH",
  2157. url:ip + "/gitea/label-task-item/",
  2158. contentType:'application/json',
  2159. headers: {
  2160. authorization:token,
  2161. },
  2162. dataType:"json",
  2163. async:false,
  2164. data:JSON.stringify({'id':labeltastresult[fileindex].id,
  2165. 'label_task_id':label_task_info.id,
  2166. 'label_info':labelinfo_jsonstr,
  2167. 'label_status': labeltastresult[fileindex].label_status,
  2168. 'verify_status': labeltastresult[fileindex].verify_status,
  2169. 'pic_object_name' : img.width + "," + img.height,
  2170. 'display_order2':flag
  2171. }),
  2172. success:function(json){
  2173. return true;
  2174. },
  2175. error:function(response) {
  2176. redirect(response);
  2177. }
  2178. });
  2179. return false;
  2180. }
  2181. function get_labeltask(){
  2182. console.log('query labeltask info.');
  2183. $.ajax({
  2184. type:"GET",
  2185. url:ip + "/gitea/label-task/"+label_task+"/",
  2186. headers: {
  2187. authorization:token,
  2188. },
  2189. dataType:"json",
  2190. async:false,
  2191. success:function(json){
  2192. label_task_info = json;
  2193. console.log('return labeltask info.' + label_task_info);
  2194. page(0,pageSize);
  2195. },
  2196. error:function(response) {
  2197. redirect(response);
  2198. }
  2199. });
  2200. }
  2201. function update_labeltask(task_label_type_info){
  2202. console.log("label_task_id=" + label_task_info.id);
  2203. console.log("task_label_type_info=" + task_label_type_info);
  2204. $.ajax({
  2205. type:"PATCH",
  2206. url:ip + "/gitea/label-task/",
  2207. headers: {
  2208. authorization:token,
  2209. },
  2210. dataType:"json",
  2211. data:{
  2212. 'label_task_id':label_task_info.id,
  2213. 'task_label_type_info':task_label_type_info,
  2214. },
  2215. async:false,
  2216. success:function(json){
  2217. console.log(json);
  2218. },
  2219. error:function(response) {
  2220. redirect(response);
  2221. }
  2222. });
  2223. }
  2224. function list(current,pageSize,index=0){
  2225. $.ajax({
  2226. type:"GET",
  2227. url:ip + "/gitea/label-task-item-page/",
  2228. headers: {
  2229. authorization:token,
  2230. },
  2231. dataType:"json",
  2232. data:{
  2233. 'label_task':label_task_info.id,
  2234. 'startPage':current,
  2235. 'pageSize':pageSize,
  2236. 'orderType': orderType,
  2237. 'findLast':findLast,
  2238. },
  2239. async:false,
  2240. success:function(json){
  2241. tablePageData = json;
  2242. tableData = json.data;
  2243. labeltastresult = tableData;
  2244. fileindex=index;
  2245. if(lastindex){
  2246. fileindex = pageSize - 1;
  2247. }
  2248. //console.log(json);
  2249. // return json.token;
  2250. },
  2251. error:function(response) {
  2252. redirect(response);
  2253. }
  2254. });
  2255. }
  2256. var pageSize = 20;
  2257. var tableData;
  2258. var tablePageData;
  2259. function pageReload(current,pageSize,fileindex){
  2260. list(current,pageSize,fileindex);
  2261. loadimg();
  2262. showtaskinfo();
  2263. showfilelist();
  2264. //display_list();
  2265. setPage(tablePageData,pageSize);
  2266. }
  2267. function page(current,pageSize){
  2268. list(current,pageSize);
  2269. loadimg();
  2270. showtaskinfo();
  2271. showfilelist();
  2272. //display_list();
  2273. setPage(tablePageData,pageSize);
  2274. }
  2275. function nextPage(){
  2276. hidePopup();
  2277. var current = $('#displayPage1').text();
  2278. console.log("current=" + current);
  2279. findLast = 0;
  2280. page(current,pageSize);
  2281. }
  2282. function prePage(){
  2283. hidePopup();
  2284. var current =$('#displayPage1').text();
  2285. console.log("current=" + current);
  2286. if(current > 1){
  2287. console.log("current=" + (current - 2));
  2288. findLast = 0;
  2289. page(current - 2,pageSize);
  2290. }
  2291. }
  2292. function goPage(){
  2293. hidePopup();
  2294. var goNum = $('#goNum').val();
  2295. findLast = 0;
  2296. var pageTotal = $("#totalNum").text();
  2297. var pageNum = parseInt(pageTotal/pageSize);
  2298. if(pageTotal%pageSize!=0){
  2299. pageNum += 1;
  2300. }else {
  2301. pageNum = pageNum;
  2302. }
  2303. if (goNum<=0){
  2304. alert("请输入大于0的数值");
  2305. }
  2306. else if(goNum<=pageNum){
  2307. page(goNum - 1,pageSize);
  2308. }
  2309. else{
  2310. alert("不能超出总页码!");
  2311. }
  2312. }
  2313. $("#goNum").keydown(function (e) {
  2314. if (e.keyCode == 13) {
  2315. goPage();
  2316. }
  2317. });
  2318. function setPage(pageData,pageSize){
  2319. var startIndex = pageData.current * pageSize;
  2320. if(startIndex < 10){
  2321. $('#startIndex').text(" " + (pageData.current * pageSize + 1));
  2322. }else{
  2323. $('#startIndex').text(pageData.current * pageSize + 1);
  2324. }
  2325. var endIndex = pageData.current * pageSize + pageData.data.length;
  2326. if(endIndex < 10){
  2327. $('#endIndex').text(" " + (pageData.current * pageSize + pageData.data.length));
  2328. }else{
  2329. $('#endIndex').text(pageData.current * pageSize + pageData.data.length);
  2330. }
  2331. $('#totalNum').text(pageData.total);
  2332. $('#displayPage1').text(pageData.current + 1);
  2333. console.log("set prePage status, pageData.current=" + pageData.current);
  2334. if(pageData.current == 0){
  2335. console.log("set prePage disabled.");
  2336. $('#prePage').removeAttr("href");
  2337. $('#prePage').attr('style','color:#000;margin-right:1em;');
  2338. }
  2339. else{
  2340. $('#prePage').attr("href","javascript:prePage()");
  2341. $('#prePage').attr('style','color:#f5f5f6;margin-right:1em;');
  2342. }
  2343. if((pageData.current + 1) * pageSize >= pageData.total){
  2344. console.log("set nextPage disabled.");
  2345. $('#nextPage').removeAttr("href");
  2346. $('#nextPage').attr('style','color:#000;margin-left:1em;')
  2347. }
  2348. else{
  2349. $('#nextPage').attr("href","javascript:nextPage()");
  2350. $('#nextPage').attr('style','color:#f5f5f6;margin-left:1em;');
  2351. }
  2352. var pageTotal = pageData.total;
  2353. var pageNum = parseInt(pageTotal/pageSize);
  2354. if(pageTotal%pageSize!=0){
  2355. pageNum += 1;
  2356. }else {
  2357. pageNum = pageNum;
  2358. }
  2359. $("#totalPageNum").text(pageNum);
  2360. }
  2361. init_index();
  2362. // canvas = document.getElementById("myCanvas");
  2363. // context = canvas.getContext("2d");
  2364. // var maxWidth = document.getElementById("showPic").offsetWidth;
  2365. // var maxHeight = document.getElementById("showPic").offsetHeight-100;
  2366. // canvas.width = maxWidth;//document.getElementById("tool0").offsetWidth;
  2367. // canvas.height = maxHeight;//document.getElementById("tool0").offsetWidth/1280*720;
  2368. // show_region = document.getElementById("show_region");
  2369. // show_region.width =document.getElementById("tool0").offsetWidth;
  2370. // show_region.height = document.getElementById("tool0").offsetWidth/1280*720;
  2371. function init_index() {
  2372. canvas = document.getElementById("myCanvas");
  2373. context = canvas.getContext("2d");
  2374. maxWidth = document.getElementById("showPic").offsetWidth;
  2375. maxHeight = document.getElementById("showPic").offsetHeight-100;
  2376. canvas.width = maxWidth;
  2377. canvas.height = maxHeight;
  2378. canvas.onmousedown = canvasClick;
  2379. canvas.onmouseup = stopDragging;
  2380. canvas.onmouseout = stopDragging;
  2381. canvas.onmousemove =dragRect;
  2382. var token = getSessionStorageMessage("token");
  2383. console.log("page load token=" + token);
  2384. if(!isEmpty(token)){
  2385. console.log("this is not null.token =" + token);
  2386. doLoad();
  2387. }
  2388. };
  2389. function doLoad(){
  2390. token = getSessionStorageMessage("token");
  2391. userType = getSessionStorageMessage("userType");
  2392. if(typeof token == "undefined" || token == null || token == ""){
  2393. console.log("token=" + token);
  2394. console.log("onload tasks/detect/index.html");
  2395. window.location.href = "../../login.html";
  2396. }
  2397. label_task = getSessionStorageMessage("label_task");
  2398. label_task_status = getSessionStorageMessage("label_task_status"); //1表示审核
  2399. get_labeltask();
  2400. drawRect();
  2401. _via_init();
  2402. //加载保存好的属性结构,如果不存在,加载默认的类别信息
  2403. if(!isEmpty(label_task_info.task_label_type_info)){
  2404. label_attributes = JSON.parse(label_task_info.task_label_type_info);
  2405. }
  2406. if (isEmpty(label_attributes)){
  2407. get_init_atrribute();
  2408. }
  2409. else{
  2410. if (Object.keys(label_attributes).length == 0){
  2411. get_init_atrribute();
  2412. }
  2413. else{
  2414. _via_attributes["region"] = label_attributes;
  2415. }
  2416. }
  2417. }
  2418. function get_init_atrribute(){
  2419. _via_attributes = {'region':{}};
  2420. var atti = "id"; // 属性名
  2421. _via_attributes['region'][atti] = {};
  2422. _via_attributes['region'][atti]["type"] = "text";
  2423. _via_attributes['region'][atti]["description"] = "";
  2424. _via_attributes['region'][atti]["default_value"] = "";
  2425. atti = "type"; // 属性名
  2426. _via_attributes['region'][atti] = {};
  2427. _via_attributes['region'][atti]["type"] = "dropdown";
  2428. _via_attributes['region'][atti]["description"] = "";
  2429. _via_attributes['region'][atti]["options"] = {};
  2430. _via_attributes['region'][atti]["options"]["car"] = "car";
  2431. _via_attributes['region'][atti]["options"]["person"] = "person";
  2432. _via_attributes['region'][atti]["options"]["non-motor"] = "non-motor";
  2433. _via_attributes['region'][atti]["default_options"] = {};
  2434. }
  2435. function model_sele_Change(event){
  2436. var modelid = $('#predict_model option:selected').val();
  2437. console.log("predict_model=" + modelid);
  2438. if(modelid == 12 || modelid == 16 || modelid == 20 || modelid == 21){
  2439. document.getElementById("tracking_startid_div").style.display="block";
  2440. document.getElementById("tracking_endid_div").style.display="block";
  2441. document.getElementById("labelOption_div").style.display="block";
  2442. if(modelid == 12 || modelid == 16){
  2443. document.getElementById("label_id_div").style.display="block";
  2444. }else{
  2445. document.getElementById("label_id_div").style.display="none";
  2446. }
  2447. if(modelid == 21){
  2448. document.getElementById("labelOption").innerHTML="<option value=\"10\" selected=\"\">person</option> <option value=\"11\">car</option>";
  2449. }else if(modelid == 20){
  2450. document.getElementById("labelOption").innerHTML="<option value=\"10\" selected=\"\">person</option>";
  2451. }else{
  2452. document.getElementById("labelOption").innerHTML="<option value=\"0\" selected=\"\">合并已有的标注信息</option> <option value=\"1\">删除已有的标注信息</option>";
  2453. }
  2454. }else{
  2455. document.getElementById("tracking_startid_div").style.display="none";
  2456. document.getElementById("tracking_endid_div").style.display="none";
  2457. document.getElementById("label_id_div").style.display="none";
  2458. document.getElementById("labelOption_div").style.display="none";
  2459. if(modelid == 5 || modelid == 6 || modelid == 7 ){
  2460. //document.getElementById("labelOption").innerHTML="<option value=\"2\" selected=\"\">请选择</option> <option value=\"3\">识别车的类型与颜色</option>";
  2461. }
  2462. }
  2463. }
  2464. function export_attribute(){
  2465. var url = ip + "/api/task-export-label-property/";
  2466. var $iframe = $('<iframe />');
  2467. var $form = $('<form method="get" target="_self"/>');
  2468. $form.attr('action', url); //设置get的url地址
  2469. $form.append('<input type="hidden" name="task_id" value="' + label_task + '" />');
  2470. $form.append('<input type="hidden" name="type" value="labeltask" />');
  2471. $iframe.append($form);
  2472. $(document.body).append($iframe);
  2473. $form[0].submit();//提交表单
  2474. $iframe.remove();//移除框架
  2475. }
  2476. function import_attribute(){
  2477. $('#datasetModal').modal('show');
  2478. }
  2479. function submit_import_property(){
  2480. var jsonContent = $("#jsoninput").val();
  2481. if(!isJSON(jsonContent)){
  2482. alert("输入格式非法。");
  2483. return;
  2484. }
  2485. $.ajax({
  2486. type:"POST",
  2487. url:ip + "/api/task-import-label-property/",
  2488. headers: {
  2489. authorization:token,
  2490. },
  2491. dataType:"json",
  2492. data:{
  2493. 'jsonContent':jsonContent,
  2494. 'taskType':"labeltask",
  2495. 'taskId':label_task
  2496. },
  2497. async:false,
  2498. success:function(json){
  2499. console.log(json);
  2500. },
  2501. error:function(response) {
  2502. redirect(response);
  2503. }
  2504. });
  2505. $('#datasetModal').modal('hide');
  2506. close_attribute();
  2507. }
  2508. function isJSON(str) {
  2509. if (typeof str == 'string') {
  2510. try {
  2511. var obj=JSON.parse(str);
  2512. if(typeof obj == 'object' && obj ){
  2513. return true;
  2514. }else{
  2515. return false;
  2516. }
  2517. } catch(e) {
  2518. console.log('error:'+str+'!!!'+e);
  2519. return false;
  2520. }
  2521. }
  2522. console.log('It is not a string!');
  2523. return false;
  2524. }
  2525. img.onload = function(){
  2526. loadFinished = false;
  2527. // 初始设置画布大小,最大值宽和高
  2528. canvas.width = maxWidth;//document.getElementById("tool0").offsetWidth;
  2529. canvas.height = maxHeight;//document.getElementById("tool0").offsetWidth/1280*720;
  2530. //调整画布大小
  2531. if ((img.width/img.height)<(canvas.width/canvas.height)){
  2532. canvas.width=canvas.height * img.width / img.height;
  2533. }
  2534. else{
  2535. canvas.height=canvas.width * img.height / img.width;
  2536. }
  2537. maxIdNum=0;
  2538. parse_labelinfo(labeltastresult[fileindex].label_info);
  2539. drawRect();
  2540. $('#filepanel').slimScroll({
  2541. alwaysVisible: true, //是否 始终显示组件(未更改库文件时,鼠标移开滚动条消失)
  2542. });
  2543. canvas.onmousewheel = canvas.onwheel = function (event) { //滚轮放大缩小
  2544. console.log("primivate x,y=" + event.clientX + "," + event.clientY);//鼠标在屏幕上的位置
  2545. event.wheelDelta = event.wheelDelta ? event.wheelDelta : (event.deltalY * (-40)); //获取当前鼠标的滚动情况
  2546. if (event.wheelDelta > 0) {// 放大
  2547. imgScale +=0.1;
  2548. console.log("imgScale=" + imgScale);
  2549. } else {// 缩小
  2550. imgScale -=0.1;
  2551. if(imgScale< 1) {//最小缩放1
  2552. imgScale = 1;
  2553. }
  2554. console.log("imgScale=" + imgScale);
  2555. }
  2556. drawRect(); //重新绘制图片
  2557. };
  2558. loadFinished=true;
  2559. };
  2560. document.onkeydown = function(e){
  2561. switch(e.keyCode){
  2562. case 37:
  2563. case 38:
  2564. case 39:
  2565. case 40:
  2566. e.preventDefault();
  2567. }
  2568. }
  2569. document.onkeyup=function(e){
  2570. console.log(e.keyCode)
  2571. console.log(window.event);
  2572. e=e||window.event;
  2573. e.preventDefault();
  2574. obj = e.srcElement||e.target;
  2575. if( obj != null && obj !=undefined ){
  2576. if(obj.type == "textarea" || obj.type=='text'){
  2577. //console.log("obj.type:"+obj.type);
  2578. return ;
  2579. }
  2580. }
  2581. switch(e.keyCode){
  2582. case 87: //W
  2583. // boxcls = classes;
  2584. createRectLabel();
  2585. break;
  2586. case 68:
  2587. deleterect();
  2588. break;
  2589. case 27:
  2590. cancel();
  2591. break;
  2592. case 83:
  2593. save();
  2594. break;
  2595. case 81:
  2596. last();
  2597. break;
  2598. case 69:
  2599. next();
  2600. break;
  2601. case 90://u
  2602. undo();
  2603. break;
  2604. case 67://c
  2605. copyOneBox();
  2606. break;
  2607. case 86://v
  2608. paste();
  2609. break;
  2610. case 37:
  2611. moveLeftSinglePx();
  2612. break;
  2613. case 38:
  2614. moveUpSinglePx();
  2615. break;
  2616. case 39:
  2617. moveRightSinglePx();
  2618. break;
  2619. case 40:
  2620. moveDownSinglePx();
  2621. break;
  2622. };
  2623. }