The production lines for wall bricks have achieved a high level of automation. Most brick production lines in developing countries have automated the steps up to placing the bricks in the kiln. However, the manual loading and unloading of bricks after firing still remains. This manual process reduces labor productivity and increases the cost of the final product. To address this issue, this study aims to utilize machine vision algorithms to detect cracks in bricks, thereby facilitating the automation of the brick loading and unloading process. A comprehensive image processing method is developed, which combines square detection and moment algorithms to analyze image properties. This integrated approach enables the accurate detection of cracks and the determination of their respective areas, ensuring precise and reliable results. By detecting defects in the bricks, we can replace faulty ones and employ robots to automatically handle rows of bricks. The study's results demonstrate the proposed method's ability to accurately identify brick defects. These findings are significant as they contribute to the automation of brick loading and unloading, which can be implemented in large-scale brick factories, leading to a safer and more efficient working environment.