Precise localization is a fundamental prerequisite for the effective operation of Simultaneous Localization and Mapping (SLAM) systems. Traditional visual SLAM is based on static environments and therefore performs poorly in dynamic environments. While numerous visual SLAM methods have been proposed to address dynamic environments, these approaches are typically based on certain prior knowledge. This paper introduces DZ-SLAM, a dynamic SLAM algorithm that does not require any prior knowledge, based on ORB-SLAM3, to handle unknown dynamic elements in the scene. This work first introduces the FastSAM to enable comprehensive image segmentation. It then proposes an adaptive threshold-based dense optical flow approach to identify dynamic elements within the environment. Finally, combining FastSAM with optical flow method and embedding it into the SLAM framework to eliminate dynamic objects and improve positioning accuracy in dynamic environments. The experiment shows that compared with the original ORB-SLAM3 algorithm, the algorithm proposed in this paper reduces the absolute trajectory error by up to 96%; Compared to the most advanced algorithms currently available, the absolute trajectory error of our algorithm can be reduced by up to 46%. In summary, the proposed dynamic object segmentation method without prior knowledge can significantly reduce the positioning error of SLAM algorithm in various dynamic environments.