This paper presents a motion planning and control design of a humanoid robot arm for vision-based grasping in an obstructed environment. A Kinect depth camera is utilized to recognize and find the target object in the environment and grasp it in real-time. First, gradient direction in a depth image is applied to segment environment into several planes. Then, speed up robust feature(SURF) is used to match features between segmented planes and locate the target object. This approach effectively speeds up the matching operation by decreasing the area to match in image planes. Moreover, this study proposes a design for safe operation of the robot arm in an unknown environment. Two safe indices are designed to improve the robustness in safe grasping in an obstructed environment. One index defines the degree of influence of obstacles to the manipulator. Another index classifies the workspace into three regions, namely safe, uncertainty and danger region. The robot employs these indices to move to safe regions by using a potential field for motion planning. Practical experiments show that the six degree-of-freedom robot arm can effectively avoid obstacles and complete the grasping task.