Community detection is a critical issue in the field of complex networks. Recently, the nonnegative matrix factorization (NMF) method has successfully uncovered the community structure in the complex networks. However, this method has a significant drawback; most of community detection methods using NMF require the number of communities to be preassigned or determined the number of communities by searching for the best community structure among all candidates. To address this problem, in this paper, we use density peak clustering (DPC) to obtain the number of centers as the pre-defined parameter for nonnegative matrix factorization. However, due to sparse and high dimensional characteristics of complex networks, DPC cannot be used to detect community directly. To overcome this issue, we employ degree and hop of nodes as the density and distance indexes, respectively; we use NMF and Symmetric NMF to deal with linearly separable data and non-linearly separable data, respectively. Experimental results show that the proposed methods exhibit excellent performance on artificial and real-world networks and superior to the state-of-the-art methods which are the most common method for community detection of complex networks.