├── .gitignore ├── LICENSE.txt ├── README.md └── release ├── data ├── example1.mat ├── example2.mat ├── example3.mat └── frontCam.mat ├── demo.m ├── models └── mocapReducedModel.mat ├── setup.m └── src ├── alignToCamera.m ├── cameraAndPose.m ├── drawCam.m ├── estimateWPCamera.m ├── leastsquareseqcon3.m ├── plot2Dskeleton.m ├── pointsVisualize.m ├── process_options.m ├── projectIntoAffineCam.m ├── reArrangeBasis.m ├── recon3DPose.m ├── setK.m ├── skelConnectionMatrix.m └── visualizeGaussianModel.m /.gitignore: -------------------------------------------------------------------------------- 1 | .m~ 2 | .asv 3 | 4 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This repository contains code and examples for the paper: 2 | 3 | Reconstructing 3D Human Pose from 2D Image Landmarks.
4 | [Varun Ramakrishna](http://www.cs.cmu.edu/~vramakri), [Takeo Kanade](http://wwww.cs.cmu.edu/~tk), [Yaser Sheikh](http://www.cs.cmu.edu/~yaser)
5 | European Conference on Computer Vision, 2012. 6 | 7 | Please cite the above paper if you use the code in your work. 8 | 9 | --- 10 | **Copyright (C) 2012 by Varun Ramakrishna** 11 | 12 | camera_and_pose is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by (at your option) any later version. 13 | 14 | camera_and_pose is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public licenses along with camera_and_pose. If not, see . 17 | -------------------------------------------------------------------------------- /release/data/example1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/varunnr/camera_and_pose/2094baed10af928dc0d2215c1ff51e15a845dc76/release/data/example1.mat -------------------------------------------------------------------------------- /release/data/example2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/varunnr/camera_and_pose/2094baed10af928dc0d2215c1ff51e15a845dc76/release/data/example2.mat -------------------------------------------------------------------------------- /release/data/example3.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/varunnr/camera_and_pose/2094baed10af928dc0d2215c1ff51e15a845dc76/release/data/example3.mat -------------------------------------------------------------------------------- /release/data/frontCam.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/varunnr/camera_and_pose/2094baed10af928dc0d2215c1ff51e15a845dc76/release/data/frontCam.mat -------------------------------------------------------------------------------- /release/demo.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Demo %%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | disp('Reconstructing Example 1'); 3 | load example1.mat; 4 | [X, R, t] = recon3DPose(im,xy,'viz',1); 5 | input('Continue?'); 6 | 7 | disp('Reconstructing Example 2'); 8 | load example2.mat; 9 | [X, R, t] = recon3DPose(im,xy,'viz',1); 10 | input('Continue?'); 11 | 12 | disp('Reconstructing Example 3'); 13 | load example3.mat; 14 | [X, R, t] = recon3DPose(im,xy,'viz',1); -------------------------------------------------------------------------------- /release/models/mocapReducedModel.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/varunnr/camera_and_pose/2094baed10af928dc0d2215c1ff51e15a845dc76/release/models/mocapReducedModel.mat -------------------------------------------------------------------------------- /release/setup.m: -------------------------------------------------------------------------------- 1 | addpath src; 2 | addpath data; 3 | addpath models; -------------------------------------------------------------------------------- /release/src/alignToCamera.m: -------------------------------------------------------------------------------- 1 | function [Xnew]=alignToCamera(X,R,t,Rnew,tnew) 2 | % [Xnew]=alignToCamera(X,R,t,Rnew,tnew) 3 | % 4 | % R, t - Current Camera 5 | % Rnew, tnew - Camera to be aligned to. 6 | % 7 | % 8 | 9 | Xnew = R*X' + repmat(t,1,length(X)); 10 | Xnew = Rnew*Xnew+repmat(tnew,1,length(X)); 11 | 12 | Xnew = Xnew'; -------------------------------------------------------------------------------- /release/src/cameraAndPose.m: -------------------------------------------------------------------------------- 1 | function [camera, pose] = cameraAndPose(pose) 2 | % Inputs: pose - Structure containing 2D annotations and algorithm 3 | % parameters. See recon3DPose.m 4 | % 5 | % Outputs: camera - Structure with estimated camera parameters. 6 | % pose - Structure with estimated 3D pose. 7 | % 8 | % Reconstructs the 3D Pose of a human figure given the locations of the 2D 9 | % anatomical landmarks. 10 | % Copyright (C) 2012 Varun Ramakrishna. 11 | % 12 | % This program is free software: you can redistribute it and/or modify 13 | % it under the terms of the GNU General Public License as published by 14 | % the Free Software Foundation, either version 3 of the License, or 15 | % (at your option) any later version. 16 | % 17 | % This program is distributed in the hope that it will be useful, 18 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | % GNU General Public License for more details. 21 | % 22 | % You should have received a copy of the GNU General Public License 23 | % along with this program. If not, see . 24 | 25 | % Compute lengths and skeleton connectivity matrix. 26 | pose = getLimbLengths(pose); 27 | 28 | %% Initialization 29 | % Scale input so that K = eye(3). 30 | pose = scaleInput(pose); 31 | 32 | % Reshape Basis 33 | pose = reshapeBasis(pose); 34 | 35 | % Estimate initial cameras 36 | rigidInds = [1 2 5 8]; % Use rigid landmarks to estimate initial cam. 37 | xyMissing = pose.xyh(:,rigidInds); 38 | XMissing = pose.Xmu(rigidInds,1:3); 39 | [camera] = estimateWPCamera(xyMissing',XMissing); 40 | 41 | %Assemble projection matrix 42 | Msub = kron(eye(length(pose.annoids),length(pose.annoids)),camera.M); 43 | Mmu = Msub*pose.mureVis; 44 | xyt = pose.xyvisible(:) - kron(ones(length(pose.annoids),1),camera.taff); 45 | res = xyt - Mmu; 46 | 47 | %% Projected Matching Pursuit 48 | selectIdx = []; 49 | pose.numIters = 0; 50 | pose.repErr = inf; 51 | while (pose.repErr> pose.tol1 && length(selectIdx) < pose.ks) 52 | 53 | %Pick best basis vector 54 | A = Msub*pose.BreVis; 55 | A(:,selectIdx) = NaN; 56 | lambdas = res'*A; 57 | [~,imax] = max(abs(lambdas)); 58 | 59 | % Add basis to collection 60 | selectIdx = [selectIdx imax]; 61 | pose.selectIdx = selectIdx; 62 | 63 | % Minimize reconstruction error and compute residual 64 | [camera, pose, res] = minimizeReconError(pose, camera); 65 | Msub = kron(eye(length(pose.annoids),length(pose.annoids)),camera.M); 66 | end 67 | 68 | end 69 | 70 | 71 | 72 | function pose = scaleInput(pose) 73 | % Helper function to scale input so that K = eye(3) 74 | pose.xyunscaled = pose.xy; 75 | pose.xyh = pose.K\pose.xy; 76 | pose.xyvisible = pose.xyh(1:2,pose.annoids); 77 | end 78 | 79 | 80 | function pose = reshapeBasis(pose) 81 | % Helper function to reshape basis 82 | 83 | Bnew=[]; 84 | for i =1:size(pose.BOMP,2); 85 | Bnew =cat(3,Bnew,reshape(pose.BOMP(:,i),pose.numPoints,3)); 86 | end 87 | pose.Breshaped = Bnew; 88 | pose.mur = reshape(pose.mu,pose.numPoints,3); 89 | pose.Bfull = pose.BOMP; 90 | [pose.Bre,pose.mure] = reArrangeBasis(pose.BOMP,pose.mu,pose.numPoints); 91 | 92 | pose.BreTensor = reshape(pose.Bre,3,pose.numPoints,[]); 93 | pose.mureTensor = reshape(pose.mure,3,pose.numPoints,[]); 94 | pose.mureVis = pose.mureTensor(:,pose.annoids); 95 | pose.mureVis = pose.mureVis(:); 96 | pose.BreVis = pose.BreTensor(:,pose.annoids,:); 97 | pose.BreVis = reshape(pose.BreVis, 3*length(pose.annoids),[]); 98 | 99 | end 100 | 101 | function pose = getLimbLengths(pose) 102 | % Helper function to compute limblengths. 103 | 104 | connect = skelConnectionMatrix(pose.skel); 105 | [pose.I,pose.J] = ind2sub(size(connect), find(connect)); 106 | Xmu = reshape(pose.mu,pose.numPoints,3); 107 | Xmu = [Xmu ones(length(pose.xy),1)]; 108 | pose.lengths = squareform(pdist(Xmu)); 109 | pose.Xmu = Xmu; 110 | pose.lengths = squareform(pdist(Xmu)); 111 | 112 | end 113 | 114 | 115 | function [camera,pose,res] = minimizeReconError(pose,camera) 116 | selectIdx = pose.selectIdx; 117 | optType = pose.optType; 118 | mur = pose.mur; 119 | I = pose.I; 120 | J = pose.J; 121 | lengths = pose.lengths; 122 | Bnew = pose.Breshaped; 123 | xyvisible = pose.xyvisible; 124 | B = pose.Bfull; 125 | annoids = pose.annoids; 126 | epsxy = inf; 127 | xyprev = zeros(2,pose.numPoints); 128 | numIters = 0; 129 | while(epsxy>pose.tol2 && numIters < pose.numIters2) 130 | Msub = kron(eye(length(annoids),length(annoids)),camera.M); 131 | A = Msub*pose.BreVis(:,selectIdx); 132 | b = xyvisible(:) - kron(ones(length(annoids),1),camera.taff) - kron(eye(length(annoids),length(annoids)),camera.M)*pose.mureVis; 133 | %% Equality constrained 134 | switch optType 135 | case 1 136 | C = []; 137 | d = []; 138 | alphasq = 0; 139 | for i = 1:length(I) 140 | if(length(selectIdx)>1) 141 | Bi = (squeeze(Bnew(I(i),:,selectIdx))); 142 | Bj = (squeeze(Bnew(J(i),:,selectIdx))); 143 | else 144 | 145 | Bi = (squeeze(Bnew(I(i),:,selectIdx)))'; 146 | Bj = (squeeze(Bnew(J(i),:,selectIdx)))'; 147 | end 148 | mui = mur(I(i),:)'; 149 | muj = mur(J(i),:)'; 150 | C = [C; (Bi-Bj)] ; 151 | d = [d; -(mui-muj)]; 152 | alphasq = alphasq + lengths(I(i),J(i))^2; 153 | end 154 | alpha = sqrt(alphasq); 155 | % alpha = sqrt(pose.lengthsum); 156 | [a,asolT] = leastsquareseqcon3(A,b,C,d,alpha); 157 | asol = asolT'; 158 | 159 | end 160 | 161 | Xnew = B(:,selectIdx)*asol + pose.mu; 162 | XnewR= reshape(Xnew,pose.numPoints,3); 163 | pose.Xnew = Xnew; 164 | pose.XnewR = XnewR; 165 | pose.XnewRt = XnewR'; 166 | pose.Xnewre = pose.XnewRt(:); 167 | pose.XnewreVis = pose.XnewRt(:,annoids); 168 | pose.XnewreVis = pose.XnewreVis(:); 169 | 170 | XMissing=XnewR(annoids,:); 171 | xyMissing = xyvisible; 172 | pose.asol = asol; 173 | pose.selectIdx = selectIdx; 174 | 175 | xyrep1 = projectIntoAffineCam(XnewR,pose.K,camera.R,camera.t,camera.S,pose.skel); 176 | repErr1 = sum(sum((xyrep1(1:2,annoids)-pose.xyunscaled(1:2,annoids)).^2,1)); 177 | 178 | %Estimate camera 179 | [cameraHyp]= estimateWPCamera(xyMissing',XMissing); 180 | 181 | %Compute reprojection error 182 | xyrep2 = projectIntoAffineCam(XnewR,pose.K,cameraHyp.R,cameraHyp.t,cameraHyp.S,pose.skel); 183 | repErr2 = sum(sum((xyrep2(1:2,annoids)-pose.xyunscaled(1:2,annoids)).^2,1)); 184 | 185 | 186 | camera =cameraHyp; 187 | xyrep = xyrep2; 188 | repErr = repErr2; 189 | 190 | epsxy = sum(sum((xyrep(1:2,annoids)-xyprev(1:2,annoids)).^2,1)); 191 | xyprev = xyrep; 192 | pose.repErr = repErr; 193 | 194 | % Visualize 195 | if(pose.viz) 196 | figure(4);clf; 197 | pointsVisualize(XnewR,pose.skel,'texton',0);hold on; 198 | drawCam(cameraHyp.R,cameraHyp.t,'gt',1); 199 | 200 | figure(3);clf; 201 | imshow(pose.im);hold on; 202 | plot2Dskeleton(xyrep',pose.skel,1,'texton',0); 203 | hold on; 204 | plot2Dskeleton(pose.xyunscaled',pose.skel,1,'texton',0,'gt',1); 205 | axis ij; 206 | end 207 | 208 | numIters = numIters + 1; 209 | pose.numIters = pose.numIters +1; 210 | end 211 | 212 | res = xyvisible(:) - kron(ones(length(annoids),1),camera.taff) - kron(eye(length(annoids),length(annoids)),camera.M)*pose.XnewreVis; 213 | res = res- ((kron(eye(length(annoids),length(annoids)),camera.M))*B(:,selectIdx))*((kron(eye(length(annoids),length(annoids)),camera.M))*B(:,selectIdx))'*res; 214 | end -------------------------------------------------------------------------------- /release/src/drawCam.m: -------------------------------------------------------------------------------- 1 | function drawCam(R,t,varargin) 2 | [gt]= process_options(varargin,'gt',0); 3 | scale =5; 4 | P = scale*[0 0 0;0.5 0.5 0.8; 0.5 -0.5 0.8; -0.5 0.5 0.8;-0.5 -0.5 0.8]; 5 | 6 | %P = scale*[0 0 0;0.5 0.5 -0.8; 0.5 -0.5 -0.8; -0.5 0.5 -0.8;-0.5 -0.5 -0.8]; 7 | 8 | P1=R'*(P'-repmat(t,[1,5])); 9 | %P1=R*P'+repmat(t,[1,5]); 10 | P1=P1'; 11 | maxp=max(max(P1)); 12 | %axis(2*[-maxp maxp -maxp maxp -maxp maxp]); 13 | if(~gt) 14 | line([P1(1,1) P1(2,1)],[P1(1,3) P1(2,3)],[P1(1,2) P1(2,2)],'color','k') 15 | line([P1(1,1) P1(3,1)],[P1(1,3) P1(3,3)],[P1(1,2) P1(3,2)],'color','k') 16 | line([P1(1,1) P1(4,1)],[P1(1,3) P1(4,3)],[P1(1,2) P1(4,2)],'color','k') 17 | line([P1(1,1) P1(5,1)],[P1(1,3) P1(5,3)],[P1(1,2) P1(5,2)],'color','k') 18 | 19 | line([P1(2,1) P1(3,1)],[P1(2,3) P1(3,3)],[P1(2,2) P1(3,2)],'color','k') 20 | line([P1(3,1) P1(5,1)],[P1(3,3) P1(5,3)],[P1(3,2) P1(5,2)],'color','k') 21 | line([P1(5,1) P1(4,1)],[P1(5,3) P1(4,3)],[P1(5,2) P1(4,2)],'color','k') 22 | line([P1(4,1) P1(2,1)],[P1(4,3) P1(2,3)],[P1(4,2) P1(2,2)],'color','k') 23 | 24 | 25 | cameraPlane =[P1(2,1) P1(2,3) P1(2,2); P1(4,1) P1(4,3) P1(4,2); P1(3,1) P1(3,3) P1(3,2);P1(5,1) P1(5,3) P1(5,2)]; 26 | faces =[2 1 3 4]; 27 | patch('Vertices',cameraPlane,'Faces',faces,'FaceVertexCData',hsv(6),'FaceColor','k','FaceAlpha',0.1); 28 | else 29 | line([P1(1,1) P1(2,1)],[P1(1,3) P1(2,3)],[P1(1,2) P1(2,2)],'color','k','LineStyle','--') 30 | line([P1(1,1) P1(3,1)],[P1(1,3) P1(3,3)],[P1(1,2) P1(3,2)],'color','k','LineStyle','--') 31 | line([P1(1,1) P1(4,1)],[P1(1,3) P1(4,3)],[P1(1,2) P1(4,2)],'color','k','LineStyle','--') 32 | line([P1(1,1) P1(5,1)],[P1(1,3) P1(5,3)],[P1(1,2) P1(5,2)],'color','k','LineStyle','--') 33 | 34 | line([P1(2,1) P1(3,1)],[P1(2,3) P1(3,3)],[P1(2,2) P1(3,2)],'color','k','LineStyle','--') 35 | line([P1(3,1) P1(5,1)],[P1(3,3) P1(5,3)],[P1(3,2) P1(5,2)],'color','k','LineStyle','--') 36 | line([P1(5,1) P1(4,1)],[P1(5,3) P1(4,3)],[P1(5,2) P1(4,2)],'color','k','LineStyle','--') 37 | line([P1(4,1) P1(2,1)],[P1(4,3) P1(2,3)],[P1(4,2) P1(2,2)],'color','k','LineStyle','--') 38 | 39 | % 40 | % cameraPlane =[P1(2,1) P1(2,3) P1(2,2); P1(4,1) P1(4,3) P1(4,2); P1(3,1) P1(3,3) P1(3,2);P1(5,1) P1(5,3) P1(5,2)]; 41 | % faces =[2 1 3 4]; 42 | % patch('Vertices',cameraPlane,'Faces',faces,'FaceVertexCData',hsv(6),'FaceColor','k','FaceAlpha',0.05); 43 | 44 | end 45 | 46 | 47 | C1=[P1(2,1) P1(2,3) P1(2,2)]; 48 | C2=[P1(3,1) P1(3,3) P1(3,2)]; 49 | C3=[P1(4,1) P1(4,3) P1(4,2)]; 50 | C4=[P1(5,1) P1(5,3) P1(5,2)]; 51 | 52 | O=[P1(1,1) P1(1,3) P1(1,2)]; 53 | Cmid =0.25*(C1+C2+C3+C4); 54 | 55 | % Lz = [O; O+0.5*(Cmid-O)]; 56 | % Lx = [O; O+0.5*(C2-C1)]; 57 | % Ly = [O; O+0.5*(C3-C1)]; 58 | 59 | Lz = [O; O+0.5*(Cmid-O)]; 60 | Lx = [O; O+0.5*(C1-C3)]; 61 | Ly = [O; O+0.5*(C1-C2)]; 62 | 63 | if(~gt) 64 | 65 | line(Lz(:,1),Lz(:,2),Lz(:,3),'color','b','linewidth',2) 66 | line(Lx(:,1),Lx(:,2),Lx(:,3),'color','g','linewidth',2) 67 | line(Ly(:,1),Ly(:,2),Ly(:,3),'color','r','linewidth',2) 68 | 69 | else 70 | line(Lz(:,1),Lz(:,2),Lz(:,3),'color','b','linewidth',1) 71 | line(Lx(:,1),Lx(:,2),Lx(:,3),'color','g','linewidth',1) 72 | line(Ly(:,1),Ly(:,2),Ly(:,3),'color','r','linewidth',1) 73 | 74 | 75 | 76 | end 77 | 78 | axis tight; -------------------------------------------------------------------------------- /release/src/estimateWPCamera.m: -------------------------------------------------------------------------------- 1 | function [camera]= estimateWPCamera(xy,XY) 2 | %[Raff, taff, R, scale,t,Rproc,tproc]= 3 | %estimateOrthoCamera(xy,XY,scaleFactor) 4 | xy=xy(:,1:2); 5 | % xy=scaleFactor*xy; 6 | taff= mean(xy,1); 7 | xy=xy-repmat(taff,[size(xy,1) 1]); 8 | 9 | 10 | numPoints = size(xy,1); 11 | A = zeros(2*numPoints,size(XY,2)+3); 12 | b = zeros(2*numPoints,1); 13 | 14 | for i=1:numPoints 15 | 16 | A((i-1)*2+1,:) = [ XY(i,:) 0 0 0]; 17 | A(i*2,:) = [ 0 0 0 XY(i,:)]; 18 | 19 | b((i-1)*2+1) = xy(i,1); 20 | b(i*2) = xy(i,2); 21 | 22 | end 23 | 24 | %% Procrustes solution as initial point 25 | 26 | x=xy; 27 | X=XY'; 28 | meanX=mean(X,2); 29 | X=X-repmat(meanX,1,size(X,2)); 30 | 31 | M=x'*X'*inv(X*X'); 32 | % M = x'/X; 33 | [U,S,V]=svd(M); 34 | 35 | Inew=[1 0 0; 0 1 0]; 36 | R = U*Inew*V'; 37 | 38 | r3=cross(R(1,:),R(2,:)); 39 | r3=r3/norm(r3); 40 | rinit =[R(1,:) R(2,:)]'; 41 | 42 | 43 | Raff=R; 44 | R=[R; r3]; 45 | scaleFactor=0.5*(S(2,2)+S(1,1)); 46 | 47 | t=[taff';1/scaleFactor]; 48 | det(R); 49 | if(sum(abs(diag(U)))>1) 50 | S = S(1:2,1:2); 51 | else 52 | S = S(1:2,1:2); 53 | S = flipud(fliplr(S)); 54 | % disp('Flip scales'); 55 | end 56 | % S = U*S; 57 | 58 | 59 | %% 60 | % %Solve non-linear optimization using fmincon 61 | % options = optimset('Algorithm','interior-point'); 62 | % r=fmincon(@(x) objective(x,A,b),rinit,[],[],[],[],[],[], @(x) orthoConstraints(x),options); 63 | % % 64 | % Raff=[ r(1) r(2) r(3);... 65 | % r(4) r(5) r(6);]; 66 | % % 67 | % % Find full rotation matrix 68 | % r1=Raff(1,:); 69 | % r2=Raff(2,:); 70 | % r3=cross(Raff(1,:),Raff(2,:)); 71 | % r3=r3/norm(r3); 72 | % R=[r1;r2;r3]; 73 | % 74 | % %Estimate average scale 75 | % %scale = mean(r2*XY'./xyunscaled(:,2)'); 76 | % %t=[taff';scale]; 77 | % 78 | camera.Raff = Raff; 79 | camera.taff = taff'; 80 | camera.R = R; 81 | camera.t = t; 82 | camera.S = S; 83 | camera.M = S*Raff; 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | end 92 | 93 | 94 | function f=objective(x,A,b) 95 | f= (A*x-b)'*(A*x-b); 96 | end 97 | 98 | function [c,ceq] = orthoConstraints(x) 99 | 100 | ceq = [[x(1) x(2) x(3)]*[x(4) x(5) x(6)]';... 101 | [x(1) x(2) x(3)]*[x(1) x(2) x(3)]'-1;... 102 | [x(4) x(5) x(6)]*[x(4) x(5) x(6)]'-1;]; 103 | c=[]; 104 | 105 | end -------------------------------------------------------------------------------- /release/src/leastsquareseqcon3.m: -------------------------------------------------------------------------------- 1 | function [x, xsol] = leastsquareseqcon3(A,b,C,d,alpha) 2 | 3 | % Solve generalized SVD to get gammas and alphas. Please refer Gander et al, for description of the algorithm. 4 | 5 | [U,V,X,Da,Dc] = gsvd(A,C); 6 | c = U'*b; 7 | e = V'*d; 8 | p = size(C,1); 9 | r = sum(diag(Dc)>0); 10 | lambda = sym('lambda','real'); 11 | i=1; 12 | % tic; 13 | f=Da(i,i)^2 *(Dc(i,i)*c(i)-Da(i,i)*e(i))^2/(Da(i,i)^2+lambda*Dc(i,i)^2)^2; 14 | for i = 2:r 15 | a=Da(i,i)^2 *(Dc(i,i)*c(i)-Da(i,i)*e(i))^2/(Da(i,i)^2+lambda*Dc(i,i)^2)^2; 16 | f = f+ a; 17 | end 18 | % toc; 19 | 20 | if(length(e)>r) 21 | for i =r+1:p 22 | f = f+e(i)^2; 23 | end 24 | end 25 | f = f-alpha^2; 26 | [num,den] = numden(f); 27 | c = coeffs(num); 28 | numNorm = vpa(num/c(end)); 29 | % lambdaSol = roots(coeff); 30 | 31 | if(diff(f)~=0) 32 | 33 | lambdaSol = solve(numNorm); 34 | lambdaSol = double(lambdaSol); 35 | 36 | realLambdaSol = lambdaSol(~(abs(imag(lambdaSol))>0)); 37 | ind = find(realLambdaSol == max(realLambdaSol)); 38 | ind =ind(1); 39 | 40 | xsol = (A'*A+realLambdaSol(ind)*(C'*C))\(A'*b+realLambdaSol(ind)*C'*d); 41 | xsol = xsol'; 42 | x = xsol; 43 | if(sum(isnan(xsol))) 44 | xsol(isnan(xsol))=0; 45 | end 46 | % disp(xsol'); 47 | else 48 | 49 | end 50 | 51 | 52 | 53 | 54 | 55 | 56 | %% Solve completely symbolically. 57 | % syms x lambda; 58 | % x = inv(A'*A + lambda*C'*C)*(A'*b + lambda*C'*d); 59 | % f = (C*x-d)'*(C*x -d); 60 | % lambdaSol = solve(f-alpha^2); 61 | % for i = 1:length(lambdaSol) 62 | % xsol(:,i) = feval(matlabFunction(x),double(lambdaSol(i))); 63 | % end 64 | % x = xsol; 65 | % realLambdaSol = lambdaSol(~(abs(imag(lambdaSol))>0)); 66 | % ind = find(realLambdaSol == max(realLambdaSol)); 67 | % xsol = x(ind,:); 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /release/src/plot2Dskeleton.m: -------------------------------------------------------------------------------- 1 | function [hSkel,hSkelText] =plot2Dskeleton(xy,skel,type,varargin) 2 | %PLOT2DSKELETON Plots projection of skeleton 3 | % plot2Dskeleton(xy,skel) 4 | % 5 | % Description: 6 | % 7 | % 8 | % Inputs: 9 | % 10 | % 11 | % Outputs: 12 | % 13 | % 14 | % Example: 15 | % plot2Dskeleton 16 | % 17 | % See also 18 | 19 | % Author: Varun Ramakrishna 20 | % Created: Jan 31, 2011 21 | xy=xy'; 22 | [texton,linewidth,gt,hparent] = process_options(varargin,'texton',1,'linewidth',2,'gt',0,'Parent',gca); 23 | numPts=size(xy,2); 24 | for i =1:numPts 25 | strs{i}={int2str(i)}; 26 | end 27 | 28 | 29 | connect = skelConnectionMatrix(skel); 30 | indices = find(connect); 31 | [I, J] = ind2sub(size(connect), indices); 32 | 33 | % gca; hold on; 34 | 35 | %figure 36 | % hold on; 37 | % plot(xy(1,:),xy(2,:),'o','LineWidth',linewidth,'MarkerSize',5); 38 | 39 | 40 | colors=prism(6); 41 | if(type==2) 42 | M=[ colors(4:6,:); ... 43 | colors(4:6,:); ... 44 | colors(6,:); colors(6,:); colors(6,:); colors(5,:); colors(6,:); ... 45 | colors(1,:); colors(2,:); colors(1,:); ... 46 | colors(1,:); colors(2,:); colors(1,:); ... 47 | ]; 48 | elseif(type==1) 49 | M= [colors(4:6,:); colors(1,:); ... 50 | colors(4:6,:); colors(1,:); ... 51 | colors(6,:); colors(6,:); colors(6,:); colors(5,:); colors(5,:); colors(5,:);... 52 | colors(1,:); colors(2,:); colors(1,:); colors(4,:); ... 53 | colors(1,:); colors(2,:); colors(1,:); colors(4,:);... 54 | ]; 55 | elseif(type==3) 56 | M=[ colors(4:6,:); ... 57 | colors(4:6,:); ... 58 | colors(6,:); colors(6,:); colors(6,:); colors(5,:); colors(6,:); ... 59 | colors(1,:); colors(2,:); colors(1,:); ... 60 | colors(1,:); 61 | ]; 62 | end 63 | 64 | if(texton) 65 | for i =1:size(xy,2) 66 | hSkelText(i) = text(xy(1,i),xy(2,i),strs{i}); 67 | end 68 | end 69 | xy=xy'; 70 | % axis equal 71 | hold on; 72 | 73 | for i = 1:length(indices) 74 | if(gt) 75 | 76 | hSkel(i) = line([xy(I(i),1) xy(J(i),1)], ... 77 | [xy(I(i),2) xy(J(i),2)],'color','k','Parent',hparent); 78 | set(hSkel(i), 'linewidth', linewidth,'LineStyle','--'); 79 | else 80 | 81 | hSkel(i) = line([xy(I(i),1) xy(J(i),1)], ... 82 | [xy(I(i),2) xy(J(i),2)],'color',M(i,:),'Parent',hparent); 83 | set(hSkel(i), 'linewidth', linewidth); 84 | end 85 | end 86 | -------------------------------------------------------------------------------- /release/src/pointsVisualize.m: -------------------------------------------------------------------------------- 1 | function pointsVisualize(vals,skel,varargin) 2 | %function pointsVisualize(vals,skel) 3 | [color,type,person,connect,missing,gt,texton,textsize,linewidth,showlines,marker]=process_options(varargin,'color','r','type',1,'person',1,'connect',[],'missing', [],'gt',0,'texton',1,'textsize',10,'linewidth',5,'showlines',1,'marker','o'); 4 | 5 | for i =1:size(vals,1) 6 | strs{i}=num2str(i); 7 | end 8 | if isempty(connect) 9 | connect = skelConnectionMatrix(skel); 10 | end 11 | 12 | indices = find(connect); 13 | [I, J] = ind2sub(size(connect), indices); 14 | %handle(1)=figure; 15 | inds = ones(size(vals,1),1); 16 | inds(missing) = 0; 17 | inds = logical(inds); 18 | 19 | handle(1) = plot3(vals(inds, 1), vals(inds, 3), vals(inds, 2), marker, 'LineWidth', linewidth, 'MarkerSize', 5); 20 | hold on; 21 | if(texton) 22 | for i = 1: length(vals) 23 | h1 = text( vals(i, 1), vals(i, 3), vals(i, 2),strs{i},'FontSize',textsize,'FontWeight','bold'); 24 | end 25 | end 26 | axis ij % make sure the left is on the left. 27 | 28 | 29 | grid on 30 | 31 | colors=prism(6); 32 | if(type==2) 33 | M=[ colors(4:6,:); ... 34 | colors(4:6,:); ... 35 | colors(6,:); colors(6,:); colors(6,:); colors(5,:); colors(6,:); ... 36 | colors(1,:); colors(2,:); colors(1,:); ... 37 | colors(1,:); colors(2,:); colors(1,:); ... 38 | ]; 39 | elseif(type==1) 40 | if person ==1 41 | colors=prism(6); 42 | M= [colors(4:6,:); colors(1,:); ... 43 | colors(4:6,:); colors(1,:); ... 44 | colors(6,:); colors(6,:); colors(6,:); colors(5,:); colors(6,:); colors(5,:);... 45 | colors(1,:); colors(2,:); colors(1,:); colors(4,:); ... 46 | colors(1,:); colors(2,:); colors(1,:); colors(4,:);... 47 | ]; 48 | elseif person ==2 49 | colors =jet(6); 50 | M= [colors(4:6,:); colors(1,:); ... 51 | colors(4:6,:); colors(1,:); ... 52 | colors(6,:); colors(6,:); colors(6,:); colors(5,:); colors(6,:); colors(5,:);... 53 | colors(1,:); colors(2,:); colors(1,:); colors(4,:); ... 54 | colors(1,:); colors(2,:); colors(1,:); colors(4,:);... 55 | ]; 56 | 57 | end 58 | elseif(type==3) 59 | M=[ colors(4:6,:); ... 60 | colors(4:6,:); ... 61 | colors(6,:); colors(6,:); colors(6,:); ... 62 | colors(1,:); colors(2,:); colors(1,:); ... 63 | colors(1,:); colors(2,:); colors(1,:); ... 64 | ]; 65 | else 66 | M = repmat(colors(2,:),length(indices),1); 67 | end 68 | if(showlines) 69 | if(type<4) 70 | for i = 1:length(indices) 71 | 72 | handle(i+1) = line([vals(I(i), 1) vals(J(i), 1)], ... 73 | [vals(I(i), 3) vals(J(i), 3)], ... 74 | [vals(I(i), 2) vals(J(i), 2)]); 75 | missI = logical(length(find(missing == I(i)))); 76 | missJ = logical(length(find(missing == J(i)))); 77 | if(missI || missJ) 78 | set(handle(i+1), 'linewidth', linewidth,'Color',M(i,:), 'LineStyle', '--'); 79 | elseif(gt) 80 | set(handle(i+1), 'linewidth', linewidth,'Color','k', 'LineStyle', '--'); 81 | else 82 | set(handle(i+1), 'linewidth', linewidth,'Color',M(i,:)); 83 | end 84 | end 85 | axis equal 86 | else 87 | 88 | for i = 1:length(indices) 89 | handle(i+1) = line([vals(I(i), 1) vals(J(i), 1)],... 90 | [vals(I(i), 2) vals(J(i), 2)], ... 91 | [vals(I(i), 3) vals(J(i), 3)]); 92 | set(handle(i+1), 'linewidth', 5,'Color',M(i,:)); 93 | end 94 | axis equal 95 | end 96 | end 97 | 98 | % xlabel('x','Interpreter','latex','fontsize',10); 99 | % ylabel('z','Interpreter','latex','fontsize',10); 100 | % zlabel('y','Interpreter','latex','fontsize',10); 101 | 102 | 103 | 104 | hold off -------------------------------------------------------------------------------- /release/src/process_options.m: -------------------------------------------------------------------------------- 1 | % PROCESS_OPTIONS - Processes options passed to a Matlab function. 2 | % This function provides a simple means of 3 | % parsing attribute-value options. Each option is 4 | % named by a unique string and is given a default 5 | % value. 6 | % 7 | % Usage: [var1, var2, ..., varn[, unused]] = ... 8 | % process_options(args, ... 9 | % str1, def1, str2, def2, ..., strn, defn) 10 | % 11 | % Arguments: 12 | % args - a cell array of input arguments, such 13 | % as that provided by VARARGIN. Its contents 14 | % should alternate between strings and 15 | % values. 16 | % str1, ..., strn - Strings that are associated with a 17 | % particular variable 18 | % def1, ..., defn - Default values returned if no option 19 | % is supplied 20 | % 21 | % Returns: 22 | % var1, ..., varn - values to be assigned to variables 23 | % unused - an optional cell array of those 24 | % string-value pairs that were unused; 25 | % if this is not supplied, then a 26 | % warning will be issued for each 27 | % option in args that lacked a match. 28 | % 29 | % Examples: 30 | % 31 | % Suppose we wish to define a Matlab function 'func' that has 32 | % required parameters x and y, and optional arguments 'u' and 'v'. 33 | % With the definition 34 | % 35 | % function y = func(x, y, varargin) 36 | % 37 | % [u, v] = process_options(varargin, 'u', 0, 'v', 1); 38 | % 39 | % calling func(0, 1, 'v', 2) will assign 0 to x, 1 to y, 0 to u, and 2 40 | % to v. The parameter names are insensitive to case; calling 41 | % func(0, 1, 'V', 2) has the same effect. The function call 42 | % 43 | % func(0, 1, 'u', 5, 'z', 2); 44 | % 45 | % will result in u having the value 5 and v having value 1, but 46 | % will issue a warning that the 'z' option has not been used. On 47 | % the other hand, if func is defined as 48 | % 49 | % function y = func(x, y, varargin) 50 | % 51 | % [u, v, unused_args] = process_options(varargin, 'u', 0, 'v', 1); 52 | % 53 | % then the call func(0, 1, 'u', 5, 'z', 2) will yield no warning, 54 | % and unused_args will have the value {'z', 2}. This behaviour is 55 | % useful for functions with options that invoke other functions 56 | % with options; all options can be passed to the outer function and 57 | % its unprocessed arguments can be passed to the inner function. 58 | 59 | % Copyright (C) 2002 Mark A. Paskin 60 | % 61 | % This program is free software; you can redistribute it and/or modify 62 | % it under the terms of the GNU General Public License as published by 63 | % the Free Software Foundation; either version 2 of the License, or 64 | % (at your option) any later version. 65 | % 66 | % This program is distributed in the hope that it will be useful, but 67 | % WITHOUT ANY WARRANTY; without even the implied warranty of 68 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 69 | % General Public License for more details. 70 | % 71 | % You should have received a copy of the GNU General Public License 72 | % along with this program; if not, write to the Free Software 73 | % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 74 | % USA. 75 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 76 | 77 | function [varargout] = process_options(args, varargin) 78 | 79 | % Check the number of input arguments 80 | n = length(varargin); 81 | if (mod(n, 2)) 82 | error('Each option must be a string/value pair.'); 83 | end 84 | 85 | % Check the number of supplied output arguments 86 | if (nargout < (n / 2)) 87 | error('Insufficient number of output arguments given'); 88 | elseif (nargout == (n / 2)) 89 | warn = 1; 90 | nout = n / 2; 91 | else 92 | warn = 0; 93 | nout = n / 2 + 1; 94 | end 95 | 96 | % Set outputs to be defaults 97 | varargout = cell(1, nout); 98 | for i=2:2:n 99 | varargout{i/2} = varargin{i}; 100 | end 101 | 102 | % Now process all arguments 103 | nunused = 0; 104 | for i=1:2:length(args) 105 | found = 0; 106 | for j=1:2:n 107 | if strcmpi(args{i}, varargin{j}) 108 | varargout{(j + 1)/2} = args{i + 1}; 109 | found = 1; 110 | break; 111 | end 112 | end 113 | if (~found) 114 | if (warn) 115 | warning(sprintf('Option ''%s'' not used.', args{i})); 116 | args{i} 117 | else 118 | nunused = nunused + 1; 119 | unused{2 * nunused - 1} = args{i}; 120 | unused{2 * nunused} = args{i + 1}; 121 | end 122 | end 123 | end 124 | 125 | % Assign the unused arguments 126 | if (~warn) 127 | if (nunused) 128 | varargout{nout} = unused; 129 | else 130 | varargout{nout} = cell(0); 131 | end 132 | end 133 | -------------------------------------------------------------------------------- /release/src/projectIntoAffineCam.m: -------------------------------------------------------------------------------- 1 | function xy=projectIntoAffineCam(X, K,R,t,S,skel,varargin ) 2 | %xy=projectIntoAffineCam(X, K,R,t,S,skel ) 3 | [viz,s]=process_options(varargin,'viz',0,'scale',1); 4 | 5 | %% Do projection 6 | numPts =size(X,1); 7 | 8 | %Create Affine camera 9 | Raff =[ R(1,:); R(2,:); zeros(1,3)]; 10 | taff =K*[ t(1); t(2); 1]; % TODO: z-dim should be scaling 11 | M=K*Raff; 12 | 13 | 14 | %Project into affine camera 15 | xy = S*M(1:2,:)*X' + repmat(taff(1:2),[1,numPts]); 16 | xy(3,:) = ones(1,size(xy,2)); 17 | %% Plot projection 18 | 19 | if(viz) 20 | connect = skelConnectionMatrix(skel); 21 | indices = find(connect); 22 | [I, J] = ind2sub(size(connect), indices); 23 | for i =1:numPts 24 | strs{i}={int2str(i)}; 25 | end 26 | 27 | if(~isempty(skel)) 28 | 29 | figure 30 | handle(1)=plot(xy(1,:),xy(2,:),'x'); 31 | hold on 32 | for i =1:size(xy,2) 33 | text(xy(1,i),xy(2,i),strs{i}); 34 | end 35 | axis equal 36 | hold off 37 | 38 | if(K(1,3)>0) &&(K(2,3)>0) 39 | axis([0 2*K(1,3) 0 2*K(2,3)]); 40 | end 41 | axis ij% make sure the left is on the left. 42 | set(handle(1), 'markersize', 20); 43 | hold on 44 | grid on 45 | for i = 1:length(indices) 46 | handle(i+1) = line([xy(1,I(i)) xy(1,J(i))], ... 47 | [xy(2,I(i)) xy(2,J(i))]); 48 | set(handle(i+1), 'linewidth', 2); 49 | end 50 | hold off 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /release/src/reArrangeBasis.m: -------------------------------------------------------------------------------- 1 | function [Bre,mure] = reArrangeBasis(B,mu,numPoints) 2 | 3 | for i = 1:size(B,2) 4 | Btemp = reshape(B(:,i),numPoints,3)'; 5 | Bre(:,i) = Btemp(:); 6 | end 7 | mutemp = reshape(mu,numPoints,3)'; 8 | mure = mutemp(:); -------------------------------------------------------------------------------- /release/src/recon3DPose.m: -------------------------------------------------------------------------------- 1 | % [X, R, t] = function recon3DPose(xy,im,varargin) 2 | % 3 | % Inputs: xy - [2 x 14] matrix of 2D joint locations 4 | % im - Input image 5 | % 6 | % 7 | % 8 | % Outputs: X - [3 x 14] matrix of 3D joint locations. 9 | % R - [3 x 3] Relative Camera Rotation. 10 | % t - [3 x 1] Relative Camera translation. 11 | % 12 | % Wrapper for reconstruction of the 3D Pose of a human figure given the 13 | % locations of the 2D anatomical landmarks. 14 | % Copyright (C) 2012 Varun Ramakrishna. 15 | % 16 | % This program is free software: you can redistribute it and/or modify 17 | % it under the terms of the GNU General Public License as published by 18 | % the Free Software Foundation, either version 3 of the License, or 19 | % (at your option) any later version. 20 | % 21 | % This program is distributed in the hope that it will be useful, 22 | % but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 | % GNU General Public License for more details. 25 | % 26 | % You should have received a copy of the GNU General Public License 27 | % along with this program. If not, see . 28 | 29 | function [X, R, t] = recon3DPose(im,xy,varargin) 30 | % [X, R, t] = recon3DPose(xy,im,varargin) 31 | 32 | % Parse parameters. 33 | [pose.skel, pose.BOMP, pose.mu, pose.lambda1,... 34 | pose.lamda2, pose.K, pose.numIter,... 35 | pose.numIters2, pose.tol1, pose.tol2, pose.ks,... 36 | pose.optType, pose.viz, pose.annoids,pose.numPoints] = process_options(varargin,... 37 | 'skel','',... 38 | 'BOMP','',... 39 | 'mu' ,'',... 40 | 'lambda2',0.01,... 41 | 'lambda1',0.01,... 42 | 'K', setK(size(im,2),size(im,1),2),... 43 | 'numIter', 20,... 44 | 'numIters2',30,... 45 | 'tol1', 500, ... 46 | 'tol2', 1, ... 47 | 'ks', 15, ... 48 | 'optType', 1, ... 49 | 'viz', 0,... 50 | 'annoids',1:15,... 51 | 'numPoints',15); 52 | pose.im = im; 53 | pose.xy = [xy; ones(1,size(xy,2))]; 54 | 55 | % Load default basis and skeleton 56 | if(isempty(pose.BOMP)||isempty(pose.mu)||isempty(pose.skel)) 57 | basis = load('mocapReducedModel.mat'); 58 | pose.BOMP = basis.B; 59 | pose.mu = basis.mu; 60 | pose.skel = basis.skel; 61 | pose.numPoints = length(pose.skel.tree); 62 | pose.annoids = [1:length(pose.skel.tree)]; 63 | end 64 | 65 | % Reconstruct camera and pose. 66 | [camera, pose] = cameraAndPose(pose); 67 | 68 | % Assign outputs 69 | X = pose.XnewR; 70 | R = camera.R; 71 | t = camera.t; 72 | 73 | % Show aligned output 74 | if(pose.viz) 75 | load frontCam; 76 | Xnew1 = alignToCamera(pose.XnewR,camera.R,camera.t,R,t); 77 | figure(9);clf; 78 | visualizeGaussianModel(Xnew1,pose.skel); 79 | drawCam(R,t); 80 | end 81 | -------------------------------------------------------------------------------- /release/src/setK.m: -------------------------------------------------------------------------------- 1 | function K=setK(x,y,f) 2 | K=eye(3); 3 | K(1,1) = f*x; 4 | K(2,2) =f*x; 5 | K(1,3) = x/2; 6 | K(2,3) =y/2; -------------------------------------------------------------------------------- /release/src/skelConnectionMatrix.m: -------------------------------------------------------------------------------- 1 | function connection = skelConnectionMatrix(skel); 2 | 3 | % SKELCONNECTIONMATRIX Compute the connection matrix for the structure. 4 | % 5 | % Description: 6 | % 7 | % CONNECTION = SKELCONNECTIONMATRIX(SKEL) computes the connection 8 | % matrix for the structure. Returns a matrix which has zeros at all 9 | % entries except those that are connected in the skeleton. 10 | % Returns: 11 | % CONNECTION - connectivity matrix. 12 | % Arguments: 13 | % SKEL - the skeleton for which the connectivity is required. 14 | % 15 | % 16 | % See also 17 | % SKELVISUALISE, SKELMODIFY 18 | 19 | 20 | % Copyright (c) 2006 Neil D. Lawrence 21 | % skelConnectionMatrix.m CVS version 1.2 22 | % skelConnectionMatrix.m SVN version 42 23 | % last update 2008-08-12T20:23:47.000000Z 24 | 25 | connection = zeros(length(skel.tree)); 26 | for i = 1:length(skel.tree); 27 | for j = 1:length(skel.tree(i).children) 28 | connection(i, skel.tree(i).children(j)) = 1; 29 | end 30 | end 31 | 32 | -------------------------------------------------------------------------------- /release/src/visualizeGaussianModel.m: -------------------------------------------------------------------------------- 1 | function gaussianMan = visualizeGaussianModel(vals,skel,varargin) 2 | 3 | [color,type,person,connect]=process_options(varargin,'color','r','type',1,'person',1,'connect',[]); 4 | 5 | for i =1:size(vals,1) 6 | strs{i}={int2str(i)}; 7 | end 8 | if isempty(connect) 9 | connect = skelConnectionMatrix(skel); 10 | end 11 | 12 | indices = find(connect); 13 | [I, J] = ind2sub(size(connect), indices); 14 | handle(1) = plot3(vals(:, 1), vals(:, 3), vals(:, 2), '.'); 15 | axis ij % make sure the left is on the left. 16 | set(handle(1), 'markersize', 1); 17 | hold on 18 | grid on 19 | 20 | colors=prism(6); 21 | if(type==2) 22 | M=[ colors(4:6,:); ... 23 | colors(4:6,:); ... 24 | colors(6,:); colors(6,:); colors(6,:); colors(5,:); colors(6,:); ... 25 | colors(1,:); colors(2,:); colors(1,:); ... 26 | colors(1,:); colors(2,:); colors(1,:); ... 27 | ]; 28 | elseif(type==1) 29 | if person ==1 30 | colors=prism(6); 31 | M= [colors(4:6,:); colors(1,:); ... 32 | colors(4:6,:); colors(1,:); ... 33 | colors(6,:); colors(6,:); colors(6,:); colors(5,:); colors(5,:); colors(5,:);... 34 | colors(1,:); colors(2,:); colors(1,:); colors(4,:); ... 35 | colors(1,:); colors(2,:); colors(1,:); colors(4,:);... 36 | ]; 37 | elseif person ==2 38 | colors =jet(6); 39 | M= [colors(4:6,:); colors(1,:); ... 40 | colors(4:6,:); colors(1,:); ... 41 | colors(6,:); colors(6,:); colors(6,:); colors(5,:); colors(6,:); colors(5,:);... 42 | colors(1,:); colors(2,:); colors(1,:); colors(4,:); ... 43 | colors(1,:); colors(2,:); colors(1,:); colors(4,:);... 44 | ]; 45 | 46 | end 47 | elseif(type==3) 48 | M=[ colors(4:6,:); ... 49 | colors(4:6,:); ... 50 | colors(6,:); colors(6,:); colors(6,:); ... 51 | colors(1,:); colors(2,:); colors(1,:); ... 52 | colors(1,:); colors(2,:); colors(1,:); ... 53 | ]; 54 | else 55 | M = repmat(colors(2,:),length(indices),1); 56 | end 57 | 58 | 59 | 60 | if(type<4) 61 | for i = 1:length(indices) 62 | P1 = [vals(I(i),1) vals(I(i),3) vals(I(i),2)]; 63 | P2 = [vals(J(i),1) vals(J(i),3) vals(J(i),2)]; 64 | P = 0.5*(P1 + P2); 65 | U = [ null(P1 - P2)'; (P1 -P2)/norm(P1-P2)]; 66 | S = eye(3); S(1,1) = 1.5*norm(P1-P2); 67 | C = U*S*U'; 68 | [x,y,z] = ellipsoid(0,0,0,0.8,0.8,1.1*sqrt(1.5*norm(P1-P2)),8); 69 | axis equal; 70 | xv =x(:); 71 | yv = y(:); 72 | zv = z(:); 73 | newXYZ = U'*[xv';yv';zv']; 74 | xnew = reshape(newXYZ(1,:)+P(1),size(x,1),size(x,2)); 75 | ynew = reshape(newXYZ(2,:)+P(2),size(x,1),size(x,2)); 76 | znew = reshape(newXYZ(3,:)+P(3),size(x,1),size(x,2)); 77 | 78 | 79 | handle(i+1) = patch(surf2patch(xnew,ynew,znew)); 80 | 81 | set(handle(i+1),'EdgeColor','k','EdgeAlpha',0.1); 82 | set(handle(i+1),'FaceLighting','phong','AmbientStrength',0.6); 83 | set(handle(i+1),'FaceColor', M(i,:)); 84 | set(handle(i+1),'BackfaceLighting','lit'); 85 | 86 | gaussianMan(i).P = P; 87 | gaussianMan(i).C = C; 88 | 89 | end 90 | axis equal 91 | 92 | else 93 | 94 | 95 | 96 | end 97 | 98 | axis on 99 | hold off 100 | 101 | 102 | 103 | --------------------------------------------------------------------------------